Graphics Reference
In-Depth Information
Source file.
Model _ MoveToTarget.cpp
file in the Model folder of
the D3D _ OrientationIn2D
project.
bool CModel::ComputeFrontVelocity( float sec) {
. // code from Listing 12.2 : Computed front direction ( V w f )
. // code from Listing 12.3 : Computed and decreased
θ
// fronDir= V wc f (normalized)
vec3 velocity = frontDir * ARM _ SPEED * sec;
m _ pArmDrive->SetVelocity(velocity);
}
Listing 12.4. Step 3: Compute and set arm velocity.
overshoot when rotating the arm toward the target. At label E, we compute the
Left versus right turns. See
Section B.2.2 for details of
applying the cross product in
differentiating left from right
sides of a given vector.
cross product of V wc f and V w t in order to determine if the arm object should be
turning left or right to face the target position p wc
t
. At label F, the arm's rotation is
updated by a percentage of the computed
value. In this way, we can accomplish
the effect of turning the arm object gradually toward the target in subsequent
updates. Listing 12.4 shows the final computation of the velocity for the arm
object. Recall that frontDir has been normalized. Here, we are setting the
appropriate scene node velocity such that the arm object will move at constant
speed ( ARM _ SPEED ) toward the current front direction ( V w f ).
This tutorial demonstrates some valuable lessons.
θ
Coordinate system. We must be acutely aware of the different coordinate
systems involved. We have chosen the world coordinate (WC) system to
carry out all computations.
Directions. In this case, the front direction of the arm object in OC space
is defined trivially to be along the x -axis. However, as the arm navigates in
the WC space, we must continuously recompute the current front direction
in the WC space. As we have seen, we:
- identify appropriate positions in the OC space, that is, identify p o f and
p o o ;
- transform these positions from OC to WC, that is, compute p wc
f
and
p w o ;
- compute the WC direction vector by subtracting the WC positions,
that is, compute V wc
f
p wc
f
p w o .
=
Turn i ng . Given a forward-facing direction ( V wc
f
) and a target position
( p wc
t
), we use the vector dot product to determine the amount of turning
Search WWH ::




Custom Search