Graphics Reference
In-Depth Information
void
CModel::ComputeTeapotRotation(
float
sec) {
.
// Compute
dirToTiger
(
V
f
)
: direction from teapot to tiger
//
(1)
: compute teapot position in WC: details are similar to Listing
16.14
//
(2)
: compute
V
f
by subtracting teapot from tiger position:
// details are similar to Listing
16.15
//
dirToTiger
(
V
f
)
is computed and initialized
.
if
(m
_
RotateWithMatrix)
// Compute teapot aiming with rotation matrix:
// details are similar to
Listing 16.16
.
Source file.
Model
_
AimTeapot.cpp
file
else
in
the
Model
folder
of
the
D3D
_
Orientation
project.
//
V
oc
t
- teapot spout direction in OC
A:
vec3
teapotFront(1.0f,0.0f,0.0f);
// the
R
a
rotation (
q
a
)
mat3
tm = teapotXf.GetRotation();
//
V
w
t
=
V
oc
t
R
a
teapotFront = teapotFront
*
tm;
//
V
wc
t
V
f
)
float
cosTheta=dot(teapotFront,dirToTiger);
// convert from radians to degree
float
theta = UWB
_
ToDegrees(acosf(cosTheta));
.
vec3
rotAxis = cross(teapotFront, dirToTiger);
//
V
b
=
θ
b
=
acos
(
,
V
wc
t
V
f
×
// normalize
V
b
to get
V
b
normalize(rotAxis);
V
b
,
θ
b
)
//
q
b
=(
quat qb = quatFromAA(rotAxis, theta);
// keep a copy of
q
a
(or
R
a
)
B:
quat qa = teapotXf.GetRotationQuat();
teapotXf.UpdateRotationByQuat(qb);
// concat. to the XformInfo:
//
q
c
=
q
a
q
b
//
q
c
quat qc = teapotXf.GetRotationQuat();
C:
quat newQ = slerp(qa, qc, 0.05f);
// newQ=
q
new
5
%
from
q
a
to
q
c
teapotXf.SetRotationQuat(newQ);
// sets the new rotation
q
new
m
_
TeapotNode->SetXformInfo(teapotXf);
// to the XformInfo node
Listing 16.18.
Slerp: Working with spherical linear interpolation.
spherical arc, or spherical linear interpolation, or simply slerp.
Listing 16.18
shows implementation with spherical linear interpolation (slerp).
At label A,
we compute the
q
b
rotation that aligns the current
V
wc
with
V
f
(this computa-
t
Search WWH ::
Custom Search