Game Development Reference
In-Depth Information
if(s < COLLISIONTOLERANCE)
{// possible collision
Vector pt1, pt2, vel1, vel2, n, Vr;
float Vrn;
pt1 = (Bodies[i].vPosition + Bodies[j].vPosition)/2;
tmp = pt2 = pt1;
pt1 = pt1-Bodies[i].vPosition;
pt2 = pt2-Bodies[j].vPosition;
vel1 = Bodies[i].vVelocity +
(Bodies[i].vAngularVelocityGlobal^pt1);
vel2 = Bodies[j].vVelocity +
(Bodies[j].vAngularVelocityGlobal^pt2);
n = d;
n.Normalize();
Vr = (vel1 - vel2);
Vrn = Vr * n;
if(Vrn < -VELOCITYTOLERANCE)
{
// Have a collision so fill the data structure
assert(NumCollisions < (NUMBODIES*8));
if(NumCollisions < (NUMBODIES*8))
{
pCollisionData->body1 = i;
pCollisionData->body2 = j;
pCollisionData->vCollisionNormal = n;
pCollisionData->vCollisionPoint = tmp;
pCollisionData->vRelativeVelocity = Vr;
pCollisionData->vCollisionTangent = (n^Vr)^n;
pCollisionData->vCollisionTangent.Normalize();
pCollisionData++;
NumCollisions++;
status = COLLISION;
} }
}
}
}
for(i=0; i<NUMBODIES; i++)
{
check = NOCOLLISION;
assert(NumCollisions < (NUMBODIES*8));
check = CheckGroundPlaneCollisions(pCollisionData, i);
if(check == COLLISION)
{
Search Nedrilad ::




Custom Search