Merge pull request #13138 from AndrewMeadows/avoid-div-by-zero

avoid div by zero when measuring RigidBody effective acceleration
This commit is contained in:
John Conklin II 2018-05-14 13:41:08 -07:00 committed by GitHub
commit c57b0a957d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -731,7 +731,9 @@ void EntityMotionState::measureBodyAcceleration() {
// hence the equation for acceleration is: a = (v1 / (1 - D)^dt - v0) / dt
glm::vec3 velocity = getBodyLinearVelocityGTSigma();
_measuredAcceleration = (velocity / powf(1.0f - _body->getLinearDamping(), dt) - _lastVelocity) * invDt;
const float MIN_DAMPING_FACTOR = 0.01f;
float invDampingAttenuationFactor = 1.0f / glm::max(powf(1.0f - _body->getLinearDamping(), dt), MIN_DAMPING_FACTOR);
_measuredAcceleration = (velocity * invDampingAttenuationFactor - _lastVelocity) * invDt;
_lastVelocity = velocity;
if (numSubsteps > PHYSICS_ENGINE_MAX_NUM_SUBSTEPS) {
// we fall in here when _lastMeasureStep is old: the body has just become active