Graphics Reference
In-Depth Information
void CModel::ComputeTigerPosition( float sec) {
// Transform operator of the tiger scene node
UWB _ XformInfo xf = m _ TigerNode->GetXformInfo();
// user rotation settings ( R )
mat3 tigerM = xf.GetRotation();
// forward direction in tiger oc space ( V o f )
A:
B:
vec3 tigerFront(0,0,-1);
// forward direction in WC ( V w f )
Source file.
Model _ MoveTiger.cpp
file
vec3 currentFront = tigerFront * tigerM;
// speed of 0.4 unit per second
in
the Model
folder
of
the
D3D _ Orientation project.
C:
float tigerSpeed = 0.4f;
// tiger's current velocity ( V t )
vec3 tigerVelocity = currentFront * tigerSpeed;
// sets the velocity to the scene node
m _ TigerNode->SetVelocity(tigerVelocity);
// computes: P t = P t +( V t × sec )
m _ TigerNode->MoveNodeByVelocity(sec);
D:
}
Listing 16.13. Moving the tiger forward.
Now, to move the tiger forward, we compute a forward-moving velocity V t ,
V wc
V t =
×
speed
,
f
where speed is some constant, and we change the tiger position P t :
P t =
P t +
V t .
Listing 16.13 shows the implementation of moving the tiger in its forward direc-
tion. The ComputeTigerPosition() function is called from CModel::Update
Simulation() during each timer update event. We can see a straightforward im-
plementation of the mathematics we have derived. At label A, we obtain a matrix
representation of the user's rotation settings R , the forward direction in WC space
V wc
f is computed at label B, the forward velocity V t is computed at label C, and
finally, the tiger's new position P t is computed at label D.
Aiming with a rotation matrix. Enable plane aiming by checking the “Aim
Plane At Tiger” checkbox. Notice that the orientation of the purple plane is
changed immediately to face toward the tiger. Now, enable the movement of the
tiger by checking the “Move Tiger” checkbox and navigate the tiger. Observe that
Search WWH ::




Custom Search