Graphics Reference
In-Depth Information
void
CModel::ComputePlaneRotation(
float
sec) {
// details are in:
Listing 16.15
...
//compute the dirToTiger =
V
f
.
Source file.
Model
_
AimPlane.cpp
file
if
(
this
->m
_
RotateWithMatrix)
// details are in:
Listing 16.16
...
// aim the plane with a rotation matrix
.
else
in
the
Model
folder
of
the
D3D
_
Orientation
project.
// front dir (
V
p
) is negative
z
A:
vec3
frontDir(0,0,-1);
//
R
a
- current plane rotation matrix
mat3
pm = planeXF.GetRotation();
//
V
w
p
=
V
o
p
R
a
- front direction in WC
frontDir = frontDir
*
pm;
// cosTheta is
θ
b
is the angle between
V
wc
θ
b
, where
and
V
f
p
B:
float
cosTheta=dot(frontDir, dirToTiger);
.
// convert the angle into degree
float
theta=UWB
_
ToDegrees(acosf(cosTheta));
// Two vectors already aligned, done.
if
(theta < 0.001f)
return
;
// rotAxis is:
V
b
=
V
w
p
×
V
f
C:
vec3
rotAxis=cross(frontDir,dirToTiger);
// Normaize
V
b
to
V
b
normalize(rotAxis);
// compute
q
b
=(
V
b
,
θ
b
)
D:
quat qb = quatFromAA(rotAxis, theta);
// final plane rotation
q
b
concatenate
R
a
planeXf.UpdateRotationByQuat(qb);
// update plane scene node with new rotation
m
_
PlaneNode->SetXformInfo(planeXf);
←
Listing 16.17.
Aiming the plane with a quaternion rotation.
then we can consider the aiming operation as a single rotation to align the
V
p
vector in the
V
f
direction. We observe that in the original object space, the plane's
forward direction is
V
o
p
=(
,
,−
)
.
0
0
1
Search WWH ::
Custom Search