Game Development Reference

In-Depth Information

F
IGURE
9.4

The car is rotated.

The matrix form of orientation looks like this:

cos
θ

−

sin
θ

Θ

=

sin
θ

cos
θ

where
θ
is the orientation angle, as before. This matrix is usually called the “rotation

matrix”: it can be used to rotate a location. We can work out the new position of the

headlamp by multiplying the
relative
position of the headlamp by the rotation matrix

cos
θ

q
b

−

sin
θ

q
=

sin
θ

cos
θ

where
q
b
is the relative location of the headlamp. In our case, where
θ

=

3
π/
8, we get

0
.
38

1
.
5

−

0
.
57

1
.
27

1
.
10

−

0
.
92

+

0
.
69

q
=

=

=

0
.
92

0
.
38

0
.
75

1
.
39

−

0
.
29

whereallvaluesaregiventotwodecimalplaces.

After applying the orientation in this way we can then apply the change in position

as before. The total process looks like this:

q

=

Θ
q
b
+

p

[9.2]