improved avatar hand-holding logic

This commit is contained in:
Jeffrey Ventrella 2013-04-24 08:13:15 -07:00
parent 8135a45ccf
commit ee9ae3f220

View file

@ -1006,11 +1006,14 @@ void Head::updateSkeleton() {
_bone[b].position = _bone[ _bone[b].parent ].position; _bone[b].position = _bone[ _bone[b].parent ].position;
} }
///TEST! - get this working and then add a comment; JJV //-------------------------------------------------------------------------------------
// if this is not my avatar, then hand position comes from transmitted data
//-------------------------------------------------------------------------------------
if ( ! _isMine ) { if ( ! _isMine ) {
_bone[ AVATAR_BONE_RIGHT_HAND ].position = _handPosition; _bone[ AVATAR_BONE_RIGHT_HAND ].position = _handPosition;
} }
// the following will be replaced by a proper rotation...
float xx = glm::dot( _bone[b].defaultPosePosition, _bone[b].orientation.getRight() ); float xx = glm::dot( _bone[b].defaultPosePosition, _bone[b].orientation.getRight() );
float yy = glm::dot( _bone[b].defaultPosePosition, _bone[b].orientation.getUp () ); float yy = glm::dot( _bone[b].defaultPosePosition, _bone[b].orientation.getUp () );
float zz = glm::dot( _bone[b].defaultPosePosition, _bone[b].orientation.getFront() ); float zz = glm::dot( _bone[b].defaultPosePosition, _bone[b].orientation.getFront() );
@ -1024,7 +1027,6 @@ void Head::updateSkeleton() {
} }
} }
void Head::initializeBodySprings() { void Head::initializeBodySprings() {
for (int b=0; b<NUM_AVATAR_BONES; b++) { for (int b=0; b<NUM_AVATAR_BONES; b++) {
_bone[b].springyPosition = _bone[b].position; _bone[b].springyPosition = _bone[b].position;
@ -1128,31 +1130,22 @@ void Head::updateHandMovement( float deltaTime ) {
setHandState(_mousePressed); setHandState(_mousePressed);
bool atLeastOneAvatarIsGrasping = false;
if ( getHandState() == 1 ) { atLeastOneAvatarIsGrasping = true; }
//if ( _isMine ) {
//if ( _otherAvatar.handState == 1 ) {
if ( _nearOtherAvatar ) {
atLeastOneAvatarIsGrasping = true;
}
//}
//}
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// if holding hands with another avatar, add a force to the hand... // if holding hands with another avatar, add a force to the hand...
//--------------------------------------------------------------------- //---------------------------------------------------------------------
if ( atLeastOneAvatarIsGrasping ) { if (( getHandState() == 1 )
|| ( _otherAvatar.handState == 1 )) {
glm::vec3 vectorToOtherHand = _otherAvatar.handPosition - _handHolding.position; if ( _nearOtherAvatar ) {
glm::vec3 vectorToMyHand = _bone[ AVATAR_BONE_RIGHT_HAND ].position - _handHolding.position;
glm::vec3 vectorToOtherHand = _otherAvatar.handPosition - _handHolding.position;
_handHolding.velocity *= 0.7; glm::vec3 vectorToMyHand = _bone[ AVATAR_BONE_RIGHT_HAND ].position - _handHolding.position;
_handHolding.velocity += ( vectorToOtherHand + vectorToMyHand ) * _handHolding.force * deltaTime;
_handHolding.position += _handHolding.velocity; _handHolding.velocity *= 0.7;
_handHolding.velocity += ( vectorToOtherHand + vectorToMyHand ) * _handHolding.force * deltaTime;
_bone[ AVATAR_BONE_RIGHT_HAND ].position = _handHolding.position; _handHolding.position += _handHolding.velocity;
_bone[ AVATAR_BONE_RIGHT_HAND ].position = _handHolding.position;
}
} }
else { else {
_handHolding.position = _bone[ AVATAR_BONE_RIGHT_HAND ].position; _handHolding.position = _bone[ AVATAR_BONE_RIGHT_HAND ].position;