Graphics Reference
In-Depth Information
Rotation: q c
Teapot OC
z
y
Facing the Tiger
x
Rotation: q new
Intermediate
Rotation: q a
Turning gradually
from current
to facing the tiger”
Current
Figure 16.12.
Linear interpolation of rotations.
tion is similar to Listing 16.17). At label B, we obtain a copy of the existing
q a rotation and take advantage of the XformInfo::UpdateRotationByQuat()
function to compute q c by concatenating q b with q a . At label C, we invoke the
math3d++::slerp() function to compute q new as a linear combination of 95% q a
and 5% q c . In this way, the orientation of the teapot will gradually approach the
desired q c rotation.
Homing in with slerp. Click on the “Shoot” button to release an arrow from
the plane. Notice that the arrow travels toward the tiger. When this arrow collides
with the tiger, it will disappear. Select the tiger node and adjust the slider bars to
change the translation of the tiger. Now, release another arrow and see that the
arrow now travels toward the new tiger position. In fact, we can change the tiger
position at any time to observe the arrow adjusting its flight path to home in on
the tiger. This example demonstrates that we can combine moving forward and
slerp functionality to implement a home-in flight path.
To implement this functionality, we must release the arrow according to the
position and the orientation of the plane. In this way, the arrow begins its flight
from the plane location with initial direction aligned to that of the plane. List-
ing 16.19 shows the FireArrow() function that computes the initial transforma-
tion of the arrow. At label A, we define accessors to the XformIno of the plane and
the arrow. At label B, we set the arrow's position and rotation according to that
of the plane's. With the proper transformation settings, home-in behavior can be
implemented simply as continuously moving the arrow forward while adjusting
the forward direction of the arrow slightly toward the tiger using slerp.
Search WWH ::




Custom Search