I read Thomas Jakobsen's article in Gamasutra (http://www.gamasutra.com/resource_guide ... n_01.shtml) but I don't think I can implement a Verlet integrator the way I have been handling movement in my engine. I use impulses to move the rigid bodies. So what I need is an example of how to implement constraints in this kind of system. Can anyone point me in the right direction?
I'm using a simple Euler integrator at the moment (thinking of writing a Runge-Kutta integrator soon):
Code: Select all
void BeEulerIntegrator::Integrate(BeRigidBody* Body, Float DeltaTime)
{
// Should we mess with this body?
if (!Body->IsDynamic() || Body->IsFlagSet(BeRigidBodyFlags::DISABLED) ||
Body->Mass() < MathUtil::BE_EPSILON || !Body->Scene())
return;
BeVector3 Force;
BeVector3 Torque;
// Linear dynamics
// ---------------
Force = Body->Force() + Body->ImpulseForce();
if (!Body->IsFlagSet(BeRigidBodyFlags::NO_GRAVITY))
Force += Body->Scene()->Gravity() * Body->Mass();
Body->AddLinearMomentum(Force * DeltaTime);
Body->Translate(Body->LinearVelocity() * DeltaTime);
// Angular dynamics
// ----------------
Torque = Body->Torque() + Body->ImpulseTorque();
Body->AddAngularMomentum(Torque * DeltaTime);
BeQuaternion kW = BeQuaternion(Body->AngularVelocity().x(),
Body->AngularVelocity().y(),
Body->AngularVelocity().z(),
0.0f);
BeQuaternion kA1DQDT = 0.5f * kW * Body->QOrientation();
Body->SetQOrientation(Body->QOrientation() + DeltaTime * kA1DQDT);
// Reset impulses
Body->SetImpulseForce(BeVector3::Zero);
Body->SetImpulseTorque(BeVector3::Zero);
}