i
i
i
i
i
i
i
i
78 4. Transforms
Figure 4.9. Unit quaternions are represented as points on the unit sphere. The function
slerp is used to interpolate between the quaternions, and the interpolated path is a great
arc on the sphere. Note that interpolating from
ˆ
q
1
to
ˆ
q
2
and interpolating from
ˆ
q
1
to
ˆ
q
3
to
ˆ
q
2
are not the same thing, even though they arrive at the same orientation.
constitute the shortest arc on a four-dimensional unit sphere from
ˆ
q (t =0)
to
ˆ
r (t = 1). The arc is located on the circle that is formed from the
intersection between the plane given by
ˆ
q,
ˆ
r, and the origin, and the four-
dimensional unit sphere. This is illustrated in Figure 4.9. The computed
rotation quaternion rotates around a fixed axis at constant speed. A curve
such as this, that has constant speed and thus zero acceleration, is called
a geodesic curve [263].
The slerp function is perfectly suited for interpolating between two ori-
entations and it behaves well (fixed axis, constant speed). This is not the
case with when interpolating using several Euler angles. In practice, com-
puting a slerp directly is an expensive operation involving calling trigono-
metric functions. Li [771, 772] provides much faster incremental methods
to compute slerps that do not sacrifice any accuracy.
When more than two orientations, say
ˆ
q
0
,
ˆ
q
1
,...,
ˆ
q
n1
, are available,
and we want to interpolate from
ˆ
q
0
to
ˆ
q
1
to
ˆ
q
2
, and so on until
ˆ
q
n1
,slerp
could be used in a straightforward fashion. Now, when we approach, say,
ˆ
q
i
,wewoulduse
ˆ
q
i1
and
ˆ
q
i
as arguments to slerp. After passing through
ˆ
q
i
,wewouldthenuse
ˆ
q
i
and
ˆ
q
i+1
as arguments to slerp. This will cause
sudden jerks to appear in the orientation interpolation, which can be seen
in Figure 4.9. This is similar to what happens when points are linearly
interpolated; see the upper right part of Figure 13.2 on page 578. Some
readers may wish to revisit the following paragraph after reading about
splines in Chapter 13.
A better way to interpolate is to use some sort of spline. We introduce
quaternions
ˆ
a
i
and
ˆ
a
i+1
between
ˆ
q
i
and
ˆ
q
i+1
. Spherical cubic interpola-
i
i
i
i
i
i
i
i
4.3. Quaternions 79
tion can be defined within the set of quaternions
ˆ
q
i
,
ˆ
a
i
,
ˆ
a
i+1
,and
ˆ
q
i+1
.
Surprisingly, these extra quaternions are computed as shown below [294]
12
:
ˆ
a
i
=
ˆ
q
i
exp
log(
ˆ
q
1
i
ˆ
q
i1
) + log(
ˆ
q
1
i
ˆ
q
i+1
)
4
. (4.51)
The
ˆ
q
i
,and
ˆ
a
i
will be used to spherically interpolate the quaternions using
a smooth cubic spline, as shown in Equation 4.52:
squad(
ˆ
q
i
,
ˆ
q
i+1
,
ˆ
a
i
,
ˆ
a
i+1
,t)=
slerp(slerp(
ˆ
q
i
,
ˆ
q
i+1
,t), slerp(
ˆ
a
i
,
ˆ
a
i+1
,t), 2t(1 t)).
(4.52)
As can be seen above, the squad function is constructed from repeated
spherical interpolation using slerp (see Section 13.1.1 for information on re-
peated linear interpolation for points). The interpolation will pass through
the initial orientations
ˆ
q
i
, i [0,...,n1], but not through
ˆ
a
i
—these are
used to indicate the tangent orientations at the initial orientations.
Rotation from One Vector to Another
A common operation is transforming from one direction s to another di-
rection t via the shortest path possible. The mathematics of quater-
nions simplifies this procedure greatly, and also shows the close relation-
ship the quaternion has with this representation. First, normalize s and
t. Then compute the unit rotation axis, called u, which is computed as
u =(s × t)/||s × t||.Next,e = s · t =cos(2φ)and||s × t|| =sin(2φ),
where 2φ is the angle between s and t. The quaternion that represents
the rotation from s to t is then
ˆ
q =(sinφu, cos φ). In fact, simplifying
ˆ
q =(
sin φ
sin 2φ
(s ×t), cos φ), using the half-angle relations (see page 919) and
the trigonometric identity (Equation B.9) gives [853]
ˆ
q =(q
v
,q
w
)=
1
2(1 + e)
(s × t),
2(1 + e)
2
. (4.53)
Directly generating the quaternion in this fashion (versus normalizing the
cross product s×t) avoids numerical instability when s and t point in nearly
the same direction [853]. Stability problems appear for both methods when
s and t point in opposite directions, as a division by zero occurs. When
this special case is detected, any axis of rotation perpendicular to s can be
used to rotate to t.
Sometimes we need the matrix representation of a rotation from s to
t. After some algebraic and trigonometric simplification of Equation 4.43,
12
Shoemake [1176] gives another derivation.
i
i
i
i
i
i
i
i
80 4. Transforms
the rotation matrix becomes [893]
R(s, t)=
e + hv
2
x
hv
x
v
y
v
z
hv
x
v
z
+ v
y
0
hv
x
v
y
+ v
z
e + hv
2
y
hv
y
v
z
v
x
0
hv
x
v
z
v
y
hv
y
v
z
+ v
x
e + hv
2
z
0
0001
. (4.54)
In this equation, we have used the following intermediate calculations:
v = s × t,
e =cos(2φ)=s · t,
h =
1 cos(2φ)
sin
2
(2φ)
=
1 e
v ·v
=
1
1+e
.
(4.55)
As can be seen, all square roots and trigonometric functions have disap-
peared due to the simplifications, and so this is an efficient way to create
the matrix.
Note that care must be taken when s and t are parallel or near parallel,
because then ||s ×t|| 0. If φ 0, then we can return the identity matrix.
However, if 2φ π, then we can rotate π radians around any axis. This
axis can be found as the cross product between s and any other vector that
is not parallel to s (see Section 4.2.4). oller and Hughes use Householder
matrices to handle this special case in a different way [893].
E
XAMPLE:POSITIONING AND ORIENTING A CAMERA. Assume that the de-
fault position for a virtual camera (or viewpoint) is (0 0 0)
T
and the
default view direction v is along the negative z-axis, i.e., v =(0 0 1)
T
.
Now, the goal is to create a transform that moves the camera to a new posi-
tion p, looking in a new direction w. Start by orienting the camera, which
can be done by rotating the default view direction into the destination view
direction. R(v, w) takes care of this. The positioning is simply done by
translating to p, which yields the resulting transform X = T(p)R(v, w).
In practice, after the first rotation another vector-vector rotation will most
likely be desired to rotate the view’s up direction to some desired orienta-
tion.
4.4 Vertex Blending
Imagine that an arm of a digital character is animated using two parts, a
forearm and an upper arm, as shown to the left in Figure 4.10. This model
could be animated using rigid-body transforms (Section 4.1.6). However,
then the joint between these two parts will not resemble a real elbow. This
i
i
i
i
i
i
i
i
4.4. Vertex Blending 81
Figure 4.10. An arm consisting of a forearm and an upper arm is animated using rigid-
body transforms of two separate objects to the left. The elbow does not appear realistic.
To the right, vertex blending is used on one single object. The next-to-rightmost arm
illustrates what happens when a simple skin directly joins the two parts to cover the
elbow. The rightmost arm illustrates what happens when vertex blending is used, and
some vertices are blended with different weights: (2/3, 1/3) means that the vertex weighs
the transform from the upper arm by 2/3 and from the forearm by 1/3. This figure also
shows a drawback of vertex blending in the rightmost illustration. Here, folding in the
inner part of the elbow is visible. Better results can be achieved with more bones, and
with more carefully selected weights.
is because two separate objects are used, and therefore, the joint consists
of overlapping parts from these two separate objects. Clearly, it would be
better to use just one single object. However, static model parts do not
address the problem of making the joint flexible.
Vertex blending is one possible solution to this problem [770, 1376].
This technique has several other names, such as skinning, enveloping,and
skeleton-subspace deformation. While the exact origin of the algorithm
presented here is unclear, defining bones and having skin react to changes
is an old concept in computer animation [807]. In its simplest form, the
forearm and the upper arm are animated separately as before, but at the
joint, the two parts are connected through an elastic “skin.” So, this elastic
part will have one set of vertices that are transformed by the forearm matrix
and another set that are transformed by the matrix of the upper arm. This
results in triangles whose vertices may be transformed by different matrices,
in contrast to using a single matrix per triangle. See Figure 4.10. This basic
technique is sometimes called stitching [1376].
By taking this one step further, one can allow a single vertex to be trans-
formed by several different matrices, with the resulting locations weighted
and blended together. This is done by having a skeleton of bones for the
animated object, where each bone’s transform may influence each vertex
by a user-defined weight. Since the entire arm may be “elastic,” i.e., all
vertices may be affected by more than one matrix, the entire mesh is often
called a skin (over the bones). See Figure 4.11. Many commercial model-
i
i
i
i
i
i
i
i
82 4. Transforms
Figure 4.11. A real example of vertex blending. The top left image shows the two bones
of an arm, in an extended position. On the top right, the mesh is shown, with color
denoting which bone owns each vertex. Bottom: the shaded mesh of the arm in a slightly
different position. (Images courtesy of Jeff Lander [717].)
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset