mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
Merge pull request #13138 from AndrewMeadows/avoid-div-by-zero
avoid div by zero when measuring RigidBody effective acceleration
This commit is contained in:
commit
c57b0a957d
1 changed files with 3 additions and 1 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue