Game Development Reference

In-Depth Information

// Apply impulse:

Bodies[b1].vVelocity +=

(j * Collisions[i].vCollisionNormal) /

Bodies[b1].fMass;

Bodies[b1].vAngularVelocityGlobal +=

(pt1 ^ (j * Collisions[i].vCollisionNormal)) *

Bodies[b1].mIeInverse;

Bodies[b1].vAngularVelocity =

QVRotate(~Bodies[b1].qOrientation,

Bodies[b1].vAngularVelocityGlobal);

}

}

}

}

}

The final function we need to show you is
CheckGroundPlaneContacts
. Recall that this

function is called from
CalcObjectForces
in order to determine if a ball is in resting

contact with the table. If the ball's vertical position is less than or equal to its radius plus

some small tolerance, and if the ball's vertical velocity is 0 (or nearly so within some

small tolerance), then we consider the ball in contact with the table. If there's a contact,

the relevant data gets stored in the
Collisions
array and used to resolve the contact,

not the collision, in
CalcObjectForces
:

int CheckGroundPlaneContacts(pCollision CollisionData, int body1)

{

Vector v1[8];

Vector tmp;

Vector u, v;

Vector f[4];

Vector vel1;

Vector pt1;

Vector Vr;

float Vrn;

Vector n;

int status = NOCOLLISION;

Vector Ar;

float Arn;

if(Bodies[body1].vPosition.z <= (Bodies[body1].fRadius + COLLISIONTOLERANCE))

{

pt1 = Bodies[body1].vPosition;

pt1.z = COLLISIONTOLERANCE;

tmp = pt1;

pt1 = pt1-Bodies[body1].vPosition;

vel1 = Bodies[body1].vVelocity/*Body*/ +

(Bodies[body1].vAngularVelocityGlobal^pt1);

n.x = 0;

n.y = 0;