Game Development Reference
In-Depth Information
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;
n.z = 1;
Vr = vel1;
Vrn = Vr * n;
if(Vrn < -VELOCITYTOLERANCE)
{
// Have a collision so fill the data structure
assert(NumCollisions < (NUMBODIES*8));
if(NumCollisions < (NUMBODIES*8))
{
CollisionData->body1 = body1;
CollisionData->body2 = −1;
CollisionData->vCollisionNormal = n;
CollisionData->vCollisionPoint = tmp;
CollisionData->vRelativeVelocity = Vr;
CollisionData->vCollisionTangent = (n^Vr)^n;
CollisionData->vCollisionTangent.Reverse();
CollisionData->vCollisionTangent.Normalize();
status = COLLISION;
}
}
}
return status;
}
Resolving collisions, whether ball-ball or ball-table collisions, uses the same approach
we've already shown you. Thus, we won't go over the code again, and will instead just
show you the function that implements collision response:
void ResolveCollisions(void)
{
int i;
double j;
Vector pt1, pt2, vB1V, vB2V, vB1AV, vB2AV;
float fCr = COEFFICIENTOFRESTITUTION;
int b1, b2;
float Vrt;
float muB = FRICTIONCOEFFICIENTBALLS;
float muG = FRICTIONCOEFFICIENTGROUND;
bool dofriction = DOFRICTION;
Search Nedrilad ::




Custom Search