0% found this document useful (0 votes)
3 views

col0498

The document discusses the implementation of real-time character animation using quaternion interpolation for a first-person fighting game. It covers the creation of a custom interface that allows players to design unique attack moves by manipulating an arm with three bones, and the importance of using Spherical Linear Interpolation (SLERP) for smooth transitions between keyframes. Additionally, it addresses challenges in achieving seamless character animations and introduces the concept of skinning over a bone hierarchy to enhance realism.

Uploaded by

rkrams1989
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

col0498

The document discusses the implementation of real-time character animation using quaternion interpolation for a first-person fighting game. It covers the creation of a custom interface that allows players to design unique attack moves by manipulating an arm with three bones, and the importance of using Spherical Linear Interpolation (SLERP) for smooth transitions between keyframes. Additionally, it addresses challenges in achieving seamless character animations and introduces the concept of skinning over a bone hierarchy to enhance realism.

Uploaded by

rkrams1989
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

by Jeff Lander GRAPHIC CONTENT

Slashing Through Real-Time


Character Animation
ast time we left off, you were hanging out on a bridge in quaternion

L space. Quaternion space is like the space between the handout desk and
the deal room at any booth of any publisher at E3. It’s a concept you can
grasp, but it’s really tough to visualize being there.
As you’ll recall, I finished up with an
OpenGL application that converts Euler
angle data to quaternions and then dis-
Clearly, the problem revolves around
the interpolation of the arm positions.
hypersphere. If I were simply to inter-
polate between the two keyframes in a
straight line, I would be cutting across
13

plays the results. Now I want to extend the arc of that sphere (Figure 1a). As
this application to allow for the inter- Interpolation you can see, in-betweens that are even-
polation of two keyframed positions. It ly spaced on the hypersphere create
struck me that I should create a custom s I discussed last month, one of nonlinear positions on the LERP-line.
3D first-person interface that effectively
demonstrates interpolation.
A the key benefits of using a quater-
nion representation is the ability to
Alternately, the effect of evenly spacing
out in-betweens along the LERP-line
interpolate between keyframes. Nick would create an animation that would
Bobick, in his article in the February appear to move faster as it traveled
The Task 1998 issue of Game Developer, discussed across the middle of the interpolation
interpolation of quaternions (“Rotating (Figure 1b). This may not always be a
s the project technical lead, I am Objects Using Quaternions,” pp.38-39). bad thing, so it’s quite easy to adjust
A asked to create an interface for a
first-person fighting game. However,
Bobick described the use of Spherical
Linear Interpolation (SLERP) to achieve
between LERP and SLERP.
The code in Listing 1 gives me the
the design calls for allowing the player smooth interpolation. For very small basis for creating my 3D interface. By
to create custom attacks in some sort of interpolation, he mentioned that it’s a applying these routines to a three-
pregame editor. The player does this by good idea to use simple Linear bone hierarchy, I get a smooth attack
manipulating an arm consisting of an Interpolation (LERP). Being the hard- from any two keyframed positions. To
upper arm, a lower arm, and a hand core game programmers that you are, implement this in OpenGL, I only
with a weapon. The player positions you may ask, “Why not use LERPs all needed to modify my display routine a
this arm into two poses. One pose is the time and avoid the expensive math little bit. The critical section is in
the beginning of the attack move and that SLERPs require?” The reason is that Listing 2, and you can see the results
the other pose is the end of the attack unit length quaternions describe a 4D in Figures 2a-c.
move. During the game, this custom
action is triggered and creates a smooth
attack. The player’s effective use of this
interface determines the effectiveness
of the move. Several of these moves are
then combined to create a unique
fighting experience.
Alright, so it’s not revolutionary, but
it’s a well-defined task with a pretty
clear path of attack. As technical lead, I
like that. So how do I get started?

When not bending the bones of some


strange alien creature, Jeff can be found
hanging out at his studio at the beach. F I G U R E 1 a . Spherical Linear
See if you can smack some sense into Interpolation (SLERP) between F I G U R E 1 b . Linear Interpolation
him by writing to [email protected]. quaternions. (LERP) between quaternions.

http://www.gdmag.com APRIL 1998 G A M E D E V E L O P E R


