Skip to main content
GameDev.net gamedev.net
🔒 Locked

How does 3D Model animation work ?

Started by AcidJazz Oct 24, 2002 at 8:39 PM 3 replies 1.9k views
Original Post
AcidJazz
AcidJazz
I''m using opengl, but I figure it''s somewhat the same for both directx and opengl. I read that you use matrix stacks to animate objects, then again I also read that some file formats contain key frame information. I''m not exactly sure what this key frame information is but I know it''s relating to animation. Anybody able/willing to explain this ? Thanks a bunch, AJ
Why is 99% of the Comp Sci population guys, and the other 1% not female? ;/
iNsAn1tY
iNsAn1tY
Er, I kinda know what it is...here goes...

Basically, you have a model. The model has bones, which, when moved, move the polygons connected to them. Say you have an arm, which has two bones, the upper arm and the lower arm, and one joint which connects them, the elbow. In a game, the arm changes from being bent at the elbow to being completely outstretched. What you would do is to save two keyframes: one with information about when the arm is bent, and one with information about when the arm is straight. Then, in the game, you would use linear interpolation to fill in the missing frames of rotation between the arm being bent and being outstretched.

You''d take the position of the lower arm bone (and hence the lower arm polygons) and rotate it (using the matrix math you mentioned) around the elbow joint a little. By a little, I mean this: you move from the first keyframe to the second keyframe based on how much time has elapsed. You calculate how far the arm would have rotated in the time that has passed since the last frame, and then rotate it by that amount.

Say the arm moves 90 degrees around the x axis, from 90 degrees to 180 degrees. The keyframe info might look like this:

Keyframe1: LowerArmBone.Rotation.x = 90;
Keyframe2: LowerArmBone.Rotation.x = 180;

Then, in the code, you''d rotate the lower arm bone from 90 degrees (it''s start position) to 180 degrees (it''s end position) a little every frame. This is linear interpolation. As no other frames except the two keyframes are saved in the model file, this is a very efficent way of creating complex movement without huge model files. Quake III uses this method. In fact, if you head over to www.gametutorials.com, you can find a *.md3 file format animation tutorial. It''s quite hardcore stuff (quaternions and stuff, you''ll need to know your C and math) but it''s excellent.

I hope this made some sense. I''m pulling an all-nighter to reset my body clock (it''s not good when you start waking up at three. In the afternoon.) and get some work done, so I have some time on my hands.


Movie Quote of the Week:

"Mr. Madison, what you have just said is one of the most insanely
idiotic things I have ever heard. At no point in your rambling,
incoherent response were you even close to anything that could
be considered a rational thought. Everyone in this room is now
dumber for having listened to it. I award you no points, and may
God have mercy on your soul."
- The Principal, Billy Madison.
Try http://uk.geocities.com/mentalmantle. Seriously. It''s brilliant.
And I just completely redesigned it so it looks even better.
DarkVertex Beta 0.8 available soon!
My opinion is a recombination and regurgitation of the opinions of those around me. I bring nothing new to the table, and as such, can be safely ignored.[ Useful things - Firefox | GLee | Boost | DevIL ]
Rian
Rian
It can be even easier than that, and usually is. There doesn''t have to be any bones about it.

Using bones, or skeletal animation, requires much more math and is generally a little harder to implement, and assuming you''re a beginner, I wouldn''t recommend fooling with them just yet. Once you get aquanited, though, they are generally more life-like and so can be used in games like Quake III. Basicly, they involve animating imaginary bones in a model during real-time, and having the mesh or polygons around the bones react to them.

The other, simpler (in my opinion) way to animate is to read in a file, ie .md3, that has a list of vertices that are drawn in a mesh of triangles for each keyframe, and then interpolanate between them. Basicly, an .md3 is just a file that contains a header (with info like the skin .bmp) and then a huge array of vertices that is loaded into memory.

Say a specific model has 100 vertices per frame, and 1000 total, both as specified in the header. Then, you would need to draw the first 100, interpolanate to the next 100, and so on everyframe. Once you hit the last vertex, start over. .md3 actually has several different animations stored in each model, including ones for running, walking, jumping, etc.

Interpolanation just means something like "calculating the points between." Do this by multiplying each vertex by a percent. For example:

Assume each keyframe is 1 sec apart. The distance between a vertex in the first keyframe and the same vertex in the second keyframe is calculated first. Then, if 0.1 seconds have past since the first keyframe was rendered, then it would not be time to draw the second keyframe yet. Instead, it would be (1 sec * 0.1 sec) = .1 = 10% of the second keyframe. Get it? So, multiply the distance between the first and second pts by 10% to get the new estimated vertex at that time.

if t = the time since the last keyframe was drawn and a new keyframe is drawn every second, then:

DeltaX = NewX - OldX;
NewX = DeltaX * t

It will never be perfect, because as the equation is linear, the vertices will only move in straight lines between keyframes. But, it works, because it usually happens too quickly for anyone to notice.

The problem with this approach is that you have to have some other software to actually create the models and calculate the vertices for the mesh, which I really have no idea about. For practice, you can experiment with already animated .md3 models downloaded off the internet.

You will have to get info from another source about how to read in .md3 files. Sorry.
I can imagine a world without hate, a world without fear, a world without war. And I can imagine us attacking that world, because they would never expect it. -Jack Handy
Luctus
Luctus
Rian, what you''re talking about is(/could be) the .md2 format. Md2 animations are made by interpolating sequentially stored vertices.

Also, a good and cheap 3d editor/modeler for games is Milkshape 3d by chumbalum soft. It handles a lot of 3d fileformats, including md2, md3, mdl and several other formats used in games.

-Luctus
-LuctusIn the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move - Douglas Adams
iNsAn1tY
iNsAn1tY
Yeah, my bad, I got my wires crossed. You use bones in the modeller (to actually create the keyframes easily), and just polygons in the engine, right? I've been doing a lot of skeletal animation research recently, and I know that the system I described above is used in UT2K3, but not in Quake III, which I based my example on. In Quake III, as you said, the linear interpolation happens only on polygons.

If you want a file on the *.md3 model format, it's actually included with that tutorial over at www.gametutorials.com.

Luctus, we're both referring to the *.md2 and *.md3 files which the Quake engines use. And Milkshape is a decent free modeller, but if you're serious about making models, shell out for 3D Studio Max (used to make all the models in Quake III) or Maya (extremely expensive, but being used for all the models in Doom III). Actually, you can get Maya and 3DS Max for quite reasonable rates on student discount. Just ask about it. All you have to do is give the school/college/university you're at, and £4000 for 3DS Max becomes a more manageable £300...

Actually, I'm gonna go and get Milkshape now. I have to start work on the *.md3 loader for my map editor...


Movie Quote of the Week:

"Mr. Madison, what you have just said is one of the most insanely
idiotic things I have ever heard. At no point in your rambling,
incoherent response were you even close to anything that could
be considered a rational thought. Everyone in this room is now
dumber for having listened to it. I award you no points, and may
God have mercy on your soul."
- The Principal, Billy Madison.
Try http://uk.geocities.com/mentalmantle. Seriously. It's brilliant.
And I just completely redesigned it so it looks even better.
DarkVertex Beta 0.8 available soon!


[edited by - iNsAn1tY on October 25, 2002 6:58:43 PM]
My opinion is a recombination and regurgitation of the opinions of those around me. I bring nothing new to the table, and as such, can be safely ignored.[ Useful things - Firefox | GLee | Boost | DevIL ]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.