Game Development Reference
F IGURE 13.10
Contacts between a box and a plane.
For one vertex at p the code to generate a contact looks like this:
Excerpt from src/collide_fine.cpp
// Calculate the distance from the plane.
real vertexDistance = vertexPos * plane.direction;
// Compare this to the plane's distance.
if (vertexDistance <= plane.offset + data->tolerance)
// Create the contact data.
// The contact point is halfway between the vertex and the
// plane - we multiply the direction by half the separation
// distance and add the vertex location.
contact->contactPoint = plane.direction;
contact->contactPoint *= (vertexDistance-plane.offset);
contact->contactPoint = vertexPos;
contact->contactNormal = plane.direction;
contact->penetration = plane.offset - vertexDistance;
The full algorithm runs this code for each vertex of the box. We can generate the set
of vertices from a box data structure that looks like this: