Game Development Reference
In-Depth Information
// ... Other RigidBody code as before ...
* Holds the amount of damping applied to angular
* motion. Damping is required to remove energy added
* through numerical instability in the integrator.
real angularDamping;
Just as we saw with linear velocity, the angular velocity is updated with the equa-
θ = θ(d a ) t
+ θ t
where d a is the angular damping coefficient. The complete integration routine now
looks like this:
Excerpt from src/body.cpp
void RigidBody::integrate(real duration)
// Calculate linear acceleration from force inputs.
lastFrameAcceleration = acceleration;
lastFrameAcceleration.addScaledVector(forceAccum, inverseMass);
// Calculate angular acceleration from torque inputs.
Vector3 angularAcceleration =
// Adjust velocities
// Update linear velocity from both acceleration and impulse.
velocity.addScaledVector(lastFrameAcceleration, duration);
// Update angular velocity from both acceleration and impulse.
rotation.addScaledVector(angularAcceleration, duration);
// Impose drag.
velocity *= real_pow(linearDamping, duration);
rotation *= real_pow(angularDamping, duration);
// Adjust positions
// Update linear position.
position.addScaledVector(velocity, duration);
// Update angular position.
Search Nedrilad ::

Custom Search