Game Development Reference
In-Depth Information
Chapter 5
Motion and Collision
In this chapter, I will discuss motion and collision. In terms of motion, I will discuss the basics of
an object's linear velocity, linear acceleration, angular velocity, and angular acceleration. I cover
Newton's three laws of motion and the new Physics class we have created to implement these
laws of motion. I then discuss a hands-on example that demonstrates with a bouncing and rotating
cube how to apply linear and angular acceleration to objects. Next, I cover collision detection and
collision response and add code to our Physics class to implement this collision detection and
collision response. I then go through a hands-on example where we add in another cube on top
of the one from the previous hands-on example and demonstrate our new collision detection and
response code. Finally, we create a gravity grid and then demonstrate its use by adding this grid to
the previous hands-on example with the two colliding cubes.
Overview of Motion
I will start by covering linear and angular velocity and acceleration, as well as Newton's three laws of
motion, and then put all of these to use in the hands-on examples.
Linear Velocity and Linear Acceleration
Linear velocity is a vector quantity that has direction and magnitude. For example, let's say that a car
is heading northeast on a street at 35 miles per hour. This can be represented by a vector pointing
in the northeasterly direction and with a magnitude that would represent 35 miles an hour. Let's say
the driver presses down on the brake. This produces an acceleration in the opposite direction to the
velocity, which has the result of slowing the car down. After the car stops, the driver then puts the
car into reverse and drives down the street backward. The resulting velocity and acceleration vectors
are now back in alignment. (See Figure 5-1 .)
135
 
Search WWH ::




Custom Search