Game Development Reference
In-Depth Information
Bank is computed in a similar manner from m 12 and m 22 :
m 12 = sinbcosp,
m 12 /cosp = sinb;
m 22 = cosbcosp,
m 22 /cosp = cosb;
b = atan2(sinb,cosb) = atan2(m 12 /cosp,m 22 /cosp)
= atan2(m 12 ,m 22 ).
Now we've got all three angles. However, if cosp = 0, then we cannot
use the above trick since it would result in division by zero. But notice that
when cosp = 0, then p = ±90 o , which means we are either looking straight
up or straight down. This is the Gimbal lock situation, where heading
and bank effectively rotate about the same physical axis (the vertical axis).
In other words, the mathematical and geometric singularities occur at the
same time. In this case, we will arbitrarily assign all rotation about the
vertical axis to heading, and set bank equal to zero. This means that we
know values of pitch and bank, and all we have left is to solve for heading.
If we take the simplifying assumptions
cosp = 0,
b = 0,
sinb = 0,
cosb = 1,
and plug these assumptions into Equation (8.14), we get
2
3
coshcosb + sinhsinpsinb sinbcosp − sinhcosb + coshsinpsinb
− coshsinb + sinhsinpcosb cosbcosp sinbsinh + coshsinpcosb
sinhcosp
4
5
− sinp
coshcosp
2
3
cosh(1) + sinhsinp(0)
(0)(0)
− sinh(1) + coshsinp(0)
4
5
=
− cosh(0) + sinhsinp(1)
(1)(0)
(0) sinh + coshsinp(1)
sinh(0)
− sinp
cosh(0)
2
3
cosh
0
− sinh
4
5
=
sinhsinp
0
coshsinp
.
0
− sinp
0
Now we can compute h from −m 13 and m 11 , which contain the sine and
cosine of heading, respectively.
Listing 8.4 is C code that extracts the Euler angles from an object-to-
upright rotation matrix, using the technique developed above.
Search WWH ::




Custom Search