From d00001613f6716ef429bfdce3ac4315dc8c59bad Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Mon, 15 Apr 2013 21:06:45 -0700 Subject: [PATCH 1/7] Renamed functions in head, added ability to change body yaw. --- interface/src/Head.cpp | 8 +------- interface/src/Head.h | 6 ++++-- interface/src/main.cpp | 9 ++------- 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index ef1e9ffeb6..3b048fd7e9 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -188,7 +188,7 @@ void Head::reset() { //this pertains to moving the head with the glasses //--------------------------------------------------- -void Head::UpdatePos(float frametime, SerialInterface * serialInterface, int head_mirror, glm::vec3 * gravity) +void Head::UpdateGyros(float frametime, SerialInterface * serialInterface, int head_mirror, glm::vec3 * gravity) // Using serial data, update avatar/render position and angles { const float PITCH_ACCEL_COUPLING = 0.5; @@ -445,8 +445,6 @@ void Head::simulate(float deltaTime) { } } - - const float DEGREES_BETWEEN_VIEWER_EYES = 3; const float DEGREES_TO_VIEWER_MOUTH = 7; @@ -980,10 +978,6 @@ void Head::updateAvatarSprings( float deltaTime ) { } } -float Head::getBodyYaw() { - return bodyYaw; -} - glm::vec3 Head::getHeadLookatDirection() { return glm::vec3 ( diff --git a/interface/src/Head.h b/interface/src/Head.h index f8af6521d1..938d92884c 100644 --- a/interface/src/Head.h +++ b/interface/src/Head.h @@ -142,7 +142,7 @@ class Head : public AgentData { Head* clone() const; void reset(); - void UpdatePos(float frametime, SerialInterface * serialInterface, int head_mirror, glm::vec3 * gravity); + void UpdateGyros(float frametime, SerialInterface * serialInterface, int head_mirror, glm::vec3 * gravity); void setNoise (float mag) { noise = mag; } void setPitch(float p) {Pitch = p; } void setYaw(float y) {Yaw = y; } @@ -163,7 +163,9 @@ class Head : public AgentData { float getYaw() {return Yaw;} float getLastMeasuredYaw() {return YawRate;} - float getBodyYaw(); + float getBodyYaw() {return bodyYaw;}; + void addBodyYaw(float y) {bodyYaw += y;}; + glm::vec3 getHeadLookatDirection(); glm::vec3 getHeadLookatDirectionUp(); glm::vec3 getHeadLookatDirectionRight(); diff --git a/interface/src/main.cpp b/interface/src/main.cpp index e3e440c80c..932d96199e 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -227,12 +227,7 @@ void displayStats(void) char stats[200]; sprintf(stats, "FPS = %3.0f Pkts/s = %d Bytes/s = %d Head(x,y,z)= %4.2f, %4.2f, %4.2f ", FPS, packetsPerSecond, bytesPerSecond, avatarPos.x,avatarPos.y,avatarPos.z); - drawtext(10, statsVerticalOffset + 49, 0.10f, 0, 1.0, 0, stats); - if (serialPort.active) { - sprintf(stats, "ADC samples = %d, LED = %d", - serialPort.getNumSamples(), serialPort.getLED()); - drawtext(300, statsVerticalOffset + 30, 0.10f, 0, 1.0, 0, stats); - } + drawtext(10, statsVerticalOffset + 49, 0.10f, 0, 1.0, 0, stats); std::stringstream voxelStats; voxelStats << "Voxels Rendered: " << voxels.getVoxelsRendered(); @@ -383,7 +378,7 @@ void updateAvatar(float frametime) float gyroPitchRate = serialPort.getRelativeValue(PITCH_RATE); float gyroYawRate = serialPort.getRelativeValue(YAW_RATE); - myAvatar.UpdatePos(frametime, &serialPort, headMirror, &gravity); + myAvatar.UpdateGyros(frametime, &serialPort, headMirror, &gravity); // // Update gyro-based mouse (X,Y on screen) From 39bb556cd3a5d08182c76896dc85fc704e3f775f Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Tue, 16 Apr 2013 20:29:10 -0700 Subject: [PATCH 2/7] Fix to add local variable underscores to head get/add body yaw functions. --- interface/src/Head.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interface/src/Head.h b/interface/src/Head.h index 3978f369ab..fae9d18fff 100644 --- a/interface/src/Head.h +++ b/interface/src/Head.h @@ -124,8 +124,8 @@ class Head : public AvatarData { float getYaw() {return Yaw;} float getLastMeasuredYaw() {return YawRate;} - float getBodyYaw() {return bodyYaw;}; - void addBodyYaw(float y) {bodyYaw += y;}; + float getBodyYaw() {return _bodyYaw;}; + void addBodyYaw(float y) {_bodyYaw += y;}; glm::vec3 getHeadLookatDirection(); glm::vec3 getHeadLookatDirectionUp(); From 4f0ca2f33eff3cc167a0d873fc59ca76c62b43ed Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Wed, 17 Apr 2013 12:31:03 -0700 Subject: [PATCH 3/7] added quaternions to avatar body and bone structure (but not using them yet) --- interface/src/Head.cpp | 76 ++++++++++++--------------- interface/src/Head.h | 10 +++- libraries/avatars/src/Orientation.cpp | 3 +- 3 files changed, 43 insertions(+), 46 deletions(-) diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 4f77e6fafe..18fa5c9181 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -48,26 +48,20 @@ unsigned int iris_texture_height = 256; Head::Head() { initializeAvatar(); - + avatar.orientation.setToIdentity(); avatar.velocity = glm::vec3( 0.0, 0.0, 0.0 ); avatar.thrust = glm::vec3( 0.0, 0.0, 0.0 ); - avatar.orientation.setToIdentity(); - - closestOtherAvatar = 0; - - _bodyYaw = -90.0; - _bodyPitch = 0.0; - _bodyRoll = 0.0; - - bodyYawDelta = 0.0; - - triggeringAction = false; - - mode = AVATAR_MODE_STANDING; + rotation = glm::quat( 0.0f, 0.0f, 0.0f, 0.0f ); + closestOtherAvatar = 0; + _bodyYaw = -90.0; + _bodyPitch = 0.0; + _bodyRoll = 0.0; + bodyYawDelta = 0.0; + triggeringAction = false; + mode = AVATAR_MODE_STANDING; initializeSkeleton(); - for (int i = 0; i < MAX_DRIVE_KEYS; i++) driveKeys[i] = false; PupilSize = 0.10; @@ -102,17 +96,15 @@ Head::Head() { browAudioLift = 0.0; noise = 0; - handBeingMoved = false; - previousHandBeingMoved = false; - movedHandOffset = glm::vec3( 0.0, 0.0, 0.0 ); + handBeingMoved = false; + previousHandBeingMoved = false; + movedHandOffset = glm::vec3( 0.0, 0.0, 0.0 ); + usingSprings = false; + springForce = 6.0f; + springVelocityDecay = 16.0f; sphere = NULL; - usingSprings = false; - - springForce = 6.0f; - springVelocityDecay = 16.0f; - if (iris_texture.size() == 0) { switchToResourcesIfRequired(); unsigned error = lodepng::decode(iris_texture, iris_texture_width, iris_texture_height, iris_texture_file); @@ -137,30 +129,23 @@ Head::Head() { } - - Head::Head(const Head &otherHead) { initializeAvatar(); + avatar.orientation.set( otherHead.avatar.orientation ); avatar.velocity = otherHead.avatar.velocity; avatar.thrust = otherHead.avatar.thrust; - avatar.orientation.set( otherHead.avatar.orientation ); - - closestOtherAvatar = otherHead.closestOtherAvatar; - - _bodyYaw = otherHead._bodyYaw; - _bodyPitch = otherHead._bodyPitch; - _bodyRoll = otherHead._bodyRoll; - - bodyYawDelta = otherHead.bodyYawDelta; - - triggeringAction = otherHead.triggeringAction; - - mode = otherHead.mode; + rotation = otherHead.rotation; + closestOtherAvatar = otherHead.closestOtherAvatar; + _bodyYaw = otherHead._bodyYaw; + _bodyPitch = otherHead._bodyPitch; + _bodyRoll = otherHead._bodyRoll; + bodyYawDelta = otherHead.bodyYawDelta; + triggeringAction = otherHead.triggeringAction; + mode = otherHead.mode; initializeSkeleton(); - for (int i = 0; i < MAX_DRIVE_KEYS; i++) driveKeys[i] = otherHead.driveKeys[i]; PupilSize = otherHead.PupilSize; @@ -833,14 +818,19 @@ void Head::initializeAvatar() { } - - void Head::initializeSkeleton() { for (int b=0; b + +#include and + + enum eyeContactTargets {LEFT_EYE, RIGHT_EYE, MOUTH}; #define FWD 0 @@ -80,6 +85,7 @@ struct AvatarBone glm::vec3 springyPosition; // used for special effects (a 'flexible' variant of position) glm::dvec3 springyVelocity; // used for special effects ( the velocity of the springy position) float springBodyTightness; // how tightly the springy position tries to stay on the position + glm::quat rotation; // this will eventually replace yaw, pitch and roll (and maybe orienttion) float yaw; // the yaw Euler angle of the bone rotation off the parent float pitch; // the pitch Euler angle of the bone rotation off the parent float roll; // the roll Euler angle of the bone rotation off the parent @@ -231,7 +237,9 @@ class Head : public AvatarData { GLUquadric *sphere; Avatar avatar; - + + glm::quat rotation; // the rotation of the avatar body as a whole + AvatarBone bone[ NUM_AVATAR_BONES ]; AvatarMode mode; diff --git a/libraries/avatars/src/Orientation.cpp b/libraries/avatars/src/Orientation.cpp index 8eeb3dd0ff..f11f820c89 100755 --- a/libraries/avatars/src/Orientation.cpp +++ b/libraries/avatars/src/Orientation.cpp @@ -22,7 +22,6 @@ void Orientation::setToIdentity() { front = glm::vec3( 0.0, 0.0, 1.0 ); } - void Orientation::set( Orientation o ) { right = o.right; up = o.up; @@ -125,7 +124,7 @@ void Orientation::testForOrthogonalAndNormalizedVectors( float epsilon ) { //---------------------------------------------------------------- - // make sure vectors are orthoginal (or close enough) + // make sure vectors are orthogonal (or close enough) //---------------------------------------------------------------- glm::vec3 rightCross = glm::cross( up, front ); glm::vec3 upCross = glm::cross( front, right ); From 3856a70b7e2eb76f8949e372a23965afa0958949 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Wed, 17 Apr 2013 12:48:47 -0700 Subject: [PATCH 4/7] added "_" to several members in Head class, and cleaned up some code formatting (housecleaning :) --- interface/src/Head.cpp | 426 ++++++++++++++++++++--------------------- interface/src/Head.h | 52 +++-- 2 files changed, 235 insertions(+), 243 deletions(-) diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 18fa5c9181..1d25118210 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -48,17 +48,17 @@ unsigned int iris_texture_height = 256; Head::Head() { initializeAvatar(); - avatar.orientation.setToIdentity(); - avatar.velocity = glm::vec3( 0.0, 0.0, 0.0 ); - avatar.thrust = glm::vec3( 0.0, 0.0, 0.0 ); - rotation = glm::quat( 0.0f, 0.0f, 0.0f, 0.0f ); - closestOtherAvatar = 0; + _avatar.orientation.setToIdentity(); + _avatar.velocity = glm::vec3( 0.0, 0.0, 0.0 ); + _avatar.thrust = glm::vec3( 0.0, 0.0, 0.0 ); + _rotation = glm::quat( 0.0f, 0.0f, 0.0f, 0.0f ); + _closestOtherAvatar = 0; _bodyYaw = -90.0; _bodyPitch = 0.0; _bodyRoll = 0.0; - bodyYawDelta = 0.0; - triggeringAction = false; - mode = AVATAR_MODE_STANDING; + _bodyYawDelta = 0.0; + _triggeringAction = false; + _mode = AVATAR_MODE_STANDING; initializeSkeleton(); @@ -96,12 +96,12 @@ Head::Head() { browAudioLift = 0.0; noise = 0; - handBeingMoved = false; - previousHandBeingMoved = false; - movedHandOffset = glm::vec3( 0.0, 0.0, 0.0 ); - usingSprings = false; - springForce = 6.0f; - springVelocityDecay = 16.0f; + _handBeingMoved = false; + _previousHandBeingMoved = false; + _movedHandOffset = glm::vec3( 0.0, 0.0, 0.0 ); + _usingSprings = false; + _springForce = 6.0f; + _springVelocityDecay = 16.0f; sphere = NULL; @@ -132,17 +132,17 @@ Head::Head() { Head::Head(const Head &otherHead) { initializeAvatar(); - avatar.orientation.set( otherHead.avatar.orientation ); - avatar.velocity = otherHead.avatar.velocity; - avatar.thrust = otherHead.avatar.thrust; - rotation = otherHead.rotation; - closestOtherAvatar = otherHead.closestOtherAvatar; + _avatar.orientation.set( otherHead._avatar.orientation ); + _avatar.velocity = otherHead._avatar.velocity; + _avatar.thrust = otherHead._avatar.thrust; + _rotation = otherHead._rotation; + _closestOtherAvatar = otherHead._closestOtherAvatar; _bodyYaw = otherHead._bodyYaw; _bodyPitch = otherHead._bodyPitch; _bodyRoll = otherHead._bodyRoll; - bodyYawDelta = otherHead.bodyYawDelta; - triggeringAction = otherHead.triggeringAction; - mode = otherHead.mode; + _bodyYawDelta = otherHead._bodyYawDelta; + _triggeringAction = otherHead._triggeringAction; + _mode = otherHead._mode; initializeSkeleton(); @@ -268,7 +268,7 @@ void Head::setLeanSideways(float dist){ } void Head::setTriggeringAction( bool d ) { - triggeringAction = d; + _triggeringAction = d; } @@ -279,7 +279,7 @@ void Head::simulate(float deltaTime) { // DEBUG - other avatars... //------------------------------------- //closeEnoughToInteract = 0.3f; - closestOtherAvatar = -1; + _closestOtherAvatar = -1; float closestDistance = 10000.0f; @@ -303,15 +303,15 @@ void Head::simulate(float deltaTime) { //------------------------------------- // test other avs for proximity... //------------------------------------- - glm::vec3 v( bone[ AVATAR_BONE_RIGHT_SHOULDER ].position ); + glm::vec3 v( _bone[ AVATAR_BONE_RIGHT_SHOULDER ].position ); v -= DEBUG_otherAvatarListPosition[o]; float distance = glm::length( v ); - if ( distance < avatar.maxArmLength ) { + if ( distance < _avatar.maxArmLength ) { if ( distance < closestDistance ) { closestDistance = distance; - closestOtherAvatar = o; + _closestOtherAvatar = o; } } } @@ -327,80 +327,80 @@ void Head::simulate(float deltaTime) { //------------------------------------------------------------------------ // reset hand and elbow position according to hand movement //------------------------------------------------------------------------ - if ( handBeingMoved ){ - if (! previousHandBeingMoved ){ + if ( _handBeingMoved ){ + if (! _previousHandBeingMoved ){ initializeBodySprings(); - usingSprings = true; + _usingSprings = true; //printf( "just started moving hand\n" ); } } else { - if ( previousHandBeingMoved ){ - usingSprings = false; + if ( _previousHandBeingMoved ){ + _usingSprings = false; //printf( "just stopped moving hand\n" ); } } - if ( handBeingMoved ) { + if ( _handBeingMoved ) { updateHandMovement(); updateBodySprings( deltaTime ); } - previousHandBeingMoved = handBeingMoved; - handBeingMoved = false; + _previousHandBeingMoved = _handBeingMoved; + _handBeingMoved = false; //------------------------------------------------- // this handles the avatar being driven around... //------------------------------------------------- - avatar.thrust = glm::vec3( 0.0, 0.0, 0.0 ); + _avatar.thrust = glm::vec3( 0.0, 0.0, 0.0 ); if (driveKeys[FWD]) { - glm::vec3 front( avatar.orientation.getFront().x, avatar.orientation.getFront().y, avatar.orientation.getFront().z ); - avatar.thrust += front * THRUST_MAG; + glm::vec3 front( _avatar.orientation.getFront().x, _avatar.orientation.getFront().y, _avatar.orientation.getFront().z ); + _avatar.thrust += front * THRUST_MAG; } if (driveKeys[BACK]) { - glm::vec3 front( avatar.orientation.getFront().x, avatar.orientation.getFront().y, avatar.orientation.getFront().z ); - avatar.thrust -= front * THRUST_MAG; + glm::vec3 front( _avatar.orientation.getFront().x, _avatar.orientation.getFront().y, _avatar.orientation.getFront().z ); + _avatar.thrust -= front * THRUST_MAG; } if (driveKeys[RIGHT]) { - glm::vec3 right( avatar.orientation.getRight().x, avatar.orientation.getRight().y, avatar.orientation.getRight().z ); - avatar.thrust -= right * THRUST_MAG; + glm::vec3 right( _avatar.orientation.getRight().x, _avatar.orientation.getRight().y, _avatar.orientation.getRight().z ); + _avatar.thrust -= right * THRUST_MAG; } if (driveKeys[LEFT]) { - glm::vec3 right( avatar.orientation.getRight().x, avatar.orientation.getRight().y, avatar.orientation.getRight().z ); - avatar.thrust += right * THRUST_MAG; + glm::vec3 right( _avatar.orientation.getRight().x, _avatar.orientation.getRight().y, _avatar.orientation.getRight().z ); + _avatar.thrust += right * THRUST_MAG; } if (driveKeys[UP]) { - glm::vec3 up( avatar.orientation.getUp().x, avatar.orientation.getUp().y, avatar.orientation.getUp().z ); - avatar.thrust += up * THRUST_MAG; + glm::vec3 up( _avatar.orientation.getUp().x, _avatar.orientation.getUp().y, _avatar.orientation.getUp().z ); + _avatar.thrust += up * THRUST_MAG; } if (driveKeys[DOWN]) { - glm::vec3 up( avatar.orientation.getUp().x, avatar.orientation.getUp().y, avatar.orientation.getUp().z ); - avatar.thrust -= up * THRUST_MAG; + glm::vec3 up( _avatar.orientation.getUp().x, _avatar.orientation.getUp().y, _avatar.orientation.getUp().z ); + _avatar.thrust -= up * THRUST_MAG; } if (driveKeys[ROT_RIGHT]) { - bodyYawDelta -= YAW_MAG * deltaTime; + _bodyYawDelta -= YAW_MAG * deltaTime; } if (driveKeys[ROT_LEFT]) { - bodyYawDelta += YAW_MAG * deltaTime; + _bodyYawDelta += YAW_MAG * deltaTime; } //---------------------------------------------------------- - float translationalSpeed = glm::length( avatar.velocity ); - float rotationalSpeed = fabs( bodyYawDelta ); + float translationalSpeed = glm::length( _avatar.velocity ); + float rotationalSpeed = fabs( _bodyYawDelta ); if ( translationalSpeed + rotationalSpeed > 0.2 ) { - mode = AVATAR_MODE_WALKING; + _mode = AVATAR_MODE_WALKING; } else { - mode = AVATAR_MODE_COMMUNICATING; + _mode = AVATAR_MODE_COMMUNICATING; } //---------------------------------------------------------- // update body yaw by body yaw delta //---------------------------------------------------------- - _bodyYaw += bodyYawDelta * deltaTime; + _bodyYaw += _bodyYawDelta * deltaTime; //---------------------------------------------------------- // (for now) set head yaw to body yaw @@ -411,23 +411,23 @@ void Head::simulate(float deltaTime) { // decay body yaw delta //---------------------------------------------------------- const float TEST_YAW_DECAY = 5.0; - bodyYawDelta *= ( 1.0 - TEST_YAW_DECAY * deltaTime ); + _bodyYawDelta *= ( 1.0 - TEST_YAW_DECAY * deltaTime ); //---------------------------------------------------------- // add thrust to velocity //---------------------------------------------------------- - avatar.velocity += glm::dvec3( avatar.thrust * deltaTime ); + _avatar.velocity += glm::dvec3( _avatar.thrust * deltaTime ); //---------------------------------------------------------- // update position by velocity //---------------------------------------------------------- - _bodyPosition += (glm::vec3)avatar.velocity * deltaTime; + _bodyPosition += (glm::vec3)_avatar.velocity * deltaTime; //---------------------------------------------------------- // decay velocity //---------------------------------------------------------- const float LIN_VEL_DECAY = 5.0; - avatar.velocity *= ( 1.0 - LIN_VEL_DECAY * deltaTime ); + _avatar.velocity *= ( 1.0 - LIN_VEL_DECAY * deltaTime ); @@ -545,7 +545,7 @@ void Head::render(int faceToFace, int isMine) { //--------------------------------------------------- // show avatar orientation //--------------------------------------------------- - renderOrientationDirections(bone[ AVATAR_BONE_HEAD ].position, bone[ AVATAR_BONE_HEAD ].orientation, 0.2f ); + renderOrientationDirections( _bone[ AVATAR_BONE_HEAD ].position, _bone[ AVATAR_BONE_HEAD ].orientation, 0.2f ); //--------------------------------------------------- // render body @@ -568,11 +568,11 @@ void Head::render(int faceToFace, int isMine) { glPopMatrix(); } - if ( usingSprings ) { - if ( closestOtherAvatar != -1 ) { + if ( _usingSprings ) { + if ( _closestOtherAvatar != -1 ) { - glm::vec3 v1( bone[ AVATAR_BONE_RIGHT_HAND ].position ); - glm::vec3 v2( DEBUG_otherAvatarListPosition[ closestOtherAvatar ] ); + glm::vec3 v1( _bone[ AVATAR_BONE_RIGHT_HAND ].position ); + glm::vec3 v2( DEBUG_otherAvatarListPosition[ _closestOtherAvatar ] ); glLineWidth( 5.0 ); glColor4f( 0.9f, 0.5f, 0.2f, 0.6 ); @@ -624,20 +624,20 @@ void Head::renderHead( int faceToFace, int isMine ) { glPushMatrix(); - if ( usingSprings ) { + if ( _usingSprings ) { glTranslatef ( - bone[ AVATAR_BONE_HEAD ].springyPosition.x, - bone[ AVATAR_BONE_HEAD ].springyPosition.y, - bone[ AVATAR_BONE_HEAD ].springyPosition.z + _bone[ AVATAR_BONE_HEAD ].springyPosition.x, + _bone[ AVATAR_BONE_HEAD ].springyPosition.y, + _bone[ AVATAR_BONE_HEAD ].springyPosition.z ); } else { glTranslatef ( - bone[ AVATAR_BONE_HEAD ].position.x, - bone[ AVATAR_BONE_HEAD ].position.y, - bone[ AVATAR_BONE_HEAD ].position.z + _bone[ AVATAR_BONE_HEAD ].position.x, + _bone[ AVATAR_BONE_HEAD ].position.y, + _bone[ AVATAR_BONE_HEAD ].position.z ); } @@ -786,12 +786,12 @@ void Head::renderHead( int faceToFace, int isMine ) { void Head::setHandMovement( glm::vec3 movement ) { - handBeingMoved = true; - movedHandOffset = movement; + _handBeingMoved = true; + _movedHandOffset = movement; } AvatarMode Head::getMode() { - return mode; + return _mode; } @@ -821,18 +821,18 @@ void Head::initializeAvatar() { void Head::initializeSkeleton() { for (int b=0; b 0.0f ) { glm::vec3 springDirection = springVector / length; - float force = ( length - bone[b].length ) * springForce * deltaTime; + float force = ( length - _bone[b].length ) * _springForce * deltaTime; - bone[ b ].springyVelocity -= springDirection * force; - bone[ bone[b].parent ].springyVelocity += springDirection * force; + _bone[ b ].springyVelocity -= springDirection * force; + _bone[ _bone[b].parent ].springyVelocity += springDirection * force; } - bone[b].springyVelocity += ( bone[b].position - bone[b].springyPosition ) * bone[b].springBodyTightness * deltaTime; + _bone[b].springyVelocity += ( _bone[b].position - _bone[b].springyPosition ) * _bone[b].springBodyTightness * deltaTime; - float decay = 1.0 - springVelocityDecay * deltaTime; + float decay = 1.0 - _springVelocityDecay * deltaTime; if ( decay > 0.0 ) { - bone[b].springyVelocity *= decay; + _bone[b].springyVelocity *= decay; } else { - bone[b].springyVelocity = glm::vec3( 0.0f, 0.0f, 0.0f ); + _bone[b].springyVelocity = glm::vec3( 0.0f, 0.0f, 0.0f ); } - bone[b].springyPosition += bone[b].springyVelocity; + _bone[b].springyPosition += _bone[b].springyVelocity; } } @@ -1024,36 +1024,36 @@ float Head::getBodyYaw() { glm::vec3 Head::getHeadLookatDirection() { return glm::vec3 ( - avatar.orientation.getFront().x, - avatar.orientation.getFront().y, - avatar.orientation.getFront().z + _avatar.orientation.getFront().x, + _avatar.orientation.getFront().y, + _avatar.orientation.getFront().z ); } glm::vec3 Head::getHeadLookatDirectionUp() { return glm::vec3 ( - avatar.orientation.getUp().x, - avatar.orientation.getUp().y, - avatar.orientation.getUp().z + _avatar.orientation.getUp().x, + _avatar.orientation.getUp().y, + _avatar.orientation.getUp().z ); } glm::vec3 Head::getHeadLookatDirectionRight() { return glm::vec3 ( - avatar.orientation.getRight().x, - avatar.orientation.getRight().y, - avatar.orientation.getRight().z + _avatar.orientation.getRight().x, + _avatar.orientation.getRight().y, + _avatar.orientation.getRight().z ); } glm::vec3 Head::getHeadPosition() { return glm::vec3 ( - bone[ AVATAR_BONE_HEAD ].position.x, - bone[ AVATAR_BONE_HEAD ].position.y, - bone[ AVATAR_BONE_HEAD ].position.z + _bone[ AVATAR_BONE_HEAD ].position.x, + _bone[ AVATAR_BONE_HEAD ].position.y, + _bone[ AVATAR_BONE_HEAD ].position.z ); } @@ -1061,26 +1061,26 @@ void Head::updateHandMovement() { glm::vec3 transformedHandMovement; transformedHandMovement - = avatar.orientation.getRight() * -movedHandOffset.x - + avatar.orientation.getUp() * -movedHandOffset.y * 0.5f - + avatar.orientation.getFront() * -movedHandOffset.y; + = _avatar.orientation.getRight() * -_movedHandOffset.x + + _avatar.orientation.getUp() * -_movedHandOffset.y * 0.5f + + _avatar.orientation.getFront() * -_movedHandOffset.y; - bone[ AVATAR_BONE_RIGHT_HAND ].position += transformedHandMovement; + _bone[ AVATAR_BONE_RIGHT_HAND ].position += transformedHandMovement; //if holding hands, add a pull to the hand... - if ( usingSprings ) { - if ( closestOtherAvatar != -1 ) { - if ( triggeringAction ) { + if ( _usingSprings ) { + if ( _closestOtherAvatar != -1 ) { + if ( _triggeringAction ) { /* glm::vec3 handShakePull( DEBUG_otherAvatarListPosition[ closestOtherAvatar ]); - handShakePull -= bone[ AVATAR_BONE_RIGHT_HAND ].position; + handShakePull -= _bone[ AVATAR_BONE_RIGHT_HAND ].position; handShakePull *= 1.0; transformedHandMovement += handShakePull; */ - bone[ AVATAR_BONE_RIGHT_HAND ].position = DEBUG_otherAvatarListPosition[ closestOtherAvatar ]; + _bone[ AVATAR_BONE_RIGHT_HAND ].position = DEBUG_otherAvatarListPosition[ _closestOtherAvatar ]; } } } @@ -1090,8 +1090,8 @@ void Head::updateHandMovement() { //------------------------------------------------------------------------------- // determine the arm vector //------------------------------------------------------------------------------- - glm::vec3 armVector = bone[ AVATAR_BONE_RIGHT_HAND ].position; - armVector -= bone[ AVATAR_BONE_RIGHT_SHOULDER ].position; + glm::vec3 armVector = _bone[ AVATAR_BONE_RIGHT_HAND ].position; + armVector -= _bone[ AVATAR_BONE_RIGHT_SHOULDER ].position; //------------------------------------------------------------------------------- @@ -1102,52 +1102,52 @@ void Head::updateHandMovement() { //------------------------------------------------------------------------------- // if right hand is being dragged beyond maximum arm length... //------------------------------------------------------------------------------- - if ( distance > avatar.maxArmLength ) { + if ( distance > _avatar.maxArmLength ) { //------------------------------------------------------------------------------- // reset right hand to be constrained to maximum arm length //------------------------------------------------------------------------------- - bone[ AVATAR_BONE_RIGHT_HAND ].position = bone[ AVATAR_BONE_RIGHT_SHOULDER ].position; + _bone[ AVATAR_BONE_RIGHT_HAND ].position = _bone[ AVATAR_BONE_RIGHT_SHOULDER ].position; glm::vec3 armNormal = armVector / distance; - armVector = armNormal * avatar.maxArmLength; - distance = avatar.maxArmLength; - glm::vec3 constrainedPosition = bone[ AVATAR_BONE_RIGHT_SHOULDER ].position; + armVector = armNormal * _avatar.maxArmLength; + distance = _avatar.maxArmLength; + glm::vec3 constrainedPosition = _bone[ AVATAR_BONE_RIGHT_SHOULDER ].position; constrainedPosition += armVector; - bone[ AVATAR_BONE_RIGHT_HAND ].position = constrainedPosition; + _bone[ AVATAR_BONE_RIGHT_HAND ].position = constrainedPosition; } /* //------------------------------------------------------------------------------- // keep arm from going through av body... //------------------------------------------------------------------------------- - glm::vec3 adjustedArmVector = bone[ AVATAR_BONE_RIGHT_HAND ].position; - adjustedArmVector -= bone[ AVATAR_BONE_RIGHT_SHOULDER ].position; + glm::vec3 adjustedArmVector = _bone[ AVATAR_BONE_RIGHT_HAND ].position; + adjustedArmVector -= _bone[ AVATAR_BONE_RIGHT_SHOULDER ].position; float rightComponent = glm::dot( adjustedArmVector, avatar.orientation.getRight() ); if ( rightComponent < 0.0 ) { - bone[ AVATAR_BONE_RIGHT_HAND ].position -= avatar.orientation.getRight() * rightComponent; + _bone[ AVATAR_BONE_RIGHT_HAND ].position -= avatar.orientation.getRight() * rightComponent; } */ //----------------------------------------------------------------------------- // set elbow position //----------------------------------------------------------------------------- - glm::vec3 newElbowPosition = bone[ AVATAR_BONE_RIGHT_SHOULDER ].position; + glm::vec3 newElbowPosition = _bone[ AVATAR_BONE_RIGHT_SHOULDER ].position; newElbowPosition += armVector * ONE_HALF; - glm::vec3 perpendicular = glm::cross( avatar.orientation.getFront(), armVector ); + glm::vec3 perpendicular = glm::cross( _avatar.orientation.getFront(), armVector ); - newElbowPosition += perpendicular * ( 1.0f - ( avatar.maxArmLength / distance ) ) * ONE_HALF; - bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position = newElbowPosition; + newElbowPosition += perpendicular * ( 1.0f - ( _avatar.maxArmLength / distance ) ) * ONE_HALF; + _bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position = newElbowPosition; //----------------------------------------------------------------------------- // set wrist position //----------------------------------------------------------------------------- - glm::vec3 vv( bone[ AVATAR_BONE_RIGHT_HAND ].position ); - vv -= bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position; - glm::vec3 newWristPosition = bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position; + glm::vec3 vv( _bone[ AVATAR_BONE_RIGHT_HAND ].position ); + vv -= _bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position; + glm::vec3 newWristPosition = _bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position; newWristPosition += vv * 0.7f; - bone[ AVATAR_BONE_RIGHT_FOREARM ].position = newWristPosition; + _bone[ AVATAR_BONE_RIGHT_FOREARM ].position = newWristPosition; } @@ -1157,17 +1157,17 @@ void Head::renderBody() { // Render bone positions as spheres //----------------------------------------- for (int b=0; b - -#include and +#include +#include +#include enum eyeContactTargets {LEFT_EYE, RIGHT_EYE, MOUTH}; @@ -164,9 +164,9 @@ class Head : public AvatarData { bool getDriveKeys(int key) { return driveKeys[key]; }; // Set/Get update the thrust that will move the avatar around - void setThrust(glm::vec3 newThrust) { avatar.thrust = newThrust; }; - void addThrust(glm::vec3 newThrust) { avatar.thrust += newThrust; }; - glm::vec3 getThrust() { return avatar.thrust; }; + void setThrust(glm::vec3 newThrust) { _avatar.thrust = newThrust; }; + void addThrust(glm::vec3 newThrust) { _avatar.thrust += newThrust; }; + glm::vec3 getThrust() { return _avatar.thrust; }; // // Related to getting transmitter UDP data used to animate the avatar hand @@ -210,39 +210,33 @@ class Head : public AvatarData { float audioAttack; float browAudioLift; - bool triggeringAction; - - float bodyYawDelta; - - float closeEnoughToInteract; - int closestOtherAvatar; //temporary - placeholder for real other avs glm::vec3 DEBUG_otherAvatarListPosition [ NUM_OTHER_AVATARS ]; float DEBUG_otherAvatarListTimer [ NUM_OTHER_AVATARS ]; - bool usingSprings; - - bool handBeingMoved; - bool previousHandBeingMoved; - glm::vec3 movedHandOffset; + bool _triggeringAction; + float _bodyYawDelta; + float _closeEnoughToInteract; + int _closestOtherAvatar; + bool _usingSprings; + bool _handBeingMoved; + bool _previousHandBeingMoved; + glm::vec3 _movedHandOffset; + float _springVelocityDecay; + float _springForce; + glm::quat _rotation; // the rotation of the avatar body as a whole + AvatarBone _bone[ NUM_AVATAR_BONES ]; + AvatarMode _mode; + Avatar _avatar; int driveKeys[MAX_DRIVE_KEYS]; - float springVelocityDecay; - float springForce; int eyeContact; eyeContactTargets eyeContactTarget; GLUquadric *sphere; - Avatar avatar; - - glm::quat rotation; // the rotation of the avatar body as a whole - - AvatarBone bone[ NUM_AVATAR_BONES ]; - - AvatarMode mode; float renderYaw, renderPitch; // Pitch from view frustum when this is own head. @@ -252,18 +246,16 @@ class Head : public AvatarData { timeval transmitterTimer; float transmitterHz; int transmitterPackets; - - //------------------------------------------- + //----------------------------- // private methods... - //------------------------------------------- + //----------------------------- void initializeAvatar(); void initializeSkeleton(); void updateSkeleton(); void initializeBodySprings(); void updateBodySprings( float deltaTime ); void calculateBoneLengths(); - void readSensors(); }; From 4b1ce1158f9dd26d1788a27cf0b6517ab9d12c91 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 17 Apr 2013 13:15:44 -0700 Subject: [PATCH 5/7] fix number of bytes for avatar processBulkAgentData --- interface/src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 851408b55e..9fb29cc6e2 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -1316,7 +1316,7 @@ void *networkReceive(void *args) AgentList::getInstance()->processBulkAgentData(&senderAddress, incomingPacket, bytesReceived, - (sizeof(float) * 3) + (sizeof(uint16_t) * 2)); + (sizeof(float) * 3) + (sizeof(uint16_t) * 3)); break; default: AgentList::getInstance()->processAgentData(&senderAddress, incomingPacket, bytesReceived); From 952cb2f2ae2bf4ba118656a3a55349874bb7b9f7 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Wed, 17 Apr 2013 15:14:30 -0700 Subject: [PATCH 6/7] Added head _isMine variable, added hand position transmission! --- interface/src/Head.cpp | 18 ++++++++++++------ interface/src/Head.h | 7 ++++--- interface/src/main.cpp | 8 ++++---- libraries/avatars/src/AvatarData.cpp | 14 ++++++++++++++ libraries/avatars/src/AvatarData.h | 2 ++ 5 files changed, 36 insertions(+), 13 deletions(-) diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 2fdb6efe72..0a7390613b 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -45,7 +45,7 @@ vector iris_texture; unsigned int iris_texture_width = 512; unsigned int iris_texture_height = 256; -Head::Head() { +Head::Head(bool isMine) { initializeAvatar(); _avatar.orientation.setToIdentity(); @@ -59,6 +59,7 @@ Head::Head() { _bodyYawDelta = 0.0; _triggeringAction = false; _mode = AVATAR_MODE_STANDING; + _isMine = isMine; initializeSkeleton(); @@ -529,7 +530,7 @@ void Head::simulate(float deltaTime) { -void Head::render(int faceToFace, int isMine) { +void Head::render(int faceToFace) { //--------------------------------------------------- // show avatar position @@ -553,7 +554,7 @@ void Head::render(int faceToFace, int isMine) { //--------------------------------------------------- // render head //--------------------------------------------------- - renderHead( faceToFace, isMine ); + renderHead(faceToFace); //--------------------------------------------------- // render other avatars (DEBUG TEST) @@ -613,7 +614,7 @@ void Head::renderOrientationDirections( glm::vec3 position, Orientation orientat -void Head::renderHead( int faceToFace, int isMine ) { +void Head::renderHead( int faceToFace) { int side = 0; glEnable(GL_DEPTH_TEST); @@ -659,6 +660,7 @@ void Head::renderHead( int faceToFace, int isMine ) { glColor3fv(skinColor); // Head + if (!_isMine) glColor3f(0,0,1); // Temp: Other people are BLUE glutSolidSphere(1, 30, 30); // Ears @@ -1059,8 +1061,8 @@ void Head::updateHandMovement() { + _avatar.orientation.getUp() * -_movedHandOffset.y * 0.5f + _avatar.orientation.getFront() * -_movedHandOffset.y; - _bone[ AVATAR_BONE_RIGHT_HAND ].position += transformedHandMovement; - + _bone[ AVATAR_BONE_RIGHT_HAND ].position += transformedHandMovement; + //if holding hands, add a pull to the hand... if ( _usingSprings ) { if ( _closestOtherAvatar != -1 ) { @@ -1142,6 +1144,10 @@ void Head::updateHandMovement() { glm::vec3 newWristPosition = _bone[ AVATAR_BONE_RIGHT_UPPER_ARM ].position; newWristPosition += vv * 0.7f; _bone[ AVATAR_BONE_RIGHT_FOREARM ].position = newWristPosition; + + // Set the vector we send for hand position to other people to be our right hand + setHandPosition(_bone[ AVATAR_BONE_RIGHT_HAND ].position); + } diff --git a/interface/src/Head.h b/interface/src/Head.h index 30fa9ba936..fae52332ab 100644 --- a/interface/src/Head.h +++ b/interface/src/Head.h @@ -103,7 +103,7 @@ struct Avatar class Head : public AvatarData { public: - Head(); + Head(bool isMine); ~Head(); Head(const Head &otherHead); Head* clone() const; @@ -143,10 +143,10 @@ class Head : public AvatarData { void setTriggeringAction( bool trigger ); - void render(int faceToFace, int isMine); + void render(int faceToFace); void renderBody(); - void renderHead( int faceToFace, int isMine ); + void renderHead( int faceToFace); //void renderOrientationDirections( glm::vec3 position, Orientation orientation, float size ); void simulate(float); @@ -178,6 +178,7 @@ class Head : public AvatarData { float getTransmitterHz() { return transmitterHz; }; private: + bool _isMine; float noise; float Pitch; float Yaw; diff --git a/interface/src/main.cpp b/interface/src/main.cpp index 547ac38a57..b2b7055db5 100644 --- a/interface/src/main.cpp +++ b/interface/src/main.cpp @@ -102,7 +102,7 @@ Oscilloscope audioScope(256,200,true); ViewFrustum viewFrustum; // current state of view frustum, perspective, orientation, etc. -Head myAvatar; // The rendered avatar of oneself +Head myAvatar(true); // The rendered avatar of oneself Camera myCamera; // My view onto the world (sometimes on myself :) Camera viewFrustumOffsetCamera; // The camera we use to sometimes show the view frustum from an offset mode @@ -826,7 +826,7 @@ void display(void) glPushMatrix(); glm::vec3 pos = agentHead->getBodyPosition(); glTranslatef(-pos.x, -pos.y, -pos.z); - agentHead->render(0, 0); + agentHead->render(0); glPopMatrix(); } } @@ -841,7 +841,7 @@ void display(void) //Render my own avatar - myAvatar.render( true, 1 ); + myAvatar.render(true); } glPopMatrix(); @@ -1494,7 +1494,7 @@ void mouseoverFunc( int x, int y) void attachNewHeadToAgent(Agent *newAgent) { if (newAgent->getLinkedData() == NULL) { - newAgent->setLinkedData(new Head()); + newAgent->setLinkedData(new Head(false)); } } diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index 0bf9ddff74..9be48b04ac 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -51,6 +51,7 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) { // TODO: DRY this up to a shared method // that can pack any type given the number of bytes // and return the number of bytes to push the pointer + memcpy(destinationBuffer, &_bodyPosition, sizeof(float) * 3); destinationBuffer += sizeof(float) * 3; @@ -58,6 +59,11 @@ int AvatarData::getBroadcastData(unsigned char* destinationBuffer) { destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _bodyPitch); destinationBuffer += packFloatAngleToTwoByte(destinationBuffer, _bodyRoll); + memcpy(destinationBuffer, &_handPosition, sizeof(float) * 3); + destinationBuffer += sizeof(float) * 3; + + //std::cout << _handPosition.x << ", " << _handPosition.y << ", " << _handPosition.z << "\n"; + return destinationBuffer - bufferStart; } @@ -73,6 +79,10 @@ void AvatarData::parseData(unsigned char* sourceBuffer, int numBytes) { sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t *)sourceBuffer, &_bodyYaw); sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t *)sourceBuffer, &_bodyPitch); sourceBuffer += unpackFloatAngleFromTwoByte((uint16_t *)sourceBuffer, &_bodyRoll); + + memcpy(&_handPosition, sourceBuffer, sizeof(float) * 3); + sourceBuffer += sizeof(float) * 3; + } glm::vec3 AvatarData::getBodyPosition() { @@ -85,6 +95,10 @@ void AvatarData::setBodyPosition(glm::vec3 bodyPosition) { _bodyPosition = bodyPosition; } +void AvatarData::setHandPosition(glm::vec3 handPosition) { + _handPosition = handPosition; +} + float AvatarData::getBodyYaw() { return _bodyYaw; } diff --git a/libraries/avatars/src/AvatarData.h b/libraries/avatars/src/AvatarData.h index 5e7f52a04d..b650a317f8 100644 --- a/libraries/avatars/src/AvatarData.h +++ b/libraries/avatars/src/AvatarData.h @@ -24,6 +24,7 @@ public: glm::vec3 getBodyPosition(); void setBodyPosition(glm::vec3 bodyPosition); + void setHandPosition(glm::vec3 handPosition); int getBroadcastData(unsigned char* destinationBuffer); void parseData(unsigned char* sourceBuffer, int numBytes); @@ -39,6 +40,7 @@ public: protected: glm::vec3 _bodyPosition; + glm::vec3 _handPosition; float _bodyYaw; float _bodyPitch; From 1a3df2be5f635b915a72ff254d3078233a0952de Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Wed, 17 Apr 2013 15:25:05 -0700 Subject: [PATCH 7/7] comment cleanup in AvatarData --- libraries/avatars/src/AvatarData.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/libraries/avatars/src/AvatarData.cpp b/libraries/avatars/src/AvatarData.cpp index 0bf9ddff74..c29789029f 100644 --- a/libraries/avatars/src/AvatarData.cpp +++ b/libraries/avatars/src/AvatarData.cpp @@ -43,8 +43,6 @@ AvatarData* AvatarData::clone() const { return new AvatarData(*this); } -// transmit data to agents requesting it -// called on me just prior to sending data to others (continuasly called) int AvatarData::getBroadcastData(unsigned char* destinationBuffer) { unsigned char* bufferStart = destinationBuffer;