Game Development Reference

In-Depth Information

Bodies[i].vVelocityBody.x = 0.0f;

Bodies[i].vVelocityBody.y = 0.0f;

Bodies[i].vVelocityBody.z = 0.0f;

// Set the initial orientation

iRoll = 0.0f;

iPitch = 0.0f;

iYaw = 0.0f;

Bodies[i].qOrientation = MakeQFromEulerAngles(iRoll, iPitch, iYaw);

// Set the mass properties

Bodies[i].fMass = BALLWEIGHT/(-g);

Ixx = 2.0f * Bodies[i].fMass / 5.0f * (BALLDIAMETER*BALLDIAMETER);

Izz = Iyy = Ixx;

Bodies[i].mInertia.e11 = Ixx;

Bodies[i].mInertia.e12 = 0;

Bodies[i].mInertia.e13 = 0;

Bodies[i].mInertia.e21 = 0;

Bodies[i].mInertia.e22 = Iyy;

Bodies[i].mInertia.e23 = 0;

Bodies[i].mInertia.e31 = 0;

Bodies[i].mInertia.e32 = 0;

Bodies[i].mInertia.e33 = Izz;

Bodies[i].mInertiaInverse = Bodies[i].mInertia.Inverse();

Bodies[i].fRadius = BALLDIAMETER/2;

}

}

Stepping the Simulation

During each time step, the simulation's main loop makes a call to
StepSimulation
. This

function, shown next, is almost identical to the
StepSimulation
functions we covered

in the other examples shown throughout this topic, so there really are no surprises here.

StepSimulation
first makes a call to
CalcObjectForces
, which we'll discuss momenā

tarily, and then proceeds to integrate the equations of motion for each ball. We use a

basic Euler scheme here for simplicity. After integrating,
StepSimulation
makes a few

function calls to deal with collisions. We'll cover those shortly.

void StepSimulation(float dtime)

{

Vector Ae;

int i;

float dt = dtime;

int check = NOCOLLISION;

int c = 0;

// Calculate all of the forces and moments on the balls:

CalcObjectForces();