Game Development Reference
In-Depth Information
Collision Detection
The type of collision detection we will use in this topic is based on a sphere where the entire 3D
object fits within the boundaries of a collision sphere. The two objects involved in a collision have
initial velocities of V1Initial and V2Initial and final velocities after the collision of V1Final and V2Final.
The center of mass of Body1 and Body2 are both assumed to be at the center of the bounding or
collision sphere. The collision normal is a vector that passes through the center of masses of both
objects and is key in determining the final collision velocities and direction of the objects. The forces
acting on the objects when they collide will act along the collision normal and will be equal and
opposite in direction, according to Newton's third law of motion. (See Figure 5-17 .)
Center of Mass
Body 1
V1 Final
V2 Final
Body 1
Collision Normal
Body 2
V1 Initial
Center of Mass
Body 2
V2
Initial
Figure 5-17. Collision between two 3D objects represented by bounding spheres
Modifying the MeshEx Class
First, we must be able to calculate the radius of the collision sphere for a 3D object. In order to do
this, we have to add some code to our MeshEx class.
The following variables have been added. The m_Size variable measures the largest size of the 3D
object mesh in the x, y, and z directions.
private Vector3 m_Size = new Vector3(0,0,0);
The m_Radius variable holds the radius of the collision sphere that holds the entire object.
private float m_Radius = 0;
The m_RadiusAverage variable holds the average of the biggest parts of the object in the x, y, and z
axes directions. This radius may not enclose the entire object and is not used for our collision detecti
on method discussed later.
private float m_RadiusAverage = 0;
 
Search WWH ::




Custom Search