From 17455486656662cdfa1a00758843aec018f5328d Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Wed, 7 Jan 2015 12:42:50 -0800 Subject: [PATCH] fix rapid attenuation of angular velocity --- libraries/entities/src/EntityItem.cpp | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index d0a22abd83..87d827c1f2 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -647,27 +647,30 @@ void EntityItem::simulate(const quint64& now) { glm::quat rotation = getRotation(); // angular damping - glm::vec3 angularVelocity = glm::radians(getAngularVelocity()); + glm::vec3 angularVelocity = getAngularVelocity(); if (_angularDamping > 0.0f) { angularVelocity *= powf(1.0f - _angularDamping, timeElapsed); if (wantDebug) { qDebug() << " angularDamping :" << _angularDamping; qDebug() << " newAngularVelocity:" << angularVelocity; } + setAngularVelocity(angularVelocity); } - float angularSpeed = glm::length(angularVelocity); + float angularSpeed = glm::length(_angularVelocity); - const float EPSILON_ANGULAR_VELOCITY_LENGTH = 0.0017453f; // ~0.1 degree/sec + const float EPSILON_ANGULAR_VELOCITY_LENGTH = 0.1; // if (angularSpeed < EPSILON_ANGULAR_VELOCITY_LENGTH) { - angularVelocity = NO_ANGULAR_VELOCITY; + setAngularVelocity(NO_ANGULAR_VELOCITY); } else { - float angle = timeElapsed * angularSpeed; - glm::quat dQ = glm::angleAxis(angle, glm::normalize(angularVelocity)); + // NOTE: angularSpeed is currently in degrees/sec!!! + // TODO: Andrew to convert to radians/sec + float angle = timeElapsed * glm::radians(angularSpeed); + glm::vec3 axis = _angularVelocity / angularSpeed; + glm::quat dQ = glm::angleAxis(angle, axis); rotation = glm::normalize(dQ * rotation); setRotation(rotation); } - setAngularVelocity(angularVelocity); } #ifdef USE_BULLET_PHYSICS