From 41259f9ae0bacf7b8abda5f4948a3a49e554aeeb Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Fri, 22 Feb 2013 12:10:29 -0800 Subject: [PATCH 1/4] Changed Hand to be a floating 'paddle' in front of the head --- interface/src/Hand.cpp | 47 +++++++++++++++++------------------------- interface/src/Hand.h | 16 +++++--------- interface/src/Head.cpp | 17 +++++++++++---- interface/src/Head.h | 6 +++++- interface/src/main.cpp | 28 ------------------------- 5 files changed, 42 insertions(+), 72 deletions(-) diff --git a/interface/src/Hand.cpp b/interface/src/Hand.cpp index 92ec070217..d7f9cf1847 100644 --- a/interface/src/Hand.cpp +++ b/interface/src/Hand.cpp @@ -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); } \ No newline at end of file diff --git a/interface/src/Hand.h b/interface/src/Hand.h index 694fb5eb03..9f64343673 100644 --- a/interface/src/Hand.h +++ b/interface/src/Hand.h @@ -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; }; diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 31a388c1d7..90033af565 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -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(); diff --git a/interface/src/Head.h b/interface/src/Head.h index 7dc8ef7588..038f37bfc5 100644 --- a/interface/src/Head.h +++ b/interface/src/Head.h @@ -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 \ No newline at end of file diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 0f96ceb951..c4846becc4 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -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); From 014fdcc618a057b4a43e5cbcd5d041608d82d2eb Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Fri, 22 Feb 2013 12:20:01 -0800 Subject: [PATCH 2/4] Tweaked hand 'length' --- interface/src/Hand.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/interface/src/Hand.cpp b/interface/src/Hand.cpp index d7f9cf1847..c7e0c57094 100644 --- a/interface/src/Hand.cpp +++ b/interface/src/Hand.cpp @@ -21,7 +21,7 @@ Hand::Hand(glm::vec3 initcolor) noise = 0.2; scale.x = 0.07; scale.y = scale.x * 5.0; - scale.z = scale.y * 2.0; + scale.z = scale.y * 1.0; } void Hand::render() @@ -46,8 +46,8 @@ void Hand::reset() void Hand::simulate(float deltaTime) { // If noise, add wandering movement - if (noise && (randFloat() < 0.1)) { - position += noise * glm::vec3(randFloat() - 0.5, randFloat() - 0.5, randFloat() - 0.5); + if (noise) { + position += noise * 0.1f * glm::vec3(randFloat() - 0.5, randFloat() - 0.5, randFloat() - 0.5); } // Decay position of hand toward target position -= deltaTime*(position - target); From 777a00db3e65e7dff6478083eab31503cc08651c Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Fri, 22 Feb 2013 12:28:27 -0800 Subject: [PATCH 3/4] Adding hand data to head broadcast packet. --- interface/src/Head.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 90033af565..b9fec9c48d 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -345,18 +345,23 @@ void Head::render(int faceToFace, float * myLocation) int Head::getBroadcastData(char* data) { // Copy data for transmission to the buffer, return length of data - sprintf(data, "H%f,%f,%f,%f,%f,%f,%f,%f", getRenderPitch() + Pitch, -getRenderYaw() + 180 -Yaw, Roll, + sprintf(data, "H%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f", + getRenderPitch() + Pitch, -getRenderYaw() + 180 -Yaw, Roll, position.x + leanSideways, position.y, position.z + leanForward, - loudness, averageLoudness); + loudness, averageLoudness, + hand->getPos().x, hand->getPos().y, hand->getPos().z); return strlen(data); } void Head::parseData(void *data, int size) { // parse head data for this agent - sscanf((char *)data, "H%f,%f,%f,%f,%f,%f,%f,%f", + glm::vec3 handPos(0,0,0); + sscanf((char *)data, "H%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f", &Pitch, &Yaw, &Roll, &position.x, &position.y, &position.z, - &loudness, &averageLoudness); + &loudness, &averageLoudness, + &handPos.x, &handPos.y, &handPos.z); + if (glm::length(handPos) > 0.0) hand->setPos(handPos); } void Head::SetNewHeadTarget(float pitch, float yaw) From 0453445b134cc80cf1dab0bfc1d425f95e378994 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Fri, 22 Feb 2013 12:47:28 -0800 Subject: [PATCH 4/4] Render own manipulator hand in front of camera --- interface/src/Head.cpp | 24 ++++++++++++------------ interface/src/main.cpp | 14 ++++++-------- 2 files changed, 18 insertions(+), 20 deletions(-) diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index b9fec9c48d..78ea7f950c 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -218,19 +218,19 @@ void Head::render(int faceToFace, float * myLocation) glm::vec3 cameraHead(myLocation[0], myLocation[1], myLocation[2]); float distanceToCamera = glm::distance(cameraHead, position); + // Always render own hand, but don't render head unless showing face2face + glEnable(GL_DEPTH_TEST); + glPushMatrix(); + + glScalef(scale, scale, scale); + glTranslatef(leanSideways, 0.f, leanForward); + + glRotatef(Yaw, 0, 1, 0); + + hand->render(); // 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); - - hand->render(); glRotatef(Pitch, 1, 0, 0); glRotatef(Roll, 0, 0, 1); @@ -335,9 +335,9 @@ void Head::render(int faceToFace, float * myLocation) glutSolidSphere(PupilSize, 15, 15); glPopMatrix(); - glPopMatrix(); + } - + glPopMatrix(); } // Transmit data to agents requesting it diff --git a/interface/src/main.cpp b/interface/src/main.cpp index c4846becc4..f7b3106b4b 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -578,14 +578,12 @@ void display(void) if (!display_head && stats_on) render_world_box(); // Render my own head - - if (display_head) { - glPushMatrix(); - glLoadIdentity(); - glTranslatef(0.f, 0.f, -7.f); - myHead.render(1, &location[0]); - glPopMatrix(); - } + glPushMatrix(); + glLoadIdentity(); + glTranslatef(0.f, 0.f, -7.f); + myHead.render(display_head, &location[0]); + glPopMatrix(); + //glm::vec3 test(0.5, 0.5, 0.5); //render_vector(&test);