Graphics Reference
In-Depth Information
bool
CModel::ComputeFrontVelocity(
float
sec) {
Source file.
Model
_
MoveToTarget.cpp
file in the
Model
folder of
the
D3D
_
OrientationIn2D
project.
.
// code from Listing
12.2
: that computed frontDir=
V
wc
f
in WC
// Target gray circle's transform
A:
txf=m
_
pMoveToTarget->GetXformInfo();
// movePt=
p
wc
t
(target position)
vec3
movePt = txf.GetTranslation();
// dir=
V
wc
=
p
wc
t
−
p
wc
o
(direction towards target)
t
B:
vec3
dir = movePt - initPos;
//
p
o
is very close to
p
t
=> done.
if
(length(dir) < 0.1f)
return false
;
// vector normalization: compute
V
wc
f
V
wc
t
and
C:
normalize(frontDir); normalize(dir);
//
cos
θ
=
V
w
t
)
theta = fabs(acosf(dot(frontDir, dir)));
//
V
wc
f
V
w
t
,or
θ
=
acos
(
V
wc
f
·
·
θ
is not very small (zero)
D:
if
(theta > 0.001f) {
//
zDir
V
w
f
×
V
wc
t
=
E:
vec3
zDir = cross(frontDir, dir);
//
aTheta
is the current Arm rotation
float
aTheta = axf.GetRotationInRadians();
// check sign of z-component from cross product
// to turn clockwise or counterclockwise
if
(zDir.z > 0) aTheta += theta
*
TURN
_
RATE;
else
aTheta -= theta
*
TURN
_
RATE;
axf.SetRotationRadians(aTheta);
// sets new rotation to
M
a
of Figure
12.3
m
_
pArmDrive->SetXformInfo(axf);
F:
}
.
// contiune with code from Listing
12.4
: to update new velocity for Arm
Listing 12.3.
Step 2: Compute and decrease θ .
computed. Listing 12.3 shows the details of the second step of
ComputeFrontVel
ocity()
(from Listing 12.1). At label A, the target position
p
w
t
in WC is re-
trieved from the appropriate transform. At label B,
V
w
t
is computed. The length
of this vector is the distance between the arm origin (
p
w
o
) and the target. When
this distance is small, the arm has arrived at the target position and we are done.
At label C, the
V
wc
f
and
V
wc
t
vectors are normalized, and the angle
θ
between these
two vectors is computed. A small
value represents that the arm is pointing ap-
proximately toward the target. The checking at label D ensures that we do not
θ
Search WWH ::
Custom Search