History

more cleanup of hand holding code

Jeffrey Ventrella committed 13 years ago

Commit 4e7f1ee1 parent eca69992 files · +51 −53Browse files

Showing the changes to interface/src/Head.cpp (1 of 2 files). Show all

Unified · Split

interface/src/Head.cpp+50−52
@@ -59,7 +59,6 @@ Head::Head(bool isMine) { · 58 unmodified lines
5959 //_transmitterTimer = 0;
6060 _transmitterHz = 0.0;
6161 _transmitterPackets = 0;
62− //_numOtherAvatars = 0;
6362
6463 initializeSkeleton();
6564
@@ -307,8 +306,6 @@ void Head::simulate(float deltaTime) { · 241 unmodified lines
307306 float closestDistance = 10000.0f;
308307
309308 AgentList * agentList = AgentList::getInstance();
310−
311− //_numOtherAvatars = 0;
312309
313310 for(std::vector<Agent>::iterator agent = agentList->getAgents().begin();
314311 agent != agentList->getAgents().end();
@@ -316,35 +313,31 @@ void Head::simulate(float deltaTime) { · 1 unmodified line
316313 if (( agent->getLinkedData() != NULL && ( agent->getType() == AGENT_TYPE_AVATAR ) )) {
317314 Head *otherAvatar = (Head *)agent->getLinkedData();
318315
319− // if ( _numOtherAvatars < MAX_OTHER_AVATARS )
320− {
321−
322− //------------------------------------------------------
323− // check for collisions with other avatars and respond
324− //------------------------------------------------------
325− updateAvatarCollisionDetectionAndResponse
326− (
327− otherAvatar->getPosition(),
328− otherAvatar->getGirth(),
329− otherAvatar->getHeight(),
330− otherAvatar->getBodyUpDirection(),
331− deltaTime
332− );
333−
334− //-------------------------------------------------
335− // test other avatar hand position for proximity
336− //------------------------------------------------
337− glm::vec3 v( _bone[ AVATAR_BONE_RIGHT_SHOULDER ].position );
338− v -= otherAvatar->getBonePosition( AVATAR_BONE_RIGHT_HAND );
339−
340− float distance = glm::length( v );
341− if ( distance < _maxArmLength ) {
342− if ( distance < closestDistance ) {
343− closestDistance = distance;
344− _otherAvatar.nearby = true;
345− _otherAvatar.handPosition = otherAvatar->getBonePosition( AVATAR_BONE_RIGHT_HAND );
346− _otherAvatar.handState = (int)otherAvatar->getHandState();
347− }
316+ //------------------------------------------------------
317+ // check for collisions with other avatars and respond
318+ //------------------------------------------------------
319+ updateAvatarCollisionDetectionAndResponse
320+ (
321+ otherAvatar->getPosition(),
322+ otherAvatar->getGirth(),
323+ otherAvatar->getHeight(),
324+ otherAvatar->getBodyUpDirection(),
325+ deltaTime
326+ );
327+
328+ //-------------------------------------------------
329+ // test other avatar hand position for proximity
330+ //------------------------------------------------
331+ glm::vec3 v( _bone[ AVATAR_BONE_RIGHT_SHOULDER ].position );
332+ v -= otherAvatar->getBonePosition( AVATAR_BONE_RIGHT_HAND );
333+
334+ float distance = glm::length( v );
335+ if ( distance < _maxArmLength ) {
336+ if ( distance < closestDistance ) {
337+ closestDistance = distance;
338+ _otherAvatar.nearby = true;
339+ _otherAvatar.handPosition = otherAvatar->getBonePosition( AVATAR_BONE_RIGHT_HAND );
340+ _otherAvatar.handState = (int)otherAvatar->getHandState();
348341 }
349342 }
350343 }
@@ -1130,13 +1123,14 @@ void Head::updateHandMovement( float deltaTime ) { · 779 unmodified lines
11301123
11311124 setHandState(_mousePressed);
11321125
1126+ /*
11331127 if ( _otherAvatar.nearby ) {
11341128 if ( _otherAvatar.handState == 1 ) {
11351129 printf( "(1)" );
11361130 }
1137− //else {
1138− // printf( "(0)" );
1139− //}
1131+ else {
1132+ printf( "(0)" );
1133+ }
11401134
11411135 if ( _handState == 1 ) {
11421136 printf( "1" );
@@ -1145,27 +1139,31 @@ void Head::updateHandMovement( float deltaTime ) { · 2 unmodified lines
11451139 printf( "0" );
11461140 }
11471141 }
1142+ */
11481143
11491144 //---------------------------------------------------------------------
1150− // if holding hands with another avatar, add a force to the hand...
1145+ // if I am holding hands with another avatar, a force is added
1146+ // to my hand, causing it to move closer to the other avatar's hand...
11511147 //---------------------------------------------------------------------
1152− if (( _handState == 1 )
1153− || ( _otherAvatar.handState == 1 )) {
1148+ if ( _isMine )
1149+ {
11541150 if ( _otherAvatar.nearby ) {
1155−
1156− glm::vec3 vectorToOtherHand = _otherAvatar.handPosition - _handHolding.position;
1157− glm::vec3 vectorToMyHand = _bone[ AVATAR_BONE_RIGHT_HAND ].position - _handHolding.position;
1158−
1159− _handHolding.velocity *= 0.7;
1160− _handHolding.velocity += ( vectorToOtherHand + vectorToMyHand ) * _handHolding.force * deltaTime;
1161− _handHolding.position += _handHolding.velocity;
1162−
1163− _bone[ AVATAR_BONE_RIGHT_HAND ].position = _handHolding.position;
1164− }
1165− }
1166− else {
1167− _handHolding.position = _bone[ AVATAR_BONE_RIGHT_HAND ].position;
1168− _handHolding.velocity = glm::vec3( 0.0, 0.0, 0.0 );
1151+ if (( getHandState() == 1 )
1152+ || ( _otherAvatar.handState == 1 )) {
1153+ glm::vec3 vectorToOtherHand = _otherAvatar.handPosition - _handHolding.position;
1154+ glm::vec3 vectorToMyHand = _bone[ AVATAR_BONE_RIGHT_HAND ].position - _handHolding.position;
1155+
1156+ _handHolding.velocity *= 0.7;
1157+ _handHolding.velocity += ( vectorToOtherHand + vectorToMyHand ) * _handHolding.force * deltaTime;
1158+ _handHolding.position += _handHolding.velocity;
1159+
1160+ _bone[ AVATAR_BONE_RIGHT_HAND ].position = _handHolding.position;
1161+ }
1162+ }
1163+ else {
1164+ _handHolding.position = _bone[ AVATAR_BONE_RIGHT_HAND ].position;
1165+ _handHolding.velocity = glm::vec3( 0.0, 0.0, 0.0 );
1166+ }
11691167 }
11701168
11711169 //-------------------------------------------------------------------------------

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t