A Simple Constraints System

gfaraj
Posts: 3
Joined: Wed Mar 08, 2006 2:42 am

A Simple Constraints System

Post by gfaraj »

Hello, I am trying to make a simple yet powerful-enough constraints system for a game physics engine. I already have simple collision detection and response using rigid bodies. I have looked for examples or tutorials on how to implement constraints, but have not found much.

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);
        } 
User avatar
John McCutchan
Posts: 133
Joined: Wed Jul 27, 2005 1:05 pm
Location: Berkeley, CA

Post by John McCutchan »

read kenny's thesis. You can find it in the forums.