Game Development Reference
L AWS OF M OTION
FOR R IGID B ODIES
time working with rigid bodies rather than particles. We'll do this by creating a
new class: RigidBody .
In section 9.1.3 I mentioned that if an object's origin is placed at its center of mass,
then its linear motion will be just like that of a particle. We'll make use of that fact
in this chapter. Almost all the code for the linear motion of our rigid body is lifted
directly from our particle class. To this we will add two things:
In this chapter we're going to repeat the work we did in chapters 2, 3, and 5, this
1. The laws of motion for rotating bodies, equivalent to the way we implemented
Newton's second law of motion.
2. The mathematics of forces that have both a linear and a rotational effect. The
question is, for a given force applied, how much will the object rotate?
With the rigid body in place, and these two extensions implemented, we will have
a rigid-body physics engine equivalent to the particle engine from part I. Adding
collisions and hard constraints will then occupy us for the remainder of this topic.
T HE R IGID B ODY
We can start by creating a RigidBody class, containing the same information we had
in the Particle class, and adding the extra data structures for rotation that we met in
the previous chapter. The code looks like the following.