Game Development Reference
In-Depth Information
Center of Mass Body 1
CollisionDistance
Center of Mass Body 2
Figure 5-22. The collision distance
The CollisionNormal is calculated by normalizing the distance vector between the two centers
of mass calculated in the previous step. The relative velocity between the two objects is also
calculated. By taking the dot product between the relative velocity vector and the collision normal
vector, the magnitude of the relative velocity along the collision normal is found. (See Figure 5-23 .)
Body 1
m_RelativeVelocity
m_CollisionNormal
(Unit Vector of Length 1)
Body 2
RelativeVelocityNormal
Figure 5-23. Calculating the collision direction
Now that you know the collision distance and the relative velocity along the collision normal, you
have the all the information you need to find out if the objects are colliding. You know if they are
touching each other, based on the collision distance, and if they are moving toward each other,
based on the relative velocity of the objects along the collision normal. See Listing 5-18 to see the
actual code.
Listing 5-18. Collision Detection Function
CollisionStatus CheckForCollisionSphereBounding(Object3d body1, Object3d body2)
{
Float ImpactRadiusSum = 0;
float RelativeVelocityNormal = 0;
float CollisionDistance = 0;
Vector3 Body1Velocity;
Vector3 Body2Velocity;
CollisionStatus retval;
 
Search WWH ::




Custom Search