Game Development Reference
In-Depth Information
of each hovercraft. The calculation is the same as that shown in the earlier version of
CheckForCollision :
vCollisionNormal = body1->vPosition −
body2->vPosition;
vCollisionNormal.Normalize();
The third and final calculation is aimed at determining the relative velocity between the
points of impact. This is an important distinction from the earlier version, since the
velocities of the points of impact on each body are functions of the linear and angular
velocities of the hovercraft:
v1 = body1->vVelocityBody +
(body1->vAngularVelocity^body1->vCollisionPoint);
v2 = body2->vVelocityBody +
(body2->vAngularVelocity^body2->vCollisionPoint);
v1 = VRotate2D(body1->fOrientation, v1);
v2 = VRotate2D(body2->fOrientation, v2);
vRelativeVelocity = v1 - v2;
Vrn = vRelativeVelocity * vCollisionNormal;
Here, v1 and v2 represent the velocities of the points of collision relative to each hov‐
ercraft in local coordinates, which are then converted to global coordinates. Once we've
obtained the relative velocity, vRelativeVelocity , we obtain the relative normal ve‐
locity, Vrn , by taking the dot product of the relative velocity with the collision normal
vector.
If there is no vertex-vertex collision, CheckForCollision proceeds to check for vertex-
edge collisions:
// Check for vertex-edge collision
if(!haveNodeNode)
{
for(i=0; i<4 && !haveNodeEdge; i++)
{
for(j=0; j<3 && !haveNodeEdge; j++)
{
if(j==3)
edge = vList2[0] - vList2[j];
else
edge = vList2[j+1] - vList2[j];
u = edge;
u.Normalize();
p = vList1[i] - vList2[j];
proj = (p * u) * u;
d = p^u;
Search Nedrilad ::




Custom Search