GRAPHIC CONTENT

wear armor or tank top shirts. objects create. In a 3D graphics pack-


Let’s Recap If the character was created from age such as Softimage, Alias, or 3D
et me take a moment to recap what one single mesh, we wouldn’t have Studio MAX, I could create a mesh and
L I’ve covered in my past two
columns. I started by taking motion
any of the problems that separate animate it with the software’s skeletal

capture data and applying it to a skeletal


system. I then created a method for con-
L I S T I N G 1 . Interpolation of Two Quaternions.
verting Euler angles to quaternions.
///////////////////////////////////////////////////////////////////////////////
Then, by using quaternion interpola-
// Function: SlerpQuat
tion, I created smooth in-betweens for
// Purpose: Spherical Linear Interpolation Between two Quaternions
the skeletal system. Lastly, to make
// Arguments: Two Quaternions, blend factor, result quaternion
things look a bit more interesting, I
// Source: Watt and Watt, Advanced Animation, p. 364
attached 3D objects to individual bones.
// NOTE: This fixes a bug in their code
One remaining problem is that the
///////////////////////////////////////////////////////////////////////////////
arm is created from three separate
void SlerpQuat(tQuaternion *quat1,tQuaternion *quat2,float slerp, tQuaternion *result)
objects — and it shows. The points at
{
which the different objects are con-
/// Local Variables ///////////////////////////////////////////////////////////
nected look a little rough. This prob-
tQuaternion quat1b;
lem has been plaguing real-time 3D
double omega,cosom,sinom,scale0,scale1;
14 graphics for some time now. In fact,
///////////////////////////////////////////////////////////////////////////////
many successful games live with this
// USE THE DOT PRODUCT TO GET THE COSINE OF THE ANGLE BETWEEN THE QUATERNIONS
and get quite good results (VIRTUA
cosom = quat1->x * quat2->x +
FIGHTER, TOMB RAIDER, and JEDI KNIGHT
quat1->y * quat2->y +
come to mind). However, to combat
quat1->z * quat2->z +
this problem, many artists design their
quat1->w * quat2->w;
characters to disguise the fact that the
bones are composed of separate
// MAKE SURE WE ARE TRAVELING ALONG THE SHORTER PATH
objects. This is done through clever
if ((1.0 + cosom) > DELTA)
texturing or modeling, and explains
{
why so many real-time 3D characters
// IF THE ANGLE IS NOT TOO SMALL, USE A SLERP
if ((1.0 - cosom) > DELTA) {
omega = acos(cosom);
sinom = sin(omega);
scale0 = sin((1.0 - slerp) * omega) / sinom;
scale1 = sin(slerp * omega) / sinom;
} else {
// FOR SMALL ANGLES, USE A LERP
scale0 = 1.0 - slerp;
scale1 = slerp;
}
result->x = scale0 * quat1->x + scale1 * quat2->x;
result->y = scale0 * quat1->y + scale1 * quat2->y;
result->z = scale0 * quat1->z + scale1 * quat2->z;
result->w = scale0 * quat1->w + scale1 * quat2->w;
} else {
// SINCE WE FOUND THE LONG WAY AROUND, USE THE SHORTER ROUTE
result->x = -quat2->y;
result->y = quat2->x;
result->z = -quat2->w;
result->w = quat2->z;
scale0 = sin((1.0 - slerp) * (float)HALF_PI);
scale1 = sin(slerp * (float)HALF_PI);
// MULT BY THE SCALE
result->x = scale0 * quat1->x + scale1 * result->x;
result->y = scale0 * quat1->y + scale1 * result->y;
result->z = scale0 * quat1->z + scale1 * result->z;
result->w = scale0 * quat1->w + scale1 * result->w;
}
F I G U R E S 2 a - c . Keyframe #1, 50 per- }
cent interpolation, and keyframe #2. // SlerpQuat /////////////////////////////////////////////////////////////////

G A M E D E V E L O P E R APRIL 1998 http://www.gdmag.com


GRAPHIC CONTENT

L I S T I N G 2 . Applying quaternion rotation in OpenGL. to keyframe two positions for a three-


bone arm and interpolate smoothly
// CONVERT THE TWO KEYFRAME ROTATIONS TO QUATERNIONS between them. ■
EulerToQuaternion(&curBone->p_rot,&primaryQuat);
REFERENCES
EulerToQuaternion(&curBone->s_rot,&secondaryQuat);
// INTERPOLATE BETWEEN THEM BY A BLEND FACTOR 0.0 - 1.0 For my quaternion SLERP code, I have
SlerpQuat(&primaryQuat,&secondaryQuat,m_AnimBlend,&curBone->quat); used Advanced Animation and
// QUATERNION HAS TO BE CONVERTED TO AN AXIS/ANGLE REPRESENTATION Rendering Techniques,(ACM Press,
QuatToAxisAngle(&curBone->quat,&axisAngle); 1992) by Watt and Watt as a starting
// DO THE ROTATION point. This is a very good book that cov-
glRotatef(axisAngle.w, axisAngle.x, axisAngle.y, axisAngle.z); ers many topics not touched by any
other text. However, as I’ve tried differ-
ent concepts in the book, I have found a
deformation system. This would create This means that for each vertex in the few errors. The code sample on interpo-
very seamless characters that could be model, you assign a certain percentage lating quaternions is a case in point.
animated very quickly by a game of its influence to each bone. While When negating an input quaternion to
engine. In fact, this method has been many vertices may be assigned 100 per- find the shortest arc, they negate the
used by QUAKE (and its genetic off- cent to an individual bone, some may wrong one. The source that accompa-
spring) quite successfully. be assigned 50/50 between two bones. nies this article corrects that error.
16 However, by predeforming the charac- By blending the influence of different Problems such as these are a good rea-
ters to animate them, I lose the key ben- bones, you can achieve a very smooth son to study the underlying concepts
efit of real-time 3D — flexibility. By skin. In some extreme cases, you may and follow sources for any new tech-
sticking to a hierarchy of bones, I’m able even need to weight a vertex between nique. This can save you a great deal of
to apply unique motion capture data, three or more bones, but in general, frustration when things do not work out
interpolate between keyframes, and two is sufficient. as they should.
incorporate many things that I haven’t Figure 4 shows how a fully weighted
talked about, such as real-time inverse mesh could be applied to the same two-
kinematics, dynamics, and motion bone system. Because of the
blending. So how do I achieve the key calculations needed to han-
benefits of a skeleton without having the dle the weighting, this sys-
ugly seams that come with it? tem is a bit more processor
intensive then basic skin-
ning. However, for a main
Skin Them Bones character or opponent, the
smooth results and flexibility
he answer is to stretch a single skin are worth the increased
T over the bones in the skeleton.
While this is a fairly advanced feature in
processor load.
The remaining question is,
most 3D modeling packages, the tech- How do I implement a fully
nique behind it is really quite easy. As a weighted mesh applied to a
good starting point, let’s consider associ- hierarchical skeleton in an
ating each vertex in the skin mesh with immediate mode API such as F I G U R E 3 . Two bones weighted 100 percent to
an individual bone. The influence of OpenGL? Well, that’s going each vertex.
that bone directly effects its associated to be the topic for next time.
vertex . Thus, when you rotate a bone, it However, some of you may be
rotates the associated vertices about the itching to get started. Since I
root position of that bone. You can see have now covered all of the
the effect of this process in Figure 3. In main pieces, for your home-
this image, two bones define the hierar- work, see if you can figure
chy, and each bone has eight vertices out an efficient way to calcu-
associated with it. While this technique late those vertex positions,
creates a seamless, deformable mesh and I will work it out next
with very little processor overhead, it month. Try to wrap your
has one drawback. At the point where brain around the underlying
the two bones meet, the skin is stretched concept, and then we’ll work
a bit. While this may be fine for many out the details together next
applications, with extreme motion, this month.
stretch is very unrealistic. The sample application for
The solution to this problem is to this month (on the Game F I G U R E 4 . Two bones weighted to each vertex
add a few more vertices to the model Developer website at 100-66/33-50/50-33/66-100.
and “weight” the individual vertices. www.gdmag.com) allows you

G A M E D E V E L O P E R APRIL 1998 http://www.gdmag.com

You might also like