Game Development Reference

In-Depth Information

F
IGURE
9.1

The angle that an object is facing.

In two dimensions we can represent an object by its two-dimensional position

and an angle that shows how it is oriented. Just as the position is specified relative to

some fixed origin point, the angle is also given relative to a predetermined direction.

Figure 9.1 illustrates this.

If the object is rotating, its orientation will change over time. Just as velocity is

the first derivative of position (see chapter 2), angular velocity is the first derivative of

orientation.

I will use the word
orientation
throughout this topic to refer to the direction in

which an object is facing. The word
rotation
has many meanings in different contexts,

and while most people feel they know what it means, it is one of those terms that can

be a chameleon, causing subtle confusion.

To be specific, I'll try to use
rotation
only to mean a change in orientation (the

exception being that when everybody and their dog calls something “rotation,” I'll

avoid the temptation to make up a new name). If something is rotated, it is natural to

mean that its orientation has changed.

If an object is spinning, however, I'll use the term
angular velocity
to mean the

rate of change of orientation.

9.1.1

T
HE
M
ATHEMATICS OF
A
NGLES

If we do any mathematics with orientations, we need to be careful: many different

orientation values can represent the same orientation. If we measure orientation in

radians (there are 2
π
radians in the 360
◦
of a circle), then the orientation of 2
π
is the

same as 0. Developers normally set a fixed range of orientation values, say
(

π,π
]

(the square bracket indicates that
π
is included in the range, and the curved bracket

that

−

π
is not). If an orientation falls outside this range, it is brought back into the

range. The mathematical routines that deal with this kind of orientation scalar can

look messy, with lots of adjustments and checks.

An alternative approach is to use vectors to represent orientation. We take a two-

element vector representing the direction in which the object is pointing. The vector

is related to the scalar value according to the equation

−

cos
θ

sin
θ

θ

=

[9.1]