627
may end up touching more than one part of the poly soup simultaneously. We
can safely say that no matt er what kind of convex shape is cast, it is possible
(albeit unlikely) for the cast to generate multiple contact points. The contacts
will always be on the surface of the cast shape in this case, never inside it (be-
cause we know that the cast shape was not interpenetrating anything when it
started its journey). This case is illustrated in Figure 12.20.
As with ray casts, some shape casting APIs report only the earliest contact (s)
experienced by the cast shape, while others allow the shape to continue along
its hypothetical path, returning all the contacts it experiences on its journey.
This is illustrated in Figure 12.21.
The contact information returned by a shape cast is necessarily a bit more
complex than it is for a ray cast. We cannot simply return one or more t val-
ues, because a t value only describes the location of the center point of the
shape along its path. It tells us nothing of where, on the surface or interior of
the shape, it came into contact with the impacted collidable. As a result, most
shape casting APIs return both a t value and the actual contact point, along
with other relevant information (such as which collidable was struck, the sur-
face normal at the contact point, etc.).
Unlike ray casting APIs, a shape casting system must always be capable of
reporting multiple contacts. This is because even if we only report the contact
with the earliest t value, the shape may have touched multiple distinct collid-
ables in the game world, or it may be touching a single non-convex collidable
at more than one point. As a result, collision systems usually return an array
or list of contact point data structures, each of which might look something
like this:
struct ShapeCastContact
{
F32 m_t; // the t value for this
// contact
U32 m_collidableId; // which collidable did we
// hit?
Contact 1
d
Contact 3 Contact 2
Figure 12.21. A shape casting API might return all contacts instead of only the earliest con-
tact.
12.3. The Collision Detection System