Graphics Reference
In-Depth Information
void
CModel::ComputeArrowTransform(
float
sec) {
A:
vec3
arrowFront(0,0,-1);
//
V
o
m
initially is -z axis
mat3
Ra=m
_
ArrowNode...GetRotation();
//
R
a
arrow node rotation
arrowFront = arrowFront
*
Ra;
//
V
w
m
=
V
o
m
R
a
.
B:
// Similar to Listing
16.13
: Computing forward direction and moving forward
// arrow velocity is defined by the current
V
w
m
vec3
arrowV = arrowSpeed
*
arrowFront;
// arrow node gets the new velocity
m
_
ArrowNode.SetVelocity(arrowV);
// move the arrow node
m
_
ArrowNode.MoveNodeByVelocity( sec );
.
// compute
V
f
C:
vec3
dirToTiger = ...
// length of
V
f
. if this is short, then it means
float
dist = length(dirToTiger);
// the arrow is close to the tiger. Hit! We are done.
if
(dist < 1.0f)
return
;
.
D:
// Similar to Listing
16.18
: Gradual alignment with
V
f
using
slerp
// to compute
V
w
m
·
V
f
)
float
cosTheta=dot(arrowFront,dirToTiger);
.
vec3
rotAxis=cross(arrowFront,dirToTiger);
//
V
b
=
θ
b
=
acos
(
V
w
m
×
V
f
)
V
b
,
θ
b
)
//
q
b
=(
quat qb = quatFromAA(rotAxis, theta);
// compute and set
q
a
and
q
c
.
//
q
new
is linear combination of
q
a
and
q
c
quat newQ = slerp(qa, qc, homeInRate);
.
// sets the new rotation to the arrow scene node XformInfo
}
Listing 16.20.
Computing homing-in functionality.
Source file.
Model
_
FireArrow.cpp
file
re-compute the velocity according to the up-to-date forward direction. At label
C,
V
f
, the vector between the arrow and the tiger is computed and tested. If this
vector is short, it means that the tiger and the arrow are close by. We will register
in
the
Model
folder
of
the
D3D
_
Orientation
project.
Search WWH ::
Custom Search