From b703d0982e35bec61186be11d79593d350c81aa4 Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Fri, 3 May 2013 09:55:25 -0700 Subject: [PATCH] Changed avatar.h to store _distanceToNearestAvatar --- interface/src/Avatar.cpp | 15 +++++++++------ interface/src/Avatar.h | 1 + 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/interface/src/Avatar.cpp b/interface/src/Avatar.cpp index a1f9103d37..b1b1eb159a 100644 --- a/interface/src/Avatar.cpp +++ b/interface/src/Avatar.cpp @@ -142,6 +142,7 @@ Avatar::Avatar(bool isMine) { _interactingOther = NULL; //_canReachToOtherAvatar = false; _handHoldingPosition = glm::vec3( 0.0, 0.0, 0.0 ); + _distanceToNearestAvatar = std::numeric_limits::max(); initializeSkeleton(); @@ -230,6 +231,7 @@ Avatar::Avatar(const Avatar &otherAvatar) { _head.lastLoudness = otherAvatar._head.lastLoudness; _head.browAudioLift = otherAvatar._head.browAudioLift; _head.noise = otherAvatar._head.noise; + _distanceToNearestAvatar = otherAvatar._distanceToNearestAvatar; initializeSkeleton(); @@ -328,7 +330,6 @@ bool Avatar::getIsNearInteractingOther() { void Avatar::simulate(float deltaTime) { - float nearestAvatarDistance = std::numeric_limits::max(); //keep this - I'm still using it to test things.... /* @@ -360,8 +361,10 @@ _head.leanForward = 0.02 * sin( tt * 0.8 ); // if the avatar being simulated is mine, then loop through // all the other avatars for potential interactions... if ( _isMine ) - { - + { + // Reset detector for nearest avatar + _distanceToNearestAvatar = std::numeric_limits::max(); + AgentList* agentList = AgentList::getInstance(); for (AgentList::iterator agent = agentList->begin(); agent != agentList->end(); agent++) { if (agent->getLinkedData() != NULL && agent->getType() == AGENT_TYPE_AVATAR) { @@ -375,7 +378,7 @@ _head.leanForward = 0.02 * sin( tt * 0.8 ); v -= otherAvatar->getBonePosition( AVATAR_BONE_RIGHT_SHOULDER ); float distance = glm::length( v ); - if (distance < nearestAvatarDistance) { nearestAvatarDistance = distance; } + if (distance < _distanceToNearestAvatar) { _distanceToNearestAvatar = distance; } if (distance < _maxArmLength + _maxArmLength) { @@ -491,10 +494,10 @@ _head.leanForward = 0.02 * sin( tt * 0.8 ); // If someone is near, damp velocity as a function of closeness const float AVATAR_BRAKING_RANGE = 1.2f; const float AVATAR_BRAKING_STRENGTH = 25.f; - if (_isMine && (nearestAvatarDistance < AVATAR_BRAKING_RANGE)) { + if (_isMine && (_distanceToNearestAvatar < AVATAR_BRAKING_RANGE)) { _velocity *= (1.f - deltaTime * AVATAR_BRAKING_STRENGTH * - (AVATAR_BRAKING_RANGE - nearestAvatarDistance)); + (AVATAR_BRAKING_RANGE - _distanceToNearestAvatar)); } // update head information diff --git a/interface/src/Avatar.h b/interface/src/Avatar.h index fec8b6e4d0..f88e5fe848 100644 --- a/interface/src/Avatar.h +++ b/interface/src/Avatar.h @@ -263,6 +263,7 @@ private: AvatarTouch _avatarTouch; bool _displayingHead; // should be false if in first-person view bool _returnHeadToCenter; + float _distanceToNearestAvatar; // How close is the nearest avatar? // private methods... void initializeSkeleton();