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
5858
5959 const float MAX_TIMESCALE = 600.0f; // 10 min is a long time
6060 if (_linearTimeScale < MAX_TIMESCALE) {
61+ btVector3 targetVelocity(0.0f, 0.0f, 0.0f);
6162 btVector3 offset = rigidBody->getCenterOfMassPosition() - glmToBullet(_positionalTarget);
6263 float offsetLength = offset.length();
63− btVector3 targetVelocity(0.0f, 0.0f, 0.0f);
64−
65− float speed = (offsetLength > FLT_EPSILON) ? glm::min(offsetLength / _linearTimeScale, SPRING_MAX_SPEED) : 0.0f;
66− targetVelocity = (-speed / offsetLength) * offset;
67− if (speed > rigidBody->getLinearSleepingThreshold()) {
68− rigidBody->activate();
64+ if (offsetLength > FLT_EPSILON) {
65+ float speed = glm::min(offsetLength / _linearTimeScale, SPRING_MAX_SPEED);
66+ targetVelocity = (-speed / offsetLength) * offset;
67+ if (speed > rigidBody->getLinearSleepingThreshold()) {
68+ rigidBody->activate();
69+ }
6970 }
70−
7171 // this action is aggresively critically damped and defeats the current velocity
7272 rigidBody->setLinearVelocity(targetVelocity);
7373 }