Game Development Reference
In-Depth Information
The Paddle Game as it is presented here models the collision between the paddle and the
ball as if the ball hits the flat face. If you wanted to get more sophisticated, you could account
for the possibility that the ball would collide with the corner of the paddle. In this case, the line
of action for the collision wouldn't be parallel to the horizontal axis, but would instead be at
some angle depending on the point of impact between the ball and corner.
Three-Dimensional Collisions
The most general type of collision is a three-dimensional collision in which the line-of-action
vector can point anywhere in three-dimensional space. The same four steps that were used to
analyze two-dimensional collisions can be applied to three-dimensional collisions. As you
might expect, however, the process is a bit more complicated in three dimensions.
The major increase in complexity between two- and three-dimensional collisions is rotating
the coordinate system so one of the coordinate axes is parallel to the line of action of the collision.
With two-dimensional collisions, the coordinate rotation is performed through a single rotation
angle, and the rotated velocity components can be determined from a simple two-dimensional
rotation matrix. A general, three-dimensional collision analysis requires a three-dimensional coor-
dinate system rotation, which requires three separate axis rotations through three separate
rotation angles.
The rotation matrix for a three-dimensional coordinate system rotation is a complicated
3×3 matrix. The elements of the matrix depend on the order of the three axis rotations. For
example, the matrix shown in Equation (6.24) is a three-dimensional rotation matrix repre-
senting a rotation about the z-axis by an angle of f , followed by a rotation about the y-axis by
an angle of q , followed by a rotation about the x-axis by an angle of y .
cos
q
cos
f
cos
qf
sin
-
sin
q
R
=
(6.24)
-
cos
yf
sin
+
sin
yqf
sin
cos
cos
ψ
cos
f
+
sin
yqf
sin
sin
cos
qy
sin
sin
yf
sin
+
cos
yqf
sin
cos
-
sin
yf
cos
+
cos
yqf
sin
sin
-
cos
qy
cos
Three-dimensional rotation matrices are messy, and the three rotation angles have to be
determined before the rotation can be performed. What's more, the elements of the rotation
matrix will be different if the order of the axis rotations is changed. We won't go into any more
detail about three-dimensional rotation matrices here, but the topic will come up again when
we develop an airplane flight simulator in Chapter 10.
Determining Whether a Collision Occurs
This chapter has spent a considerable amount of time developing the mathematical models to
simulate collisions, but another important question is how to tell when a collision occurs. Basi-
cally, the question comes down to when the outer surface of one object comes in contact with
the outer surface of another object. For complicated, asymmetrical objects, this analysis can be
quite difficult, but it simplifies considerably for basic geometrical shapes.
One of the simplest shapes to evaluate collisions with is a sphere, or a circle in two dimen-
sions. As seen in Figure 6-10, two spheres collide with each other if the distance between the
centers of the spheres, d , is less than or equal to the sum of the radii, r 1 and r 2 , of the spheres.
 
Search WWH ::




Custom Search