Game Development Reference
In-Depth Information
y
=
( m31
−
m13 )
∗
m u l t ;
z
=
( m12
−
m21 )
∗
m u l t ;
br e ak
;
c a s e
1 :
x
=
b i g g e s t V a l ;
w =
( m23
−
m32 )
∗
m u l t ;
y
=
( m12
+
m21 )
∗
m u l t ;
z
=
( m31
+
m13 )
∗
m u l t ;
br e ak
;
c a s e
2 :
y
=
b i g g e s t V a l ;
w =
( m31
−
m13 )
∗
m u l t ;
∗
x
=
( m12
+
m21 )
m u l t ;
∗
z
=
( m23
+
m32 )
m u l t ;
br e ak
;
c a s e
3 :
z
=
b i g g e s t V a l ;
w =
( m12
−
m21 )
∗
m u l t ;
x
=
( m31
+
m13 )
∗
m u l t ;
y
=
( m23
+
m32 )
∗
m u l t ;
br e ak
;
}
Listing 8.5
Converting a rotation matrix to a quaternion
8.7.5 Converting Euler Angles to a Quaternion
To convert an angular displacement from Euler angle form to quaternion, we
use a technique similar to the one used in
Section 8.7.1
to generate a rotation
matrix from Euler angles. We first convert the three rotations to quaternion
format individually, which is a trivial operation. Then we concatenate these
three quaternions in the proper order. Just as with matrices, there are
two cases to consider: one when we wish to generate an object-to-upright
quaternion, and a second when we want the upright-to-object quaternion.
Since the two are conjugates of each other, we walk through the derivation
only for the object-to-upright quaternion.
As we did in Section 8.7.1, we assign the Euler angles to the variables h,
p, and b. Let
h
,
p
, and
b
be quaternions that perform the rotations about
the y, x, and z-axes, respectively:
2
4
cos(h/2)
3
5
2
4
cos(p/2)
3
5
2
4
cos(b/2)
3
5
0
1
0
1
0
1
0
sin(h/2)
0
sin(p/2)
0
0
0
0
sin(b/2)
h
=
,
p
=
,
b
=
.
@
A
@
A
@
A
Now we concatenate these in the correct order. We have two sources of
“backwardness,” which cancel each other out. We are using fixed-axis rota-
tions, so the order of rotations actually is bank, pitch, and lastly heading.
Search WWH ::
Custom Search