Graphics Reference
In-Depth Information
As illustrated in Figure 16.10, in the WC space, the plane's current forward direc-
tion is rotated by the plane node's XformInfo operator R a :
V wc
p
V o p R a .
=
By normalizing the vectors into V wc
p
and V f , we know the angle
θ b between the
two vectors is
V wc
V f ) .
θ b =
(
·
acos
p
Rotation matrix and quater-
nion. As discussed in
Section 16.2, all rotation (or-
thonormal) matrices can be
converted into corresponding
quaternion representations. If
R a is a rotation matrix that
describes a sequence of rota-
tions, then the corresponding
quaternion q a would represent
the same rotation.
In addition, as shown in Figure 16.10, we know that the axis of rotation V b must
be perpendicular to both V w p and V f ,or
V wc
V b =
×
V f .
p
We can normalize the axis of rotation to V b . In this way, we can describe V f as
the result of rotating V wc
p
V b axis by
about the
θ b . Notice that rotating
θ b about
V b is the quaternion rotation
V b , θ b ) .
q b =(
Listing 16.17 is a continuation of Listing 16.16. This listing shows the same
plane-aiming functionality with quaternion rotation implementation. At label A,
the initial front direction V o p of the plane is defined to be in the negative z -axis and
transformed to V wc
p
in WC space. At label B, we compute the angle
θ b between
V wc
p
θ b value says that the two vectors
( V w p , V f ) are almost parallel (in the same direction), and we are done. At label
C, the axis of rotation V b is computed and normalized. At label D, the quaternion
is computed and set to the plane scene node transformation operator.
and V f with a dot product. A very small
Slerp: Spherical linear interpolation with quaternion. Restart Tutorial 16.5,
enable rotation with quaternion computation by selecting the “Rotate With Quat”
radio button, and click on “Aim Teapot At Tiger.” Notice that in this case, instead
of instantaneous change of orientation, the teapot rotates gradually toward the
tiger. As illustrated in Figure 16.11, let the spout of the teapot to be the forward
direction and,
V t
=
teapot spout direction
,
V f
=
direction from teapot to tiger
.
In the original object coordinate (OC) space, the teapot spout points in the positive
x -direction, or
V oc
t
=(
1
,
0
,
0
) .
Search WWH ::




Custom Search