From 63fb6261a37b048419b0a455cb133e9554f2e1be Mon Sep 17 00:00:00 2001 From: Daniel Chappuis Date: Sun, 20 Mar 2016 22:53:05 +0100 Subject: [PATCH] Fix issue with linear/angular damping --- src/body/RigidBody.h | 6 ++++-- src/engine/DynamicsWorld.cpp | 12 ++++-------- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/body/RigidBody.h b/src/body/RigidBody.h index 63bede26..e523861b 100644 --- a/src/body/RigidBody.h +++ b/src/body/RigidBody.h @@ -339,7 +339,8 @@ inline decimal RigidBody::getLinearDamping() const { return mLinearDamping; } -// Set the linear damping factor +// Set the linear damping factor. This is the ratio of the linear velocity +// that the body will lose every at seconds of simulation. /** * @param linearDamping The linear damping factor of this body */ @@ -356,7 +357,8 @@ inline decimal RigidBody::getAngularDamping() const { return mAngularDamping; } -// Set the angular damping factor +// Set the angular damping factor. This is the ratio of the angular velocity +// that the body will lose at every seconds of simulation. /** * @param angularDamping The angular damping factor of this body */ diff --git a/src/engine/DynamicsWorld.cpp b/src/engine/DynamicsWorld.cpp index 76f95dd9..53902293 100644 --- a/src/engine/DynamicsWorld.cpp +++ b/src/engine/DynamicsWorld.cpp @@ -338,14 +338,10 @@ void DynamicsWorld::integrateRigidBodiesVelocities() { // => v2 = v1 * (1 - c * dt) decimal linDampingFactor = bodies[b]->getLinearDamping(); decimal angDampingFactor = bodies[b]->getAngularDamping(); - decimal linearDamping = clamp(decimal(1.0) - mTimeStep * linDampingFactor, - decimal(0.0), decimal(1.0)); - decimal angularDamping = clamp(decimal(1.0) - mTimeStep * angDampingFactor, - decimal(0.0), decimal(1.0)); - mConstrainedLinearVelocities[indexBody] *= clamp(linearDamping, decimal(0.0), - decimal(1.0)); - mConstrainedAngularVelocities[indexBody] *= clamp(angularDamping, decimal(0.0), - decimal(1.0)); + decimal linearDamping = pow(decimal(1.0) - linDampingFactor, mTimeStep); + decimal angularDamping = pow(decimal(1.0) - angDampingFactor, mTimeStep); + mConstrainedLinearVelocities[indexBody] *= linearDamping; + mConstrainedAngularVelocities[indexBody] *= angularDamping; indexBody++; }