diff --git a/interface/src/avatar/MyAvatar.cpp b/interface/src/avatar/MyAvatar.cpp index acd1728388..30dd2bdd34 100644 --- a/interface/src/avatar/MyAvatar.cpp +++ b/interface/src/avatar/MyAvatar.cpp @@ -1767,14 +1767,12 @@ void MyAvatar::lateUpdatePalms() { static const float FOLLOW_TIME = 0.5f; void MyAvatar::FollowHelper::deactivate() { - _timeTotal = FOLLOW_TIME; _timeRemaining = 0.0f; } void MyAvatar::FollowHelper::activate() { - // TODO: the follow time should be proportional to the displacement. + // TODO: Perhaps, the follow time should be proportional to the displacement. _timeRemaining = FOLLOW_TIME; - _timeTotal = FOLLOW_TIME; } bool MyAvatar::FollowHelper::isActive() const { @@ -1795,10 +1793,10 @@ bool MyAvatar::FollowHelper::shouldActivate(const MyAvatar& myAvatar, const glm: const float CYLINDER_RADIUS = 0.15f; glm::vec3 offset = extractTranslation(desiredBodyMatrix) - extractTranslation(currentBodyMatrix); - glm::vec3 truncatedOffset(offset.x, 0.0f, offset.y); - float truncatedDistance = glm::length(truncatedOffset); + glm::vec3 radialOffset(offset.x, 0.0f, offset.y); + float radialDistance = glm::length(radialOffset); - return (offset.y > CYLINDER_TOP) || (offset.y < CYLINDER_BOTTOM) || (truncatedDistance > CYLINDER_RADIUS); + return (offset.y > CYLINDER_TOP) || (offset.y < CYLINDER_BOTTOM) || (radialDistance > CYLINDER_RADIUS); } void MyAvatar::FollowHelper::prePhysicsUpdate(MyAvatar& myAvatar, const glm::mat4& desiredBodyMatrix, const glm::mat4& currentBodyMatrix) { diff --git a/interface/src/avatar/MyAvatar.h b/interface/src/avatar/MyAvatar.h index a32dfc298d..a911218991 100644 --- a/interface/src/avatar/MyAvatar.h +++ b/interface/src/avatar/MyAvatar.h @@ -377,7 +377,6 @@ private: struct FollowHelper { glm::mat4 _desiredBodyMatrix; float _timeRemaining { 0.0f }; - float _timeTotal { 0.0f }; void deactivate(); void activate(); diff --git a/libraries/physics/src/CharacterController.cpp b/libraries/physics/src/CharacterController.cpp index 72d8220d4f..432b89ba31 100644 --- a/libraries/physics/src/CharacterController.cpp +++ b/libraries/physics/src/CharacterController.cpp @@ -194,9 +194,10 @@ void CharacterController::playerStep(btCollisionWorld* dynaWorld, btScalar dt) { // Rather then add this velocity to velocity the RigidBody, we explicitly teleport the RigidBody towards its goal. // This mirrors the computation done in MyAvatar::FollowHelper::postPhysicsUpdate(). // These two computations must be kept in sync. + const float MINIMUM_TIME_REMAINING = 0.005f; const float MAX_DISPLACEMENT = 0.5f * _radius; _followTimeRemaining -= dt; - if (_followTimeRemaining >= 0.005f) { + if (_followTimeRemaining >= MINIMUM_TIME_REMAINING) { btTransform bodyTransform = _rigidBody->getWorldTransform(); btVector3 startPos = bodyTransform.getOrigin(); @@ -210,9 +211,9 @@ void CharacterController::playerStep(btCollisionWorld* dynaWorld, btScalar dt) { glm::vec2 currentRight(currentFacing.y, -currentFacing.x); glm::vec2 desiredFacing = getFacingDir2D(bulletToGLM(_followDesiredBodyTransform.getRotation())); float deltaAngle = acosf(glm::clamp(glm::dot(currentFacing, desiredFacing), -1.0f, 1.0f)); - float angularVel = deltaAngle / _followTimeRemaining; + float angularSpeed = deltaAngle / _followTimeRemaining; float sign = copysignf(1.0f, glm::dot(desiredFacing, currentRight)); - btQuaternion angularDisplacement = btQuaternion(btVector3(0.0f, 1.0f, 0.0f), sign * angularVel * dt); + btQuaternion angularDisplacement = btQuaternion(btVector3(0.0f, 1.0f, 0.0f), sign * angularSpeed * dt); btQuaternion endRot = angularDisplacement * startRot; // in order to accumulate displacement of avatar position, we need to take _shapeLocalOffset into account. diff --git a/libraries/shared/src/GLMHelpers.cpp b/libraries/shared/src/GLMHelpers.cpp index 5adb9ca947..5073563afd 100644 --- a/libraries/shared/src/GLMHelpers.cpp +++ b/libraries/shared/src/GLMHelpers.cpp @@ -428,8 +428,9 @@ void generateBasisVectors(const glm::vec3& primaryAxis, const glm::vec3& seconda glm::vec2 getFacingDir2D(const glm::quat& rot) { glm::vec3 facing3D = rot * Vectors::UNIT_NEG_Z; glm::vec2 facing2D(facing3D.x, facing3D.z); - if (glm::length(facing2D) <= 0.0001f) { - return glm::vec2(1, 0); + const float ALMOST_ZERO = 0.0001f; + if (glm::length(facing2D) < ALMOST_ZERO) { + return glm::vec2(1.0f, 0.0f); } else { return glm::normalize(facing2D); } @@ -438,8 +439,9 @@ glm::vec2 getFacingDir2D(const glm::quat& rot) { glm::vec2 getFacingDir2D(const glm::mat4& m) { glm::vec3 facing3D = transformVector(m, Vectors::UNIT_NEG_Z); glm::vec2 facing2D(facing3D.x, facing3D.z); - if (glm::length(facing2D) <= 0.0001f) { - return glm::vec2(1, 0); + const float ALMOST_ZERO = 0.0001f; + if (glm::length(facing2D) < ALMOST_ZERO) { + return glm::vec2(1.0f, 0.0f); } else { return glm::normalize(facing2D); }