Game Development Reference
In-Depth Information
Another case that you have to consider is when the two bounding spheres overlap but are headed
away from each other. When the objects are moving away from each other, the dot product between
the collision normal and the relative velocity is greater or equal to 0. This case is not considered a
collision, because the objects are heading away from each other (see Figure 5-20 ). We will get into
more detail into these cases later in this section.
CollisionDistance < -m_CollisionTolerance
m_CollisionNormal
m_RelativeVelocity
RelativeVelocityNormal > 0.0
PENETRATING
Figure 5-20. Penetrating
Modifying the Physics Class
The Physics class holds the main implementation for collision detection. We have to add some
variables and a function to this class.
We added an enumeration called CollisionStatus that holds the outcome of our collision detection
testing. The values are the following:
COLLISION : A collision has occurred.
NOCOLLISION : The bodies tested are not touching at all.
PENETRATING : The bodies tested are penetrating each other but are moving away
from each other and thus not colliding.
PENETRATING_COLLISION : The bodies tested are penetrating each other and are
moving toward each other and, thus, are colliding.
enum CollisionStatus
{
COLLISION,
NOCOLLISION,
PENETRATING,
PENETRATING_COLLISION
}
Next, we add in variables for the collision tolerance. If the collision distance is within the range
-COLLISIONTOLERANCE to COLLISIONTOLERANCE , the two bodies would be considered to be colliding
with each other, and the value COLLISION is returned.
 
Search WWH ::




Custom Search