Game Development Reference
In-Depth Information
vRelativeVelocity = v1 - v2;
Vrn = vRelativeVelocity * vCollisionNormal;
if( ArePointsEqual(vList1[i],
vList2[j]) &&
(Vrn < 0.0) )
haveNodeNode = true;
This comparison makes a call to another new function, ArePointsEqual :
if( ArePointsEqual(vList1[i],
vList2[j]) &&
(Vrn < 0.0) )
haveNodeNode = true;
ArePointsEqual simply checks to see if the points are within a specified distance from
each other, as shown here:
bool ArePointsEqual(Vector p1, Vector p2)
// Points are equal if each component is within ctol of each other
if( (fabs(p1.x - p2.x) <= ctol) &&
(fabs(p1.y - p2.y) <= ctol) &&
(fabs(p1.z - p2.z) <= ctol) )
return true;
return false;
Within the nested for loops of the vertex-vertex check, we perform a number of im‐
portant calculations to determine the collision normal vector and relative velocity that
are required for collision response.
First, we calculate the collision point, which is simply the coordinates of a vertex that is
involved in the collision. Note that this point will be in global coordinates, so it will have
to be converted to local coordinates for each hovercraft in order to be useful for collision
response. Here's how that's done:
vCollisionPoint = vList1[i];
body1->vCollisionPoint = vCollisionPoint −
body2->vCollisionPoint = vCollisionPoint −
The second calculation is aimed at determining the collision normal vector, which for
vertex-vertex collisions we've assumed is along the line connecting the centers of gravity
Search Nedrilad ::

Custom Search