Showing the changes to libraries/physics/src/ObjectActionSpring.cpp (1 of 2 files). Show all
Unified · Split
| @@ -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 time | 59 | 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 velocity | 71 | // this action is aggresively critically damped and defeats the current velocity |
| 72 | rigidBody->setLinearVelocity(targetVelocity); | 72 | rigidBody->setLinearVelocity(targetVelocity); |
| 73 | } | 73 | } |