Graphics Reference
In-Depth Information
void
CModel::FireArrow()
{
Source File.
Model
_
FireArrow.cpp
file
//
pxf
is the plane's transform
in
the
Model
folder
of
the
D3D_Orientation
project.
UWB
_
XformInfo pxf = m
_
PlaneNode->GetXformInfo();
//
axf
is the arrow's transform
UWB
_
XformInfo axf = m
_
ArrowNode.GetXformInfo();
// Arrow translation set to plane WC position
A:
B:
axf.SetTranslation(ComputePlanePosition());
// Arrow orientation is plane rotation quaternion
axf.SetRotationQuat(pxf.GetRotationQuat());
// Update arrow scene node XformInfo
m
_
ArrowNode.SetXformInfo(axf);
}
Listing 16.19.
Compute initial transform for the arrow.
Let
V
m
=
forward direction of arrow
,
.
By observation, we know the arrow's original forward direction is along the neg-
ative
z
-axis,
V
f
=
direction from arrow toward tiger
V
o
m
=(
0
,
0
,−
1
)
.
We also know that at any time, the arrow's scene node rotation
R
a
will rotate the
R
a
and q
a
.R
a
is the rotation
matrix of the arrow scene node
XformInfo
. The correspond-
ing quaternion rotation is
q
a
.
arrow's forward direction to
V
o
m
R
a
.
For the arrow to travel forward, we simply change its translation in the
V
w
m
di-
rection. Now, we must also adjust the forward direction of the arrow to align
V
w
m
with
V
f
. By now we know the rotation
q
b
,
V
w
m
=
where
V
b
V
w
m
×
=
V
f
,
V
b
,
θ
b
)
q
b
=(
V
wc
m
V
f
)
,
aligns
V
w
m
with
V
f
. In exactly the same manner as in the teapot's case before,
θ
b
=
acos
(
·
q
a
−
rotates from OC to WC
,
q
b
−
rotates from WC to aim at tiger
,
q
c
−
q
a
q
b
−
rotates from OC to aim at tiger
,
where we are interested in computing a
q
new
that is a linear combination of the
q
a
and
q
c
rotations. Listing 16.20 shows the implementation of the home-in func-
tionality. At label A, we compute
V
w
m
according to the arrow's scene node trans-
form. The code under label B is similar to that of Listing 16.13 where we must
Search WWH ::
Custom Search