Recommended Posts

I'm currently working on a small online Game.
Till now I animated my playermodel (a little mech) by dividing the model into parts, like legs and body, then for walk animation i just rotated the legs by some angle.
This looks funny, but can't be the solution ;)
What is the proper solution to do this? The possible animations should be a bit more complex than just a very poor walk anim.
Should i do a model for each animation frame, and then just switch between them?
Or do some keyframes, and then calculate ingame the movement between 2 keyframes?
Or some complete other solution?

0

Share this post

Link to post

Share on other sites

Theres 2 ways of doing animations. One is with vertex/frame animation and the other is skeletal animation.

The vertex (frame) animation is when you create an animation by setting the vertex position throughout the animation and interpolate between one frame and the next one. A good format to look at would be MD2/3 file format. It's simple to understand and create the animations.

The other way is with skeletal animations. I'm currently reading about bone animations and how to set them up and all that so I might not be 100% right on some things. Basically what you have there is a mesh for the model, and each vertex of the mesh has connections to certain bones and the weights. During the animation, you recalculate the vertex's position based on what bones its connected to and the weights. For the skeleton animation, you have to specify the bones position and its orientation. Its more complex but gives a nicer animation.

If you are just starting out with animations, you should look at MD2/3 first. Thats what I started out with and it was quite simple.

0

Share this post

Link to post

Share on other sites

Original post by Rainer KI'm currently working on a small online Game.Till now I animated my playermodel (a little mech) by dividing the model into parts, like legs and body, then for walk animation i just rotated the legs by some angle.This looks funny, but can't be the solution ;)

You're actually not that far from a skeletal animation solution.

Quote:

What is the proper solution to do this? The possible animations should be a bit more complex than just a very poor walk anim.

Should i do a model for each animation frame, and then just switch between them?Or do some keyframes, and then calculate ingame the movement between 2 keyframes?Or some complete other solution?

This is another solution. It's easier to implement than skeletal animation, but that doesn't mean it's better - most notably, it means that the artist has to define the position of every single vertex for every single keyframe, and that's a lot of work.

The base principle for skeletal is quite simple. A skeletal is made of bones, which are in fact points to which a vector is attached. This vector gives a direction for the bone. Now, each vertex of the model is attached to one bone (or more - but that's a more advanced technique called "character skinning". Let's keep things simple). In addition, more bones can be attached to a bone, in order to create a hierarchy - the skeleton.

When you rotate or move a bone, the same transformation is applied to everything that is attached to this bone. Most of the time, this transformation is stored in a matrix (a 3x3 matrix), although some implementation might use quaternions (i.e. rotation over a directed axis; math is a bit more complicated, but it's also more efficient if you have a lot of bones).

Let's take a simple example (bones are named Bn, vertices are named Vm, and transformations are named Tp - n, m, p are integers).

Let's imagine we have two bones B1 and B2. To B1 we attach vertices V1 to V4 as well as the bone B2. To B2 we attach vertices V5 to V8.

The animation states that on the first frame, transformation T1 is applied to B1 and T2 is applied to B2.

It means that in order to play this frame, you shall apply T1 to B2 and V1..8, using B1 as the originator for this transformation. Then T2 is applied to V5..8 using the new B2 as the originator.

The good thing is that if you use only rotations (that happen quite often - most animation are only made of rotations) then you can reduce your work a bit: applying T1 then T2 to V5..8 is strictly equivalent to applying T2.T1. So you can optimize the algorithm to apply one one transformation per vertex by concatenating the transformations that have an influence on this vertex (i.e. the transformations of the parent bones).

Now, you still have a problem - how do you interpolate between frames? Unfortunately, the math is not so simple - you can't just interpolate your matrices linearly, as they represent rotations (and sin/cos don't grow very linearly). What you have to do is a spherical interpolation, a type of interpolation that follow the curvature of a sphere.

Note that quats and matrices are equivalent - in fact, in order to apply a quaternion transformation to a vertex, you need to convert it to a matrice. There's an historic article here (written by Diana Gruber) that compare both.