Graphics Reference
In-Depth Information
// gazePt=
p
wc
r
void
CArm::ComputePalmGaze(
vec3
gazePt,
float
sec) {
Source file.
ArmPalmGaze.cpp
file
in
// front=
p
o
f
; palmPos=
p
o
p
the
Model
folder
of
the
D3D
_
SceneNodeOrient
project.
A:
vec3
front(5,0,0), palmPos(4,0,0);
// This is
M
a
of Figure
12.3
UWB
_
XformInfo xf = GetXformInfo();
// This is
M
p
of Figure
12.3
UWB
_
XformInfo pxf = GetPalmNode()->GetXformInfo();
// Imitate scene graph traversal
dh.PushModelTransform();
// to compute OC->WC xform
B:
dh.InitializeModelTransform();
//
M
a
(parent) gets on stack first
xf.SetUpModelStack(dh);
// top of matrix stack now
=
M
a
M
p
pxf.SetUpModelStack(dh);
// Compute
p
wc
f
=
p
oc
f
M
a
M
p
C:
dh.TransformPoint(front);
// Compute
p
w
p
=
p
o
p
M
p
M
a
dh.TransformPoint(palmPos);
dh.PopModelTransform();
// currentPalmGaze=
V
w
p
=
p
w
f
−
p
wc
p
D:
vec3
currentPalmGaze = front - palmPos;
// newPalmGaze=
V
wc
r
vec3
newPalmGaze = gazePt - palmPos;
// palm overlaps the gaze position, we are done
if
(length(newPalmGaze) < 0.1f)
return
;
.
// remaining code is similar to Listing
12.3
}
Listing 12.5.
Computing the aim direction for the palm.
Our goal here is to rotate the
V
wc
p
direction to align with the
V
w
r
vector. We can
expect the solution to the fundamental problem of rotating one vector (
V
w
f
)to
align with another (
V
w
t
) to be similar to that in Listing 12.3. In this case, we must
pay attention to the slightly different OC-to-WC transformation. Listing 12.5
shows the details of computing the front direction for the palm component (
V
w
p
).
At label A, the palm's front (
p
o
f
) and origin (
p
o
p
) positions are defined in the OC
space. At label B, we imitate the scene graph traversal procedure and set up the
OC-to-WC transformation matrix on the matrix stack. At label C, the front and
origin positions are transformed into WC space (
p
wc
f
and
p
w
p
). And finally at label
Search WWH ::
Custom Search