Game Development Reference
// store the furthest intersection point from castRay()
//castRay() returns true if ray intersects mesh
if ( collisionMesh.castRay(ray,intersectPoint) )
//Check if this is the furthest
//collision point yet found
vertexToIntersect = vertex.pos − intersectPoint.pos;
if ( vertexToIntersect.length()
furthestDist = vertexToIntersect.length();
furthestPoint = intersectPoint;
//Move the vertex to the further point of intersection
vertex.pos = furthestPoint;
Listing 13.2. The Deform() function for a ray-cast collision response (in pseudocode).
Each vertex is compared against each collision object and then pushed along its normal to
contain or “envelop” the collision object.
Figure 13.2. Skin with nicely contained collision geometry (bone). Arrows represent
vertex normals (top left). The collision bone has moved. Ray casting for each vertex
has found their new positions “outside” the bone. New vertex normals are also computed
(top right). The displacement vectors for the vertices that were “pushed” by the collision
geometry (bottom) (see Color Plate X).