Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

ryoder

Anyone using linear frame interpolation?

This topic is 6922 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am writing a basic 3d engine which uses keyframed animation and linear interpolation between the keyframes. Just like QuakeII and Unreal Tournament. Here is how I am storing my objects. Each object has an array of meshes which have indices into the objects 1 vertex buffer of triangles. For a walking man there would be a mesh for the lower arm, one for the hand, one for the lower leg, one for the torso etc so that there are about 15 meshes for the total man. Use a low polygon count modeler to define the meshes and their position and rotation in model space per frame. Then the tx matrix that defines their position is saved per frame per mesh. Along with a frame start and end time. The object has a method called setAnimation(int animIndex) which sets the current animation. Say a walking animation has 6 frames and loops from frame 0 to 5. When the setAnimation is called the current time is recorded and the anim clock ticks. Each time render is called the object has to determine based on the current time, which frame is to be displayed. It gets the approximate frame to be displayed and the offset between that frame and the next and pulls those two tx matrices out and interpolates between them linearally based on the distance between the frames in time. I am working on this now. It still isn''t working due to some bugs but let me know what you think. This is a little different than the old fashioned way of doing it. Like having a frameMove and deciding based on state and currentAnimation which frame is the current frame and then having the render method just render that frame. The effect is smoothe animation based on a finite set of keyframes. MCSE, MCSD, Sun Certified Java Programmer Pimp Daddy ;)

Share this post


Link to post
Share on other sites
Advertisement
umm... I didn't know that quake2 used ANY interpolation.

Edited by - nes8bit on May 10, 2000 4:23:39 PM

Share this post


Link to post
Share on other sites
I don''t know to much about matrix math yet and I was just wondering, does interpolating between two rotation matrices linearly produce a smooth circle? And if it does why waste the computing time to convert them to a quaternion and use a spline based interpolation? Like I''ve been doing

Share this post


Link to post
Share on other sites
MD2 files contain 192 frames, each being a list of vertex coordinates. The whole MD2 character is made of ONE mesh, that is an indexed list of vertices. During a model animation, the index list never changes, just the target vertices that may be interpolated between key frames.

A few animations do not require such interpolsation because they have enough frames (that do not move much) to look smooth. But few other animations have only 3 frames, and are supposed to last at least a second, and look VERY ugly without linear interpolation...

To interpolate two vertices (I don''t know what you''re attempting with your matrices) just write:

interpolated_point = point_frame_end * dt + point_frame_start * ( 1.0f - dt );
(where dt is the time ''location'' between the two frames, dt>=0.0f, dt<1.0f)

This method is time consuming (about 400 vertices to interpolate) but you can apply a few optimizations knowing the MD2 animations are designed to be played at 15 fps (an engine running at 400 fps doesn''t need interpolating each frame...).

Share this post


Link to post
Share on other sites
I could hit each corresponding vertex in say frame 5 and 6 and interpolate based on the delta.
But the way I am doing it works this way and should be faster. I think I was calling an object segment a mesh.

For each object I have:
1 vertex buffer with all the triangles and normals textures
for all the segments of the object.
An array of segments, each having an array of indices into the vertex buffer
Then I have an array of frames.

class 3DObject
{
D3DVERTEXBUFFER7 vertexBuffer;
AnimationFrame *frames; // array of numframes

}

struct AnimationFrame
{
WORD startTime;
WORD length;
// this matrix defines the tx and rot of the segment
D3DMATRIX txAndRotMatrices[NUM_SEGMENTS];

}

When its time to render I determine the current frame based on the start time of the object''s animation and the current time. Timing is kept constant.


Then I find the delta between this frame as a float.

Then I loop through each segment and interpolate between the current segment''s current frame and next frame''s translation matrix given the delta.

With the interpolated matrix I make a call to device->setTransform with the interpolated matrix concatenated with the object''s world translation matrix.

Then I call DrawIndexedPrimitiveVB with the current segment''s list of indices into the vertex buffer and the loop continues.

I have this working with a few simple cubes stored in an object. I want to use this technique because hardware tnl is used if available. I don''t really want to take segments defined relative to the origin in model space, then offset each and every vertex and then pass that model in to be drawn with yet another translation into world space.

The only problem that I get right now is that the boxes are compressing a little bit while moving through an arc animation where interpolation happens over a 45 degree span.

But I think its floating point loss.

MCSE, MCSD, Sun Certified Java Programmer
Pimp Daddy ;)

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!