Changed Hand to be a floating 'paddle' in front of the head

This commit is contained in:
Philip Rosedale 2013-02-22 12:10:29 -08:00
parent e7fc997f78
commit 41259f9ae0
5 changed files with 42 additions and 72 deletions

View file

@ -8,33 +8,29 @@
#include "Hand.h"
const float DEFAULT_X = 0.0;
const float DEFAULT_Y = 0.0;
const float DEFAULT_Z = -7.0;
const float PHI = 1.618;
Hand::Hand(float initradius, glm::vec3 initcolor)
const float DEFAULT_X = 0;
const float DEFAULT_Y = -1.5;
const float DEFAULT_Z = 2.0;
Hand::Hand(glm::vec3 initcolor)
{
color = initcolor;
radius = initradius;
reset();
noise = 0;
noise = 0.2;
scale.x = 0.07;
scale.y = scale.x * 5.0;
scale.z = scale.y * 2.0;
}
void Hand::render()
{
glEnable(GL_DEPTH_TEST);
glPushMatrix();
glLoadIdentity();
if (isColliding) glColor3f(1,0,0);
else glColor3f(color.x, color.y, color.z);
glBegin(GL_LINES);
glVertex3f(-0.05, -0.5, 0.0);
glVertex3f(position.x, position.y, position.z);
glVertex3f(0.05, -0.5, 0.0);
glVertex3f(position.x, position.y, position.z);
glEnd();
glTranslatef(position.x, position.y, position.z);
glutSolidSphere(radius, 15, 15);
glColor3f(color.x, color.y, color.z);
glScalef(scale.x, scale.y, scale.z);
glutSolidSphere(1.5, 20, 20);
glPopMatrix();
}
@ -43,22 +39,17 @@ void Hand::reset()
position.x = DEFAULT_X;
position.y = DEFAULT_Y;
position.z = DEFAULT_Z;
setTarget(position);
velocity.x = velocity.y = velocity.z = 0;
isColliding = false;
}
void Hand::simulate(float deltaTime)
{
position += velocity*deltaTime;
velocity *= (1.f - 4.0*deltaTime);
if ((noise) && (randFloat() < 0.1))
{
velocity.x += (randFloat() - 0.5)*noise;
velocity.y += (randFloat() - 0.5)*noise;
velocity.z += (randFloat() - 0.5)*noise;
// If noise, add wandering movement
if (noise && (randFloat() < 0.1)) {
position += noise * glm::vec3(randFloat() - 0.5, randFloat() - 0.5, randFloat() - 0.5);
}
// Decay position of hand toward target
position -= deltaTime*(position - target);
}

View file

@ -16,26 +16,20 @@
#include "world.h"
#include "InterfaceConfig.h"
const float RADIUS_RANGE = 10.0;
class Hand {
public:
Hand(float initradius, glm::vec3 color);
Hand(glm::vec3 color);
void simulate (float deltaTime);
void render ();
void reset ();
void setNoise (float mag) { noise = mag; };
void addVel (glm::vec3 add) { velocity += add; };
void addVel (glm::vec3 v) { velocity += v; };
glm::vec3 getPos() { return position; };
void setPos(glm::vec3 newpos) { position = newpos; };
float getRadius() { return radius; };
void setRadius(float newradius) { radius = newradius; };
void setColliding(bool newcollide) { isColliding = newcollide; };
void setPos(glm::vec3 p) { position = p; };
void setTarget(glm::vec3 t) { target = t; };
private:
glm::vec3 position, velocity, color;
glm::vec3 position, target, velocity, color, scale;
float noise;
float radius;
bool isColliding;
};

View file

@ -57,6 +57,7 @@ Head::Head()
renderYaw = 0.0;
renderPitch = 0.0;
setNoise(0);
hand = new Hand(glm::vec3(skinColor[0], skinColor[1], skinColor[2]));
}
Head::~Head() {
@ -205,6 +206,7 @@ void Head::simulate(float deltaTime)
}
}
hand->simulate(deltaTime);
}
@ -216,27 +218,34 @@ void Head::render(int faceToFace, float * myLocation)
glm::vec3 cameraHead(myLocation[0], myLocation[1], myLocation[2]);
float distanceToCamera = glm::distance(cameraHead, position);
//std::cout << distanceToCamera << "\n";
// Don't render a head if it is really close to your location, because that is your own head!
if ((distanceToCamera > 1.0) || faceToFace) {
glEnable(GL_DEPTH_TEST);
glPushMatrix();
glScalef(scale, scale, scale);
glTranslatef(leanSideways, 0.f, leanForward);
glRotatef(Yaw, 0, 1, 0);
glRotatef(Yaw, 0, 1, 0);
hand->render();
glRotatef(Pitch, 1, 0, 0);
glRotatef(Roll, 0, 0, 1);
// Overall scale of head
if (faceToFace) glScalef(1.5, 2.0, 2.0);
else glScalef(0.75, 1.0, 1.0);
glColor3fv(skinColor);
// Head
glutSolidSphere(1, 30, 30);
glutSolidSphere(1, 30, 30);
//std::cout << distanceToCamera << "\n";
// Ears
glPushMatrix();

View file

@ -13,6 +13,8 @@
#include "AgentData.h"
#include "Field.h"
#include "world.h"
#include "Head.h"
#include "Hand.h"
#include "InterfaceConfig.h"
#include "SerialInterface.h"
@ -95,7 +97,9 @@ class Head : public AgentData {
int eyeContact;
eyeContactTargets eyeContactTarget;
void readSensors();
float renderYaw, renderPitch; // Pitch from view frustum when this is own head.
float renderYaw, renderPitch; // Pitch from view frustum when this is own head.
Hand * hand;
};
#endif

View file

@ -84,8 +84,6 @@ Oscilloscope audioScope(512,200,true);
#define HAND_RADIUS 0.25 // Radius of in-world 'hand' of you
Head myHead; // The rendered head of oneself
Hand myHand(HAND_RADIUS,
glm::vec3(0,1,1)); // My hand (used to manipulate things in world)
glm::vec3 box(WORLD_SIZE,WORLD_SIZE,WORLD_SIZE);
ParticleSystem balls(0,
@ -138,7 +136,6 @@ float noise = 1.0; // Overall magnitude scaling for random noi
int step_on = 0;
int display_levels = 0;
int display_head = 0;
int display_hand = 0;
int display_field = 0;
int display_head_mouse = 1; // Display sample mouse pointer controlled by head movement
@ -332,7 +329,6 @@ void init(void)
if (noise_on)
{
myHand.setNoise(noise);
myHead.setNoise(noise);
}
@ -383,7 +379,6 @@ void reset_sensors()
head_lean_y = HEIGHT/2;
myHead.reset();
myHand.reset();
if (serialPort.active) {
serialPort.resetTrailingAverages();
@ -414,20 +409,6 @@ void update_pos(float frametime)
head_mouse_y = max(head_mouse_y, 0);
head_mouse_y = min(head_mouse_y, HEIGHT);
// Update hand/manipulator location for measured forces from serial channel
/*
const float MIN_HAND_ACCEL = 30.0;
const float HAND_FORCE_SCALE = 0.5;
glm::vec3 hand_accel(-(avg_adc_channels[6] - adc_channels[6]),
-(avg_adc_channels[7] - adc_channels[7]),
-(avg_adc_channels[5] - adc_channels[5]));
if (glm::length(hand_accel) > MIN_HAND_ACCEL)
{
myHand.addVel(frametime*hand_accel*HAND_FORCE_SCALE);
}
*/
// Update render direction (pitch/yaw) based on measured gyro rates
const int MIN_YAW_RATE = 100;
const float YAW_SENSITIVITY = 0.08;
@ -505,9 +486,6 @@ void update_pos(float frametime)
location[0] += fwd_vec[2]*-lateral_vel;
location[2] += fwd_vec[0]*lateral_vel;
// Update manipulator objects with object with current location
balls.updateHand(myHead.getPos() + myHand.getPos(), glm::vec3(0,0,0), myHand.getRadius());
// Update own head data
myHead.setRenderYaw(myHead.getRenderYaw() + render_yaw_rate);
myHead.setRenderPitch(render_pitch);
@ -594,8 +572,6 @@ void display(void)
}
}
if (display_hand) myHand.render();
if (!display_head) balls.render();
// Render the world box
@ -715,18 +691,15 @@ void key(unsigned char k, int x, int y)
noise_on = !noise_on; // Toggle noise
if (noise_on)
{
myHand.setNoise(noise);
myHead.setNoise(noise);
}
else
{
myHand.setNoise(0);
myHead.setNoise(0);
}
}
if (k == 'h') display_head = !display_head;
if (k == 'b') display_hand = !display_hand;
if (k == 'm') head_mirror = !head_mirror;
if (k == 'f') display_field = !display_field;
@ -789,7 +762,6 @@ void idle(void)
if (simulate_on) {
field.simulate(1.f/FPS);
myHead.simulate(1.f/FPS);
myHand.simulate(1.f/FPS);
balls.simulate(1.f/FPS);
cloud.simulate(1.f/FPS);
lattice.simulate(1.f/FPS);