Graphics Reference
In-Depth Information
vec3
CModel::ComputePlanePosition() {
// initial plane position
P
oc
p
A:
vec3
planePos(0,0,0);
.
// plane node transform
M
p
Source file.
Model
_
AimPlane.cpp
file
UWB
_
XformInfo planeXf=m
_
PlaneNode->GetXformInfo();
.
planeXf.SetUpModelStack(dh);
// load
M
p
to top of matrix stack
dh.TransformPoint(planePos);
// compute
P
wc
B:
in
the
Model
folder
of
the
D3D
_
Orientation
project.
=
P
o
p
M
p
p
.
return
planePos;
// return plane position in WC:
P
wc
p
Listing 16.14.
Computing the plane position in WC.
The negation reflects the fact that the initial front direction of the plane points
toward the negative
z
-axis. Notice that the upward direction of the plane is in the
y
-axis direction of the WC, or
V
u
=
001
.
Now we can compute
V
s
according to Equation (16.6),
V
u
×
V
s
=
V
f
.
In order to ensure
V
u
is perpendicular to the other two axes, we must compute
V
u
=
V
f
×
V
s
.
Lastly, we must normalize all three vectors to compute
V
u
,
V
f
,and
V
s
for com-
ponents of the rotation matrix in Equation (16.5). Listing 16.14 shows that we
can compute the plane WC position (
P
w
p
) by observing that in OC space,
P
oc
p
is
simply the origin. At label A, we initialize the plane OC position
P
o
o
to be the
origin. At label B, we use the plane's scene node transform (
M
p
) to compute the
plane's position in WC space
P
w
p
.
In the following discussion, we separate the discussion of the
ComputePlane
Rotation()
function into three separate listings: Listing 16.15 presents how we
compute the plane-to-tiger direction
V
f
. Listing 16.16 describes using a rotation
matrix to aim the plane toward the tiger. Finally, Listing 16.17 describes us-
ing quaternion rotation to aim the plane toward the tiger. Listing 16.15 shows the
Search WWH ::
Custom Search