Game Development Reference
In-Depth Information
p = vList1[i] - vList2[j];
proj = (p * u) * u;
d = p^u;
dist = d.Magnitude();
Variable p is a vector from the first vertex on the edge to the vertex under consideration,
and proj is the distance from the first edge vertex, along the edge, to the point upon
which the vertex projects. dist is the minimum distance from the vertex to the edge.
Figure 10-3 illustrates this geometry.
Figure 10-3. Vertex-edge check
If there is a collision, the global location of the point of impact is equal to the vertex
under consideration, which we must convert to local coordinates for each hovercraft,
as shown here:
vCollisionPoint = vList1[i];
body1->vCollisionPoint = vCollisionPoint −
body1->vPosition;
body2->vCollisionPoint = vCollisionPoint −
body2->vPosition;
Since, in this type of collision, the collision normal vector is perpendicular to the edge,
you can determine it by taking the result of the cross product of u and p and crossing it
with u as follows:
vCollisionNormal = ((u^p)^u);
vCollisionNormal.Normalize();
These calculations give you a unit length vector in the plane of vectors u and p and
perpendicular to the edge.
Next, the relative velocity between the points of impact on each hovercraft is determined,
just as in the vertex-vertex collision check:
v1 = body1->vVelocityBody +
(body1->vAngularVelocity ^
body1->vCollisionPoint);