Game Development Reference
In-Depth Information
Our method from
Section 8.7.2
for extracting Euler angles from an
object-to-upright matrix is summarized below.
p = arcsin(−m
32
)
(8.34)
atan2(m
31
,m
33
)
atan2(−m
13
,m
11
)
if cosp = 0,
otherwise.
h =
(8.35)
atan2(m
12
,m
22
)
0
if cosp = 0,
otherwise.
b =
(8.36)
For convenience, we repeat the needed matrix elements from Equation (8.20):
m
11
= 1 − 2y
2
− 2z
2
, m
12
= 2xy + 2wz,
m
13
= 2xz − 2wy, (8.37)
m
22
= 1 − 2x
2
− 2z
2
,
(8.38)
m
33
= 1 − 2x
2
− 2y
2
.
(8.39)
m
31
= 2xz + 2wy,
m
32
= 2yz − 2wx,
Substituting Equations (8.37)-(8.39) into Equations (8.34)-(8.36) and sim-
plifying, we have
p = arcsin(−m
32
)
= arcsin (−2(yz − wx))
8
<
atan2(m
31
,m
33
)
= atan2(2xz + 2wy,1 − 2x
2
− 2y
2
)
if cosp = 0,
= atan2(xz + wy,1/2 − x
2
− y
2
)
h =
:
atan2(−m
13
,m
11
)
= atan2(−2xz + 2wy,1 − 2y
2
− 2z
2
)
otherwise.
= atan2(−xz + wy,1/2 − y
2
− z
2
)
8
<
atan2(m
12
,m
22
)
= atan2(2xy + 2wz,1 − 2x
2
− 2z
2
)
if cosp = 0,
= atan2(xy + wz,1/2 − x
2
− z
2
)
b =
:
0
otherwise.
We can translate this directly into code, as shown in Listing 8.6, which
converts an object-to-upright quaternion into Euler angles.
Search WWH ::
Custom Search