From eca6999c2c6d040cd971d7e56d1046ee5688b4c6 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Wed, 24 Apr 2013 11:02:23 -0700 Subject: [PATCH 1/5] added behavior in Eve for alternating between grasping and ungrasping hand (tho unable to test transmission). Also, improved readability of hand grasping logic in Head.cpp --- eve/src/main.cpp | 15 ++++++++++++++- injector/src/main.cpp | 2 +- interface/src/Head.cpp | 32 ++++++++++++++++++++++++-------- interface/src/Head.h | 4 +--- 4 files changed, 40 insertions(+), 13 deletions(-) diff --git a/eve/src/main.cpp b/eve/src/main.cpp index 3e075f7ba0..0166f8e615 100644 --- a/eve/src/main.cpp +++ b/eve/src/main.cpp @@ -27,6 +27,7 @@ const float MAX_ITERATIONS_BETWEEN_AUDIO_SENDS = (MAX_AUDIO_SEND_INTERVAL_SECS * bool stopReceiveAgentDataThread; bool injectAudioThreadRunning = false; +int handStateTimer = 0; int TEMP_AUDIO_LISTEN_PORT = 55439; // UDPSocket audioSocket(TEMP_AUDIO_LISTEN_PORT); @@ -124,7 +125,19 @@ int main(int argc, const char* argv[]) { eve.setHandPosition(glm::vec3(eve.getPosition()[0] - 0.2, 0.25, eve.getPosition()[2] + 0.1)); - + + // simulate the effect of pressing and un-pressing the mouse button/pad + handStateTimer ++; + if ( handStateTimer == 100 ) { + eve.setHandState(1); + } + if ( handStateTimer == 150 ) { + eve.setHandState(0); + } + if ( handStateTimer >= 200 ) { + handStateTimer = 0; + } + // read eve's audio data AudioInjector eveAudioInjector("eve.raw"); diff --git a/injector/src/main.cpp b/injector/src/main.cpp index 61327ec41b..b110f7553c 100644 --- a/injector/src/main.cpp +++ b/injector/src/main.cpp @@ -91,7 +91,7 @@ bool processParameters(int parameterCount, char* parameterData[]) } } return true; -};_Position +}; int main(int argc, const char* argv[]) { diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 9770bcbce1..a34d061ab5 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -48,7 +48,6 @@ Head::Head(bool isMine) { _velocity = glm::vec3( 0.0, 0.0, 0.0 ); _thrust = glm::vec3( 0.0, 0.0, 0.0 ); _rotation = glm::quat( 0.0f, 0.0f, 0.0f, 0.0f ); - _nearOtherAvatar = false; _bodyYaw = -90.0; _bodyPitch = 0.0; _bodyRoll = 0.0; @@ -130,6 +129,7 @@ Head::Head(bool isMine) { } } + _otherAvatar.nearby = false; _otherAvatar.handPosition = glm::vec3( 0.0f, 0.0f, 0.0f ); _otherAvatar.handState = 0; } @@ -141,7 +141,7 @@ Head::Head(const Head &otherAvatar) { _velocity = otherAvatar._velocity; _thrust = otherAvatar._thrust; _rotation = otherAvatar._rotation; - _nearOtherAvatar = otherAvatar._nearOtherAvatar; + _otherAvatar.nearby = otherAvatar._otherAvatar.nearby; _bodyYaw = otherAvatar._bodyYaw; _bodyPitch = otherAvatar._bodyPitch; _bodyRoll = otherAvatar._bodyRoll; @@ -303,7 +303,7 @@ void Head::simulate(float deltaTime) { //------------------------------------------------------------- if ( _isMine ) { - _nearOtherAvatar = false; + _otherAvatar.nearby = false; float closestDistance = 10000.0f; AgentList * agentList = AgentList::getInstance(); @@ -341,7 +341,7 @@ void Head::simulate(float deltaTime) { if ( distance < _maxArmLength ) { if ( distance < closestDistance ) { closestDistance = distance; - _nearOtherAvatar = true; + _otherAvatar.nearby = true; _otherAvatar.handPosition = otherAvatar->getBonePosition( AVATAR_BONE_RIGHT_HAND ); _otherAvatar.handState = (int)otherAvatar->getHandState(); } @@ -669,7 +669,7 @@ void Head::render(bool lookingInMirror) { if ( _isMine ) { if (_usingBodySprings) { - if ( _nearOtherAvatar ) { + if ( _otherAvatar.nearby ) { glm::vec3 v1( _bone[ AVATAR_BONE_RIGHT_HAND ].position ); glm::vec3 v2( _otherAvatar.handPosition ); @@ -1130,12 +1130,28 @@ void Head::updateHandMovement( float deltaTime ) { setHandState(_mousePressed); + if ( _otherAvatar.nearby ) { + if ( _otherAvatar.handState == 1 ) { + printf( "(1)" ); + } + //else { + // printf( "(0)" ); + //} + + if ( _handState == 1 ) { + printf( "1" ); + } + else { + printf( "0" ); + } + } + //--------------------------------------------------------------------- // if holding hands with another avatar, add a force to the hand... //--------------------------------------------------------------------- - if (( getHandState() == 1 ) + if (( _handState == 1 ) || ( _otherAvatar.handState == 1 )) { - if ( _nearOtherAvatar ) { + if ( _otherAvatar.nearby ) { glm::vec3 vectorToOtherHand = _otherAvatar.handPosition - _handHolding.position; glm::vec3 vectorToMyHand = _bone[ AVATAR_BONE_RIGHT_HAND ].position - _handHolding.position; @@ -1151,7 +1167,7 @@ void Head::updateHandMovement( float deltaTime ) { _handHolding.position = _bone[ AVATAR_BONE_RIGHT_HAND ].position; _handHolding.velocity = glm::vec3( 0.0, 0.0, 0.0 ); } - + //------------------------------------------------------------------------------- // determine the arm vector //------------------------------------------------------------------------------- diff --git a/interface/src/Head.h b/interface/src/Head.h index 428ba2228a..1e0a346a35 100644 --- a/interface/src/Head.h +++ b/interface/src/Head.h @@ -102,11 +102,11 @@ struct AvatarHandHolding struct OtherAvatar { + bool nearby; glm::vec3 handPosition; int handState; }; - struct AvatarBone { AvatarBoneID parent; // which bone is this bone connected to? @@ -191,7 +191,6 @@ class Head : public AvatarData { glm::vec3 getHeadPosition(); glm::vec3 getBonePosition( AvatarBoneID b ); glm::vec3 getBodyUpDirection(); - //int getHandState(); float getGirth(); float getHeight(); @@ -233,7 +232,6 @@ class Head : public AvatarData { OtherAvatar _otherAvatar; bool _mousePressed; float _bodyYawDelta; - bool _nearOtherAvatar; bool _usingBodySprings; glm::vec3 _movedHandOffset; float _springVelocityDecay; From 4e7f1ee4227f3fd573e4bf7eaa152c9cd8d4c28b Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Wed, 24 Apr 2013 11:39:43 -0700 Subject: [PATCH 2/5] more cleanup of hand holding code --- eve/src/main.cpp | 2 +- interface/src/Head.cpp | 102 ++++++++++++++++++++--------------------- 2 files changed, 51 insertions(+), 53 deletions(-) diff --git a/eve/src/main.cpp b/eve/src/main.cpp index 0166f8e615..903a2e6c96 100644 --- a/eve/src/main.cpp +++ b/eve/src/main.cpp @@ -137,7 +137,7 @@ int main(int argc, const char* argv[]) { if ( handStateTimer >= 200 ) { handStateTimer = 0; } - + // read eve's audio data AudioInjector eveAudioInjector("eve.raw"); diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index a34d061ab5..cf78625d4f 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -59,7 +59,6 @@ Head::Head(bool isMine) { //_transmitterTimer = 0; _transmitterHz = 0.0; _transmitterPackets = 0; - //_numOtherAvatars = 0; initializeSkeleton(); @@ -307,8 +306,6 @@ void Head::simulate(float deltaTime) { float closestDistance = 10000.0f; AgentList * agentList = AgentList::getInstance(); - - //_numOtherAvatars = 0; for(std::vector::iterator agent = agentList->getAgents().begin(); agent != agentList->getAgents().end(); @@ -316,35 +313,31 @@ void Head::simulate(float deltaTime) { if (( agent->getLinkedData() != NULL && ( agent->getType() == AGENT_TYPE_AVATAR ) )) { Head *otherAvatar = (Head *)agent->getLinkedData(); - // if ( _numOtherAvatars < MAX_OTHER_AVATARS ) - { - - //------------------------------------------------------ - // check for collisions with other avatars and respond - //------------------------------------------------------ - updateAvatarCollisionDetectionAndResponse - ( - otherAvatar->getPosition(), - otherAvatar->getGirth(), - otherAvatar->getHeight(), - otherAvatar->getBodyUpDirection(), - deltaTime - ); - - //------------------------------------------------- - // test other avatar hand position for proximity - //------------------------------------------------ - glm::vec3 v( _bone[ AVATAR_BONE_RIGHT_SHOULDER ].position ); - v -= otherAvatar->getBonePosition( AVATAR_BONE_RIGHT_HAND ); - - float distance = glm::length( v ); - if ( distance < _maxArmLength ) { - if ( distance < closestDistance ) { - closestDistance = distance; - _otherAvatar.nearby = true; - _otherAvatar.handPosition = otherAvatar->getBonePosition( AVATAR_BONE_RIGHT_HAND ); - _otherAvatar.handState = (int)otherAvatar->getHandState(); - } + //------------------------------------------------------ + // check for collisions with other avatars and respond + //------------------------------------------------------ + updateAvatarCollisionDetectionAndResponse + ( + otherAvatar->getPosition(), + otherAvatar->getGirth(), + otherAvatar->getHeight(), + otherAvatar->getBodyUpDirection(), + deltaTime + ); + + //------------------------------------------------- + // test other avatar hand position for proximity + //------------------------------------------------ + glm::vec3 v( _bone[ AVATAR_BONE_RIGHT_SHOULDER ].position ); + v -= otherAvatar->getBonePosition( AVATAR_BONE_RIGHT_HAND ); + + float distance = glm::length( v ); + if ( distance < _maxArmLength ) { + if ( distance < closestDistance ) { + closestDistance = distance; + _otherAvatar.nearby = true; + _otherAvatar.handPosition = otherAvatar->getBonePosition( AVATAR_BONE_RIGHT_HAND ); + _otherAvatar.handState = (int)otherAvatar->getHandState(); } } } @@ -1130,13 +1123,14 @@ void Head::updateHandMovement( float deltaTime ) { setHandState(_mousePressed); + /* if ( _otherAvatar.nearby ) { if ( _otherAvatar.handState == 1 ) { printf( "(1)" ); } - //else { - // printf( "(0)" ); - //} + else { + printf( "(0)" ); + } if ( _handState == 1 ) { printf( "1" ); @@ -1145,27 +1139,31 @@ void Head::updateHandMovement( float deltaTime ) { printf( "0" ); } } + */ //--------------------------------------------------------------------- - // if holding hands with another avatar, add a force to the hand... + // if I am holding hands with another avatar, a force is added + // to my hand, causing it to move closer to the other avatar's hand... //--------------------------------------------------------------------- - if (( _handState == 1 ) - || ( _otherAvatar.handState == 1 )) { + if ( _isMine ) + { if ( _otherAvatar.nearby ) { - - glm::vec3 vectorToOtherHand = _otherAvatar.handPosition - _handHolding.position; - glm::vec3 vectorToMyHand = _bone[ AVATAR_BONE_RIGHT_HAND ].position - _handHolding.position; - - _handHolding.velocity *= 0.7; - _handHolding.velocity += ( vectorToOtherHand + vectorToMyHand ) * _handHolding.force * deltaTime; - _handHolding.position += _handHolding.velocity; - - _bone[ AVATAR_BONE_RIGHT_HAND ].position = _handHolding.position; - } - } - else { - _handHolding.position = _bone[ AVATAR_BONE_RIGHT_HAND ].position; - _handHolding.velocity = glm::vec3( 0.0, 0.0, 0.0 ); + if (( getHandState() == 1 ) + || ( _otherAvatar.handState == 1 )) { + glm::vec3 vectorToOtherHand = _otherAvatar.handPosition - _handHolding.position; + glm::vec3 vectorToMyHand = _bone[ AVATAR_BONE_RIGHT_HAND ].position - _handHolding.position; + + _handHolding.velocity *= 0.7; + _handHolding.velocity += ( vectorToOtherHand + vectorToMyHand ) * _handHolding.force * deltaTime; + _handHolding.position += _handHolding.velocity; + + _bone[ AVATAR_BONE_RIGHT_HAND ].position = _handHolding.position; + } + } + else { + _handHolding.position = _bone[ AVATAR_BONE_RIGHT_HAND ].position; + _handHolding.velocity = glm::vec3( 0.0, 0.0, 0.0 ); + } } //------------------------------------------------------------------------------- From 86086ef20c2d43617434eea8fcb16ef67d262edc Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Wed, 24 Apr 2013 14:52:04 -0700 Subject: [PATCH 3/5] just did a fairly major re-ordering of avatar interaction logic in Head.cpp --- interface/src/Head.cpp | 315 +++++++++++++++++++---------------------- interface/src/Head.h | 10 +- 2 files changed, 153 insertions(+), 172 deletions(-) diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index cf78625d4f..f736850d4b 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -67,54 +67,51 @@ Head::Head(bool isMine) { for (int i = 0; i < MAX_DRIVE_KEYS; i++) _driveKeys[i] = false; - _head.pupilSize = 0.10; - _head.interPupilDistance = 0.6; - _head.interBrowDistance = 0.75; - _head.nominalPupilSize = 0.10; - //_head.yaw = 0.0; - //_head.pitch = 0.0; - //_head.roll = 0.0; - _head.pitchRate = 0.0; - _head.yawRate = 0.0; - _head.rollRate = 0.0; - _head.eyebrowPitch[0] = -30; - _head.eyebrowPitch[1] = -30; - _head.eyebrowRoll [0] = 20; - _head.eyebrowRoll [1] = -20; - _head.mouthPitch = 0; - _head.mouthYaw = 0; - _head.mouthWidth = 1.0; - _head.mouthHeight = 0.2; - _head.eyeballPitch[0] = 0; - _head.eyeballPitch[1] = 0; - _head.eyeballScaleX = 1.2; - _head.eyeballScaleY = 1.5; - _head.eyeballScaleZ = 1.0; - _head.eyeballYaw[0] = 0; - _head.eyeballYaw[1] = 0; - _head.pitchTarget = 0; - _head.yawTarget = 0; - _head.noiseEnvelope = 1.0; - _head.pupilConverge = 10.0; - _head.leanForward = 0.0; - _head.leanSideways = 0.0; - _head.eyeContact = 1; - _head.eyeContactTarget = LEFT_EYE; - _head.scale = 1.0; - _head.audioAttack = 0.0; - _head.averageLoudness = 0.0; - _head.lastLoudness = 0.0; - _head.browAudioLift = 0.0; - _head.noise = 0; - - _movedHandOffset = glm::vec3( 0.0, 0.0, 0.0 ); - _usingBodySprings = true; - _springForce = 6.0f; - _springVelocityDecay = 16.0f; - _renderYaw = 0.0; - _renderPitch = 0.0; - - _sphere = NULL; + _head.pupilSize = 0.10; + _head.interPupilDistance = 0.6; + _head.interBrowDistance = 0.75; + _head.nominalPupilSize = 0.10; + _head.pitchRate = 0.0; + _head.yawRate = 0.0; + _head.rollRate = 0.0; + _head.eyebrowPitch[0] = -30; + _head.eyebrowPitch[1] = -30; + _head.eyebrowRoll [0] = 20; + _head.eyebrowRoll [1] = -20; + _head.mouthPitch = 0; + _head.mouthYaw = 0; + _head.mouthWidth = 1.0; + _head.mouthHeight = 0.2; + _head.eyeballPitch[0] = 0; + _head.eyeballPitch[1] = 0; + _head.eyeballScaleX = 1.2; + _head.eyeballScaleY = 1.5; + _head.eyeballScaleZ = 1.0; + _head.eyeballYaw[0] = 0; + _head.eyeballYaw[1] = 0; + _head.pitchTarget = 0; + _head.yawTarget = 0; + _head.noiseEnvelope = 1.0; + _head.pupilConverge = 10.0; + _head.leanForward = 0.0; + _head.leanSideways = 0.0; + _head.eyeContact = 1; + _head.eyeContactTarget = LEFT_EYE; + _head.scale = 1.0; + _head.audioAttack = 0.0; + _head.averageLoudness = 0.0; + _head.lastLoudness = 0.0; + _head.browAudioLift = 0.0; + _head.noise = 0; + _movedHandOffset = glm::vec3( 0.0, 0.0, 0.0 ); + _usingBodySprings = true; + _springForce = 6.0f; + _springVelocityDecay = 16.0f; + _renderYaw = 0.0; + _renderPitch = 0.0; + _sphere = NULL; + _interactingOther = NULL; + _interactingOtherIsNearby = false; _handHolding.position = glm::vec3( 0.0, 0.0, 0.0 ); _handHolding.velocity = glm::vec3( 0.0, 0.0, 0.0 ); @@ -127,39 +124,35 @@ Head::Head(bool isMine) { printLog("error %u: %s\n", error, lodepng_error_text(error)); } } - - _otherAvatar.nearby = false; - _otherAvatar.handPosition = glm::vec3( 0.0f, 0.0f, 0.0f ); - _otherAvatar.handState = 0; } Head::Head(const Head &otherAvatar) { - _velocity = otherAvatar._velocity; - _thrust = otherAvatar._thrust; - _rotation = otherAvatar._rotation; - _otherAvatar.nearby = otherAvatar._otherAvatar.nearby; - _bodyYaw = otherAvatar._bodyYaw; - _bodyPitch = otherAvatar._bodyPitch; - _bodyRoll = otherAvatar._bodyRoll; - _bodyYawDelta = otherAvatar._bodyYawDelta; - _mousePressed = otherAvatar._mousePressed; - _mode = otherAvatar._mode; - _isMine = otherAvatar._isMine; - _renderYaw = otherAvatar._renderYaw; - _renderPitch = otherAvatar._renderPitch; - _maxArmLength = otherAvatar._maxArmLength; - _transmitterTimer = otherAvatar._transmitterTimer; - _transmitterHz = otherAvatar._transmitterHz; - _transmitterPackets = otherAvatar._transmitterPackets; - _TEST_bigSphereRadius = otherAvatar._TEST_bigSphereRadius; - _TEST_bigSpherePosition = otherAvatar._TEST_bigSpherePosition; - _movedHandOffset = otherAvatar._movedHandOffset; - _usingBodySprings = otherAvatar._usingBodySprings; - _springForce = otherAvatar._springForce; - _springVelocityDecay = otherAvatar._springVelocityDecay; + _velocity = otherAvatar._velocity; + _thrust = otherAvatar._thrust; + _rotation = otherAvatar._rotation; + _interactingOtherIsNearby = otherAvatar._interactingOtherIsNearby; + _bodyYaw = otherAvatar._bodyYaw; + _bodyPitch = otherAvatar._bodyPitch; + _bodyRoll = otherAvatar._bodyRoll; + _bodyYawDelta = otherAvatar._bodyYawDelta; + _mousePressed = otherAvatar._mousePressed; + _mode = otherAvatar._mode; + _isMine = otherAvatar._isMine; + _renderYaw = otherAvatar._renderYaw; + _renderPitch = otherAvatar._renderPitch; + _maxArmLength = otherAvatar._maxArmLength; + _transmitterTimer = otherAvatar._transmitterTimer; + _transmitterHz = otherAvatar._transmitterHz; + _transmitterPackets = otherAvatar._transmitterPackets; + _TEST_bigSphereRadius = otherAvatar._TEST_bigSphereRadius; + _TEST_bigSpherePosition = otherAvatar._TEST_bigSpherePosition; + _movedHandOffset = otherAvatar._movedHandOffset; + _usingBodySprings = otherAvatar._usingBodySprings; + _springForce = otherAvatar._springForce; + _springVelocityDecay = otherAvatar._springVelocityDecay; _orientation.set( otherAvatar._orientation ); _sphere = NULL; @@ -172,9 +165,6 @@ Head::Head(const Head &otherAvatar) { _head.interPupilDistance = otherAvatar._head.interPupilDistance; _head.interBrowDistance = otherAvatar._head.interBrowDistance; _head.nominalPupilSize = otherAvatar._head.nominalPupilSize; - //_head.yaw = otherAvatar._head.yaw; - //_head.pitch = otherAvatar._head.pitch; - //_head.roll = otherAvatar._head.roll; _head.yawRate = otherAvatar._head.yawRate; _head.pitchRate = otherAvatar._head.pitchRate; _head.rollRate = otherAvatar._head.rollRate; @@ -208,7 +198,6 @@ Head::Head(const Head &otherAvatar) { _head.browAudioLift = otherAvatar._head.browAudioLift; _head.noise = otherAvatar._head.noise; - if (iris_texture.size() == 0) { switchToResourcesParentIfRequired(); unsigned error = lodepng::decode(iris_texture, iris_texture_width, iris_texture_height, iris_texture_file); @@ -295,16 +284,33 @@ void Head::setMousePressed( bool d ) { } void Head::simulate(float deltaTime) { + + //------------------------ + // update avatar skeleton + //------------------------ + updateSkeleton(); + + //------------------------------------------------------------ + // reset hand and arm positions according to hand movement + //------------------------------------------------------------ + updateHandMovement( deltaTime ); + + if ( !_interactingOtherIsNearby ) { + //initialize _handHolding + _handHolding.position = _bone[ AVATAR_BONE_RIGHT_HAND ].position; + _handHolding.velocity = glm::vec3( 0.0, 0.0, 0.0 ); + } + + _interactingOtherIsNearby = false; //------------------------------------------------------------- // if the avatar being simulated is mine, then loop through - // all the other avatars to get information about them... + // all the other avatars for potential interactions... //------------------------------------------------------------- if ( _isMine ) { - _otherAvatar.nearby = false; float closestDistance = 10000.0f; - + AgentList * agentList = AgentList::getInstance(); for(std::vector::iterator agent = agentList->getAgents().begin(); @@ -333,18 +339,44 @@ void Head::simulate(float deltaTime) { float distance = glm::length( v ); if ( distance < _maxArmLength ) { - if ( distance < closestDistance ) { + + //if ( distance < closestDistance ) { // perhaps I don't need this if we want to allow multi-avatar interactions + { closestDistance = distance; - _otherAvatar.nearby = true; - _otherAvatar.handPosition = otherAvatar->getBonePosition( AVATAR_BONE_RIGHT_HAND ); - _otherAvatar.handState = (int)otherAvatar->getHandState(); + _interactingOther = otherAvatar; + _interactingOtherIsNearby = true; + + //--------------------------------------------------------------------- + // if I am holding hands with another avatar, a force is applied + //--------------------------------------------------------------------- + if (( getHandState() == 1 ) + || ( _interactingOther->_handState == 1 )) { + glm::vec3 vectorToOtherHand = _interactingOther->_handPosition - _handHolding.position; + glm::vec3 vectorToMyHand = _bone[ AVATAR_BONE_RIGHT_HAND ].position - _handHolding.position; + + _handHolding.velocity *= 0.7; + _handHolding.velocity += ( vectorToOtherHand + vectorToMyHand ) * _handHolding.force * deltaTime; + _handHolding.position += _handHolding.velocity; + + _bone[ AVATAR_BONE_RIGHT_HAND ].position = _handHolding.position; + } } } } } - }//if ( _isMine ) + // Set the vector we send for hand position to other people to be our right hand + setHandPosition(_bone[ AVATAR_BONE_RIGHT_HAND ].position); + }//if ( _isMine ) + + + updateArmIKAndConstraints( deltaTime ); + + if ( ! _interactingOtherIsNearby ) { + _interactingOther = NULL; + } + if ( usingBigSphereCollisionTest ) { //-------------------------------------------------------------- // test for avatar collision response (using a big sphere :) @@ -371,19 +403,10 @@ void Head::simulate(float deltaTime) { } } - //------------------------ - // update avatar skeleton - //------------------------ - updateSkeleton(); - - //------------------------------------------------------------ - // reset hand and arm positions according to hand movement - //------------------------------------------------------------ - if (_usingBodySprings) { - updateHandMovement( deltaTime ); - updateBodySprings( deltaTime ); - } - + // update body springs + updateBodySprings( deltaTime ); + + if ( _isMine ) { // driving the avatar around should only apply if this is my avatar (as opposed to an avatar being driven remotely) //------------------------------------------------- // this handles the avatar being driven around... @@ -442,7 +465,6 @@ void Head::simulate(float deltaTime) { _bodyYaw += _bodyYawDelta * deltaTime; } - //---------------------------------------------------------- // decay body yaw delta //---------------------------------------------------------- @@ -620,8 +642,6 @@ void Head::updateAvatarCollisionDetectionAndResponse } - - void Head::render(bool lookingInMirror) { //--------------------------------------------------- @@ -646,9 +666,9 @@ void Head::render(bool lookingInMirror) { glPopMatrix(); } - //--------------------------------------------------- + //--------------- // render body - //--------------------------------------------------- + //--------------- renderBody(); //--------------------------------------------------- @@ -657,28 +677,25 @@ void Head::render(bool lookingInMirror) { renderHead(lookingInMirror); //--------------------------------------------------------------------------- - // if this is my avatar, then render my interactions with the other avatars + // if this is my avatar, then render my interactions with the other avatar //--------------------------------------------------------------------------- if ( _isMine ) { - if (_usingBodySprings) { - if ( _otherAvatar.nearby ) { + if ( _interactingOtherIsNearby ) { - glm::vec3 v1( _bone[ AVATAR_BONE_RIGHT_HAND ].position ); - glm::vec3 v2( _otherAvatar.handPosition ); - - glLineWidth( 8.0 ); - glColor4f( 0.7f, 0.4f, 0.1f, 0.6 ); - glBegin( GL_LINE_STRIP ); - glVertex3f( v1.x, v1.y, v1.z ); - glVertex3f( v2.x, v2.y, v2.z ); - glEnd(); - } + glm::vec3 v1( _bone[ AVATAR_BONE_RIGHT_HAND ].position ); + glm::vec3 v2( _interactingOther->_handPosition ); + + glLineWidth( 8.0 ); + glColor4f( 0.7f, 0.4f, 0.1f, 0.6 ); + glBegin( GL_LINE_STRIP ); + glVertex3f( v1.x, v1.y, v1.z ); + glVertex3f( v2.x, v2.y, v2.z ); + glEnd(); } } } - void Head::renderHead(bool lookingInMirror) { int side = 0; @@ -962,9 +979,9 @@ void Head::initializeSkeleton() { //---------------------------------------------------------------------------- calculateBoneLengths(); - //---------------------------------------------------------------------------- + //--------------------------- // generate world positions - //---------------------------------------------------------------------------- + //--------------------------- updateSkeleton(); } @@ -1121,51 +1138,14 @@ void Head::updateHandMovement( float deltaTime ) { _bone[ AVATAR_BONE_RIGHT_HAND ].position += transformedHandMovement; - setHandState(_mousePressed); - - /* - if ( _otherAvatar.nearby ) { - if ( _otherAvatar.handState == 1 ) { - printf( "(1)" ); - } - else { - printf( "(0)" ); - } + if (_isMine) { + setHandState(_mousePressed); + } +} + + +void Head::updateArmIKAndConstraints( float deltaTime ) { - if ( _handState == 1 ) { - printf( "1" ); - } - else { - printf( "0" ); - } - } - */ - - //--------------------------------------------------------------------- - // if I am holding hands with another avatar, a force is added - // to my hand, causing it to move closer to the other avatar's hand... - //--------------------------------------------------------------------- - if ( _isMine ) - { - if ( _otherAvatar.nearby ) { - if (( getHandState() == 1 ) - || ( _otherAvatar.handState == 1 )) { - glm::vec3 vectorToOtherHand = _otherAvatar.handPosition - _handHolding.position; - glm::vec3 vectorToMyHand = _bone[ AVATAR_BONE_RIGHT_HAND ].position - _handHolding.position; - - _handHolding.velocity *= 0.7; - _handHolding.velocity += ( vectorToOtherHand + vectorToMyHand ) * _handHolding.force * deltaTime; - _handHolding.position += _handHolding.velocity; - - _bone[ AVATAR_BONE_RIGHT_HAND ].position = _handHolding.position; - } - } - else { - _handHolding.position = _bone[ AVATAR_BONE_RIGHT_HAND ].position; - _handHolding.velocity = glm::vec3( 0.0, 0.0, 0.0 ); - } - } - //------------------------------------------------------------------------------- // determine the arm vector //------------------------------------------------------------------------------- @@ -1210,14 +1190,11 @@ void Head::updateHandMovement( float deltaTime ) { 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); - } + void Head::renderBody() { //----------------------------------------- // Render bone positions as spheres diff --git a/interface/src/Head.h b/interface/src/Head.h index 1e0a346a35..377228986d 100644 --- a/interface/src/Head.h +++ b/interface/src/Head.h @@ -100,12 +100,14 @@ struct AvatarHandHolding float force; }; +/* struct OtherAvatar { bool nearby; - glm::vec3 handPosition; - int handState; + //glm::vec3 handPosition; + //int handState; }; +*/ struct AvatarBone { @@ -205,6 +207,7 @@ class Head : public AvatarData { void stopHandMovement(); void setHandMovementValues( glm::vec3 movement ); void updateHandMovement( float deltaTime ); + void updateArmIKAndConstraints( float deltaTime ); float getAverageLoudness() {return _head.averageLoudness;}; void setAverageLoudness(float al) {_head.averageLoudness = al;}; @@ -229,7 +232,6 @@ class Head : public AvatarData { bool _isMine; glm::vec3 _TEST_bigSpherePosition; float _TEST_bigSphereRadius; - OtherAvatar _otherAvatar; bool _mousePressed; float _bodyYawDelta; bool _usingBodySprings; @@ -251,6 +253,8 @@ class Head : public AvatarData { timeval _transmitterTimer; float _transmitterHz; int _transmitterPackets; + Head* _interactingOther; + bool _interactingOtherIsNearby; //----------------------------- // private methods... From e93430d553e5193319d49dd168def882e40baba5 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Wed, 24 Apr 2013 14:56:29 -0700 Subject: [PATCH 4/5] fix --- interface/src/Head.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index f9a4a51dab..94e36c5673 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -1148,7 +1148,8 @@ void Head::updateHandMovement( float deltaTime ) { _bone[ AVATAR_BONE_RIGHT_HAND ].position += transformedHandMovement; if (_isMine) { - setHandState(_mousePressed); + //setHandState(_mousePressed); + _handState = _mousePressed; } } From a9ff483d3d03f6db08827dbe73a502602aa3309b Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Wed, 24 Apr 2013 15:35:11 -0700 Subject: [PATCH 5/5] fix --- interface/src/Head.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/interface/src/Head.cpp b/interface/src/Head.cpp index 94e36c5673..1e6e78fef2 100644 --- a/interface/src/Head.cpp +++ b/interface/src/Head.cpp @@ -349,7 +349,7 @@ void Head::simulate(float deltaTime) { //--------------------------------------------------------------------- // if I am holding hands with another avatar, a force is applied //--------------------------------------------------------------------- - if (( getHandState() == 1 ) + if (( _handState == 1 ) || ( _interactingOther->_handState == 1 )) { glm::vec3 vectorToOtherHand = _interactingOther->_handPosition - _handHolding.position; glm::vec3 vectorToMyHand = _bone[ AVATAR_BONE_RIGHT_HAND ].position - _handHolding.position; @@ -1148,7 +1148,6 @@ void Head::updateHandMovement( float deltaTime ) { _bone[ AVATAR_BONE_RIGHT_HAND ].position += transformedHandMovement; if (_isMine) { - //setHandState(_mousePressed); _handState = _mousePressed; } }