Fix issue with linear/angular damping

This commit is contained in:
Daniel Chappuis 2016-03-20 22:53:05 +01:00
parent b15d46a95f
commit 63fb6261a3
2 changed files with 8 additions and 10 deletions

View File

@ -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
*/

View File

@ -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++;
}