From b98d03337d911293649132995cc7c05d3c7f74a0 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Tue, 28 May 2013 18:49:16 -0700 Subject: [PATCH 1/2] fixed bug causing camera to not get updated position of other av --- interface/src/Avatar.cpp | 3 ++ interface/src/AvatarTouch.cpp | 55 +++++++++++++++++++++-------------- interface/src/AvatarTouch.h | 2 ++ 3 files changed, 38 insertions(+), 22 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index 3981d4f76d..25e1764025 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -509,6 +509,7 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { if (_interactingOther) { + _avatarTouch.setHasInteractingOther(true); _avatarTouch.setYourBodyPosition(_interactingOther->_position); _avatarTouch.setYourOrientation (_interactingOther->_orientation); _avatarTouch.setYourHandPosition(_interactingOther->_joint[ AVATAR_JOINT_RIGHT_FINGERTIPS ].springyPosition); @@ -561,6 +562,8 @@ void Avatar::updateHandMovementAndTouching(float deltaTime) { _velocity += vectorFromMyHandToYourHand * force; } } + } else { + _avatarTouch.setHasInteractingOther(false); } }//if (_isMine) diff --git a/interface/src/AvatarTouch.cpp b/interface/src/AvatarTouch.cpp index 16c8cc64c7..0d2157cbad 100644 --- a/interface/src/AvatarTouch.cpp +++ b/interface/src/AvatarTouch.cpp @@ -28,6 +28,7 @@ AvatarTouch::AvatarTouch() { _weAreHoldingHands = false; _canReachToOtherAvatar = false; _handsCloseEnoughToGrasp = false; + _hasInteractingOther = false; _myOrientation.setToIdentity(); _yourOrientation.setToIdentity(); @@ -36,36 +37,46 @@ AvatarTouch::AvatarTouch() { } } + +void AvatarTouch::setHasInteractingOther(bool hasInteractingOther) { + _hasInteractingOther = hasInteractingOther; +} + + void AvatarTouch::simulate (float deltaTime) { - glm::vec3 vectorBetweenBodies = _yourBodyPosition - _myBodyPosition; - float distanceBetweenBodies = glm::length(vectorBetweenBodies); - glm::vec3 directionBetweenBodies = vectorBetweenBodies / distanceBetweenBodies; - - bool facingEachOther = false; - - if (( glm::dot(_myOrientation.getFront(), _yourOrientation.getFront()) < -AVATAR_FACING_THRESHOLD) - && ( glm::dot(_myOrientation.getFront(), directionBetweenBodies ) > AVATAR_FACING_THRESHOLD)) { - facingEachOther = true; - } + _canReachToOtherAvatar = false; // default - if ((distanceBetweenBodies < _reachableRadius) - && (facingEachOther)) { - _vectorBetweenHands = _yourHandPosition - _myHandPosition; + if (_hasInteractingOther) { + + glm::vec3 vectorBetweenBodies = _yourBodyPosition - _myBodyPosition; + float distanceBetweenBodies = glm::length(vectorBetweenBodies); + glm::vec3 directionBetweenBodies = vectorBetweenBodies / distanceBetweenBodies; - float distanceBetweenHands = glm::length(_vectorBetweenHands); - if (distanceBetweenHands < HANDS_CLOSE_ENOUGH_TO_GRASP) { - _handsCloseEnoughToGrasp = true; - } else { - _handsCloseEnoughToGrasp = false; + bool facingEachOther = false; + + if (( glm::dot(_myOrientation.getFront(), _yourOrientation.getFront()) < -AVATAR_FACING_THRESHOLD) // we're facing each other + && ( glm::dot(_myOrientation.getFront(), directionBetweenBodies ) > AVATAR_FACING_THRESHOLD)) { // I'm facing you + facingEachOther = true; } - _canReachToOtherAvatar = true; - } else { - _canReachToOtherAvatar = false; - } + if ((distanceBetweenBodies < _reachableRadius) + && (facingEachOther)) { + _canReachToOtherAvatar = true; + + _vectorBetweenHands = _yourHandPosition - _myHandPosition; + + float distanceBetweenHands = glm::length(_vectorBetweenHands); + if (distanceBetweenHands < HANDS_CLOSE_ENOUGH_TO_GRASP) { + _handsCloseEnoughToGrasp = true; + } else { + _handsCloseEnoughToGrasp = false; + } + } + } } + void AvatarTouch::render(glm::vec3 cameraPosition) { if (_canReachToOtherAvatar) { diff --git a/interface/src/AvatarTouch.h b/interface/src/AvatarTouch.h index fb90efa5fd..dd45d3bd44 100644 --- a/interface/src/AvatarTouch.h +++ b/interface/src/AvatarTouch.h @@ -28,6 +28,7 @@ public: void simulate(float deltaTime); void render(glm::vec3 cameraPosition); + void setHasInteractingOther(bool hasInteractingOther); void setMyHandPosition (glm::vec3 position ) { _myHandPosition = position; } void setYourHandPosition(glm::vec3 position ) { _yourHandPosition = position; } void setMyOrientation (Orientation orientation) { _myOrientation = orientation; } @@ -47,6 +48,7 @@ private: static const int NUM_POINTS = 100; + bool _hasInteractingOther; bool _weAreHoldingHands; glm::vec3 _point [NUM_POINTS]; glm::vec3 _myBodyPosition; From 0e329af03eafce530b6e9ae2decf807a838577a2 Mon Sep 17 00:00:00 2001 From: Jeffrey Ventrella Date: Tue, 28 May 2013 18:55:21 -0700 Subject: [PATCH 2/2] made inline --- interface/src/AvatarTouch.cpp | 6 ------ interface/src/AvatarTouch.h | 22 +++++++++++----------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/interface/src/AvatarTouch.cpp b/interface/src/AvatarTouch.cpp index 0d2157cbad..499e132922 100644 --- a/interface/src/AvatarTouch.cpp +++ b/interface/src/AvatarTouch.cpp @@ -37,12 +37,6 @@ AvatarTouch::AvatarTouch() { } } - -void AvatarTouch::setHasInteractingOther(bool hasInteractingOther) { - _hasInteractingOther = hasInteractingOther; -} - - void AvatarTouch::simulate (float deltaTime) { _canReachToOtherAvatar = false; // default diff --git a/interface/src/AvatarTouch.h b/interface/src/AvatarTouch.h index dd45d3bd44..6b6b75d956 100644 --- a/interface/src/AvatarTouch.h +++ b/interface/src/AvatarTouch.h @@ -28,17 +28,17 @@ public: void simulate(float deltaTime); void render(glm::vec3 cameraPosition); - void setHasInteractingOther(bool hasInteractingOther); - void setMyHandPosition (glm::vec3 position ) { _myHandPosition = position; } - void setYourHandPosition(glm::vec3 position ) { _yourHandPosition = position; } - void setMyOrientation (Orientation orientation) { _myOrientation = orientation; } - void setYourOrientation (Orientation orientation) { _yourOrientation = orientation; } - void setMyBodyPosition (glm::vec3 position ) { _myBodyPosition = position; } - void setYourBodyPosition(glm::vec3 position ) { _yourBodyPosition = position; } - void setMyHandState (int state ) { _myHandState = state; } - void setYourHandState (int state ) { _yourHandState = state; } - void setReachableRadius (float radius ) { _reachableRadius = radius; } - void setHoldingHands (bool holding ) { _weAreHoldingHands = holding; } + void setHasInteractingOther(bool hasInteractingOther) { _hasInteractingOther = hasInteractingOther;} + void setMyHandPosition (glm::vec3 position ) { _myHandPosition = position;} + void setYourHandPosition (glm::vec3 position ) { _yourHandPosition = position;} + void setMyOrientation (Orientation orientation ) { _myOrientation = orientation;} + void setYourOrientation (Orientation orientation ) { _yourOrientation = orientation;} + void setMyBodyPosition (glm::vec3 position ) { _myBodyPosition = position;} + void setYourBodyPosition (glm::vec3 position ) { _yourBodyPosition = position;} + void setMyHandState (int state ) { _myHandState = state;} + void setYourHandState (int state ) { _yourHandState = state;} + void setReachableRadius (float radius ) { _reachableRadius = radius;} + void setHoldingHands (bool holding ) { _weAreHoldingHands = holding;} bool getAbleToReachOtherAvatar () const {return _canReachToOtherAvatar; } bool getHandsCloseEnoughToGrasp() const {return _handsCloseEnoughToGrasp;}