History

prevent nan inside spring action

Andrew Meadows committed 10 years ago

Commit b9352d31 parent a8d13cb2 files · +7 −8Browse files

Showing the changes to libraries/physics/src/ObjectActionSpring.cpp (1 of 2 files). Show all

Unified · Split

libraries/physics/src/ObjectActionSpring.cpp+7−7
@@ -58,16 +58,16 @@ void ObjectActionSpring::updateActionWorker(btScalar deltaTimeStep) { · 57 unmodified lines
58 58
59 const float MAX_TIMESCALE = 600.0f; // 10 min is a long time59 const float MAX_TIMESCALE = 600.0f; // 10 min is a long time
60 if (_linearTimeScale < MAX_TIMESCALE) {60 if (_linearTimeScale < MAX_TIMESCALE) {
61 btVector3 targetVelocity(0.0f, 0.0f, 0.0f);
61 btVector3 offset = rigidBody->getCenterOfMassPosition() - glmToBullet(_positionalTarget);62 btVector3 offset = rigidBody->getCenterOfMassPosition() - glmToBullet(_positionalTarget);
62 float offsetLength = offset.length();63 float offsetLength = offset.length();
63 btVector3 targetVelocity(0.0f, 0.0f, 0.0f);64 if (offsetLength > FLT_EPSILON) {
64 65 float speed = glm::min(offsetLength / _linearTimeScale, SPRING_MAX_SPEED);
65 float speed = (offsetLength > FLT_EPSILON) ? glm::min(offsetLength / _linearTimeScale, SPRING_MAX_SPEED) : 0.0f;66 targetVelocity = (-speed / offsetLength) * offset;
66 targetVelocity = (-speed / offsetLength) * offset;67 if (speed > rigidBody->getLinearSleepingThreshold()) {
67 if (speed > rigidBody->getLinearSleepingThreshold()) {68 rigidBody->activate();
68 rigidBody->activate();69 }
69 }70 }
70
71 // this action is aggresively critically damped and defeats the current velocity71 // this action is aggresively critically damped and defeats the current velocity
72 rigidBody->setLinearVelocity(targetVelocity);72 rigidBody->setLinearVelocity(targetVelocity);
73 }73 }