Game Development Reference
In-Depth Information
deformation. Needless to say, this geometry is purely for collision purposes and
should not be rendered.
13.4.3 Ray-Casting Collisions
Given a well-constructed anatomical model and a mesh wrapping over it with
smooth skinning, how do we ensure the vertices collide properly? As is usually
the case, these things can be simplified if we make some assumptions. The core
assumption here is that vertices only need to adjust to collisions by moving along
their normal (i.e., being pushed inwards or outwards). This is a fair assumption if
you recall that we are looking for a bug-under-the-rug effect where the bug only
pushes the carpet up/down and does not pull it tangentially to the surface normal.
With this in mind, calculating the offset is a matter of finding the furthest point
along the vertex normal that touches a collision surface . If there are multiple
surfaces, we must be careful to choose the point that is furthest away.
I must stress here that this is not a way of doing general physical soft-body
collisions. Ray-casting collision response will not prevent the skin mesh from
self-intersecting. What it does do is help prevent a loss of volume by keeping the
surface of the skin outside the collision geometry.
To do this, create a ray with an origin at the vertex and direction equal to the
vertex normal. Cast this ray at the collision geometry and record the point furthest
along the ray that intersects with the collision geometry. Now move the vertex to
this furthest point of intersection (see Figure 13.2 ) . This is best demonstrated with
pseudocode, as shown in Listing 13.2.
class PolyMesh; //your engine's mesh class
PolyMesh mesh; //this particular mesh
...
for (eachVertex)
{ //Create a ray from this vertex
3dRay ray;
ray.pos = vertex.pos;
ray.direction = vertex.normal;
//Furthest point
3dPoint furthestPoint=vertex.pos;
float furthestDist = 0.0;
for (eachCollisionMesh)
{ if ( vertex not attached to this collision mesh )
return ;