Game Development Reference
In-Depth Information
With those considerations in mind, we set out to solve for the Euler
angles from the rotation matrix (Equation (8.14)) directly. For your con-
venience, the matrix is expanded below:
2
3
coshcosb + sinhsinpsinb sinbcosp − sinhcosb + coshsinpsinb
− coshsinb + sinhsinpcosb cosbcosp sinbsinh + coshsinpcosb
sinhcosp
4
5
.
− sinp
coshcosp
We can solve for p immediately from m 32 :
m 32 = − sinp,
−m 32 = sinp,
arcsin(−m 32 ) = p.
The C standard library function asin() returns a value in the range
[−π/2,+π/2] radians, which is [−90 o ,+90 o ], exactly the range of values
for pitch allowed in the canonical set.
Now that we know p, we also know cosp. Let us first assume that
cosp = 0. Since −90 o ≤ p ≤ +90 o , this means that cosp > 0. We can
determine sinh and cosh by dividing m 13 and m 33 by cosp:
m 31 = sinhcosp,
m 33 = coshcosp,
m 31 /cosp = sinh,
m 33 /cosp = cosh.
(8.16)
Once we know the sine and cosine of an angle, we can compute the value
of the angle with the C standard library function atan2() . This function
returns an angle in the range [−π,+π] radians ([−180 o ,+180 o ]), which is
again our desired output range. Knowing just the sine or cosine of angle
isn't enough to uniquely identify an angle that is allowed to take on any
value in this range, which is why we cannot just use asin() or acos() .
Substituting the results from Equation (8.16) yields
h = atan2(sinh,cosh) = atan2(m 31 /cosp,m 33 /cosp).
However, we can actually simplify this because atan2(y,x) works by taking
the arctangent of the quotient y/x, using the signs of the two arguments to
place the angle in the correct quadrant. Since cosp > 0, the divisions do not
affect the signs of x or y, nor do they change the quotient y/x. Omitting
the unnecessary divisions by cosp, heading can be computed more simply
by
h = atan2(m 31 ,m 33 ).
Search WWH ::




Custom Search