From 7d13f9220c7100aad33b32b1da1e20a9505f06ef Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 30 Aug 2016 09:55:42 -0700 Subject: [PATCH] fix math, renamed a couple variables --- .../physics/src/ObjectActionTravelOriented.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/libraries/physics/src/ObjectActionTravelOriented.cpp b/libraries/physics/src/ObjectActionTravelOriented.cpp index 7cf1e6da84..18d09d21d9 100644 --- a/libraries/physics/src/ObjectActionTravelOriented.cpp +++ b/libraries/physics/src/ObjectActionTravelOriented.cpp @@ -58,17 +58,18 @@ void ObjectActionTravelOriented::updateActionWorker(btScalar deltaTimeStep) { if (speed < TRAVEL_ORIENTED_TOO_SLOW) { return; } - velocity = glm::normalize(velocity); + glm::vec3 direction = glm::normalize(velocity); // find current angle of "forward" btQuaternion bodyRotation = rigidBody->getOrientation(); glm::quat orientation = bulletToGLM(bodyRotation); glm::vec3 forwardInWorldFrame = glm::normalize(orientation * _forward); - // find the rotation that would line up velocity and forward - glm::quat neededRotation = ::rotationBetween(forwardInWorldFrame, velocity); - glm::quat rotationalTarget = orientation * neededRotation; - btVector3 targetVelocity(0.0f, 0.0f, 0.0f); + // find the rotation that would line up direction and forward + glm::quat neededRotation = glm::rotation(forwardInWorldFrame, direction); + glm::quat rotationalTarget = neededRotation * orientation; + + btVector3 targetAngularVelocity(0.0f, 0.0f, 0.0f); auto alignmentDot = bodyRotation.dot(glmToBullet(rotationalTarget)); const float ALMOST_ONE = 0.99999f; @@ -86,13 +87,13 @@ void ObjectActionTravelOriented::updateActionWorker(btScalar deltaTimeStep) { // dQ = Q1 * Q0^ btQuaternion deltaQ = target * bodyRotation.inverse(); float speed = deltaQ.getAngle() / _angularTimeScale; - targetVelocity = speed * deltaQ.getAxis(); + targetAngularVelocity = speed * deltaQ.getAxis(); if (speed > rigidBody->getAngularSleepingThreshold()) { rigidBody->activate(); } } // this action is aggresively critically damped and defeats the current velocity - rigidBody->setAngularVelocity(targetVelocity); + rigidBody->setAngularVelocity(targetAngularVelocity); }); }