Game Development Reference
In-Depth Information
private float COLLISIONTOLERANCE = 0.1f;
private float m_CollisionTolerance = COLLISIONTOLERANCE;
The m_CollisionNormal vector is the vector from the center of mass of one object to the center of
mass of the other object.
private Vector3 m_CollisionNormal;
The m_RelativeVelocity vector is a vector that represents the relative velocity of one object to the
other object that is being tested for collision.
private Vector3 m_RelativeVelocity;
The CheckForCollisionSphereBounding() is the function that actually does the collision detection for
two 3D objects. It accepts two objects as input and returns a value of the type CollisionStatus. The
following steps are performed by the function in order to determine the collision status.
1.
Calculate the collision distance between the two objects.
2.
Calculate the collision normal between the two objects.
3.
Calculate the relative velocity of the two objects along the collision normal.
4.
Determine the collision status based on the collision distance and the relative
velocity along the collision normal.
The ImpactRadiusSum variable is the sum of the radius of object1 and radius of object2. If the
collision were exactly at the boundary of the collision spheres, then the CollisionDistance between
the two objects would be zero, and the distance between the center of the masses of the objects
would be just ImpactRadiusSum , as seen in Figure 5-21 .
Center of Mass Body 1
ImpactRadiusSum
Center of Mass Body 2
Figure 5-21. The perfect collision
The CollisionDistance measures the distance between the boundaries of the collision spheres of
the two objects. It is calculated by subtracting the ImpactRadiusSum from the distance between the
objects' center of mass. (See Figure 5-22 .)
 
Search WWH ::




Custom Search