628 12. Collision and Rigid Body Dynamics
Point m_contactPoint; // location of actual
// contact
Vector m_normal; // surface normal at
// contact pt.
// other information...
};
Given a list of contact points, we oft en want to distinguish between the
groups of contact points for each distinct t value. For example, the earliest
contact is actually described by the group of contact points that all share the
minimum t in the list. It’s important to realize that collision systems may or
may not return their contact points sorted by t. If it does not, it’s almost always
a good idea to sort the results by t manually. This ensures that if one looks at
the fi rst contact point in the list, it will be guaranteed to be among the earliest
contact points along the shape’s path.
Applications of Shape Casts
Shape casts are extremely useful in games. Sphere casts can be used to de-
termine whether the virtual camera is in collision with objects in the game
world. Sphere or capsule casts are also commonly used to implement charac-
ter movement. For example, in order to slide the character forward on uneven
terrain, we can cast a sphere or capsule that lies between the character’s feet
in the direction of motion. We can adjust it up or down via a second cast, to
ensure that it remains in contact with the ground. If the sphere hits a very
short vertical obstruction, such as a street curb, it can “pop up” over the curb.
If the vertical obstruction is too tall, like a wall, the cast sphere can be slid
horizontally along the wall. The fi nal resting place of the cast sphere becomes
the character’s new location next frame.
12.3.7.3. Phantoms
Sometimes, games need to determine which collidable objects lie within
some specifi c volume in the game world. For example, we might want the
list of all enemies that are within a certain radius of the player character.
Havok supports a special kind of collidable object known as a phantom for
this purpose.
A phantom acts much like a shape cast whose distance vector d is zero.
At any moment, we can ask the phantom for a list of its contacts with other
collidables in the world. It returns this data in essentially the same format that
would be returned by a zero-distance shape cast.
However, unlike a shape cast, a phantom is persistent in the collision
world. This means that it can take full advantage of the temporal coherency
optimizations used by the collision engine when detecting collisions between