Game Development Reference
In-Depth Information
where p is the position of the object. This equation works in both 2D and 3D, al-
though the definition of Θ is different, as we'll see later in the chapter.
Forourcarexampleweget
0 . 38
1 . 5
4
3 . 85
1 . 27
1 . 10
4
3 . 85
5 . 27
4 . 95
0 . 92
q
=
+
=
+
=
0 . 92
0 . 38
0 . 75
This calculation of the location of part of an object, based on the object's position and
orientation and the relative position of the component, is called a “transformation
from local space” (also called “body space” and “object space”) to world space. We'll
The Composition of Rotations and Translations
One vital result to notice is that any sequence of translations and rotations can be
represented with a single position and orientation. In other words, no matter how
many times I move and turn the car, we can always give a single set of values for its
current position and orientation. This is equivalent to saying that any combination
of rotations and translations is equivalent to a single rotation followed by a single
translation.
Rigid Bodies
The fact that all the components of an object are fixed relative to its origin is the
reason why we talk about rigid bodies when it comes to physics engines. If our car is
a infant's toy made of squashable rubber, then knowing the position and orientation
isn't enough to tell us where the headlamp is: the headlamp might have been stretched
out into a very different position.
Some physics engines can deal with simple soft bodies, but usually they work by
assuming the body is rigid and then applying some after-effects to make it look soft.
In our engine, as well as in the vast majority of game physics engines, we will support
only rigid bodies.
Theoretically we could choose any point on the object to be its origin. For objects
that aren't being physically simulated, this is often the approach developers take: they
choose a point that is convenient for the artist or artificial intelligence (AI) program-
mer to work with. It is possible to create physics code that works with an arbitrary
origin, but the code rapidly becomes fiendishly complicated. There is one position on
every object where the origin can be set that dramatically simplifies the mathematics:
the center of mass.
Center of Mass
The center of mass (often called the “center of gravity”) is the balance point of an
object. If you divide the object in two by cutting any straight line through this point,
you will end up with two objects that have exactly the same weight. If the object is a