activate sprung objects when action strong enough

This commit is contained in:
Andrew Meadows 2016-01-12 12:53:35 -08:00
parent 2288d96868
commit 6a5a74700f

View file

@ -62,9 +62,10 @@ void ObjectActionSpring::updateActionWorker(btScalar deltaTimeStep) {
float offsetLength = offset.length(); float offsetLength = offset.length();
btVector3 targetVelocity(0.0f, 0.0f, 0.0f); btVector3 targetVelocity(0.0f, 0.0f, 0.0f);
if (offsetLength > 0) { float speed = (offsetLength > FLT_EPSILON) ? glm::min(offsetLength / _linearTimeScale, SPRING_MAX_SPEED) : 0.0f;
float speed = (offsetLength > FLT_EPSILON) ? glm::min(offsetLength / _linearTimeScale, SPRING_MAX_SPEED) : 0.0f; if (speed > rigidBody->getLinearSleepingThreshold()) {
targetVelocity = (-speed / offsetLength) * offset; targetVelocity = (-speed / offsetLength) * offset;
rigidBody->activate();
} }
// this action is aggresively critically damped and defeats the current velocity // this action is aggresively critically damped and defeats the current velocity
@ -90,10 +91,10 @@ void ObjectActionSpring::updateActionWorker(btScalar deltaTimeStep) {
// //
// dQ = Q1 * Q0^ // dQ = Q1 * Q0^
btQuaternion deltaQ = target * bodyRotation.inverse(); btQuaternion deltaQ = target * bodyRotation.inverse();
float angle = deltaQ.getAngle(); float speed = deltaQ.getAngle() / _angularTimeScale;
const float MIN_ANGLE = 1.0e-4f; if (speed > rigidBody->getAngularSleepingThreshold()) {
if (angle > MIN_ANGLE) { targetVelocity = speed * deltaQ.getAxis();
targetVelocity = (angle / _angularTimeScale) * deltaQ.getAxis(); rigidBody->activate();
} }
} }
// this action is aggresively critically damped and defeats the current velocity // this action is aggresively critically damped and defeats the current velocity