Graphics Reference
In-Depth Information
must maintain the quaternion state in our program and convert the quaternion
to a matrix for hardware processing. Listing 16.12 shows representing rotation
by a quaternion in the XformInfo class. Label A shows the corresponding sup-
porting methods. At label B, we see the data type quat ,the math3d++ support
quat . math3d++ supports
post-multiplication while
our library implements
pre-multiplication. Internally,
XformInfo stores rotation
in post-multiplication while
this representation is con-
verted in pre-multiplication
with makeTranspose() to
transpose the rotation matrix.
for quaternion. The first three values of a quat data type define the axis of ro-
tation with the fourth value defining the amount to rotate. At label C, we see
that zero rotation of a quaternion is defined to be
(
)
. This initial value
allows proper subsequent concatenation of quaternion operators. At label D, we
see that the quaternion must be converted into a matrix for setting the hardware
matrix processor. At label E, we see that to support updating of rotation, similar
to matrix operations, we first construct a new quaternion operator to represent the
dx rotation about the x -axis, and then we compute concatenation to represent the
composite rotations. At label F, we see that it is possible to convert a rotation
represented by a matrix into a quaternion.
0
,
0
,
0
,
1
Tutorial 16.4.
Project Name:
D3D _ RotateQuat
Library Support:
UWB _ MFC _ Lib1
UWB _ D3D _ Lib17
Tutorial 16.4. Rotation with a Quaternion
Goal. Demonstrate that working with the quaternion rotation representa-
tion can be identical to that of a matrix.
Approach. Port the previous tutorial over and see that no changes in the
CModel class or the UI controls are required.
Figure 16.7 is a screenshot of running Tutorial 16.4. The source code for this
project is identical to that from Tutorial 16.3. The only difference in this case is
the quaternion support in the XformInfo class of Lib17 . This tutorial behaves
identically to Tutorial 16.3.
Figure 16.7.
Tutorial
16.4.
16.3 Orientation in 3D
At this point, we are working with UWBGL _ LIB17 , where rotation is represented
with a quaternion in the XformInfo class. Before rendering, the quaternion is
converted into a rotation matrix, and the DrawHelper::AccumulateModelTrans
form() function is invoked to compute Equation (16.3) (on p. 460):
M
=
T
(
p
)
S
(
s
)
RT
(
p
)
T
(
t
) ,
where p is the pivot position, t is the translation vector, s is the scaling factor,
and R is the rotation matrix. In this way, the translation vector ( t ) defines the
location, the scaling factor ( s ) defines the size, and the rotation matrix defines the
orientation of the object drawn.
 
Search WWH ::




Custom Search