Jump to content
  • Advertisement
Sign in to follow this  
Endar

md2 animation speed

This topic is 4881 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

_goat: Just about done actually [grin]

Okay, I read about half of that and because it's 1:30am here, my brain started melting. My code has changed a bit since I last posted in this thread, such as: I got the timer working properly so I can run more than one at a time. I have time-based updating for my scene graph so I can restrict the engine fps to whatever I like.

Just quickly, two things before I go to bed and sleep so I can get up, read and understand this and finish the md2 code completely:

1. At the moment, I don't have simple access to the time since the world started. What my timer does is return the number of seconds (float) since the last time it was called. So, each frame that I render, I send the time since the last render to every object in the scene graph so they can update themselves.

2. Ummm, have I found a discrepancy here, or do I just not understand this bit?
Quote:

begin and end are in reference to which frames to begin and end on, and fps is obviously how many frames to process per second.

...

This, in MD2 files, is easier to do because all frames have the same fps,


What am I not understanding that makes these two statements both correct?

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
1. worldtime: simply add each deltatime to a stored variable
2. an anim-sequence has a frames per second info and each frame in this anim-seq has the same timeduration to the next one, so you can calc the duration of a frame (1.0f / fps) only once for the anim-seq and not seperate for each frame

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
@RobTheBloke

no, I meant what I wrote

because we count model_time against MD2AnimaionList[m_animState].fps to advance m_currentFrame to the next frame in the animation

but we should also do a loop instead the if, because of too long delta_times we would slow down, but with the loop we have the correct frame at the current time:


float model_time = 0;

void tick_md2( float delta_time ) // time since last frame
{
model_time += delta_time;
while ( model_time >= 1.0f / MD2AnimationList[m_animState].fps )
{
++m_currentFrame;

if ( m_currentFrame > MD2AnimationList[m_animState].end )
m_currentFrame = MD2AnimationList[m_animState].begin;

model_time -= 1.0f / MD2AnimationList[m_animState].fps;
}

updateInterpolation( model_time / ( 1.0f / MD2AnimationList[m_animState].fps ) );

}


Share this post


Link to post
Share on other sites
Endar: It's possible some other file formats will have animations where all the frames that consist of that animation do not have the same length. I.e., the first frame might go for 100 ticks, and the second frame might go for 250 ticks. Since I implemented my keyframe logic independantly from filetypes, I had to take this into account. It's easier in MD2 because calculating some of the required values can just be decomposed into a multiplication or two.

(Note: If the frames in the animation don't all have the same length, then there won't be a "fps" value for that animation, because it just wouldn't be possible.)

Share this post


Link to post
Share on other sites
Quote:

I do - I have this code basically in a loop.


_goat: Could I have a look at this code? I found that I had pretty much everything except the stuff for keeping track of the total time of the animation in case of lag. That's what I'm having a little bit of trouble with.

You use ticks, and I'm just using seconds (float) and I've got something like this:

void update(float delta_time)
{
// http://www.gamedev.net/community/forums/viewreply.asp?ID=2381044

m_modelTime += delta_time;
m_animTime += delta_time; // add time
if( m_modelTime >= 1.0f / MD2AnimationList[m_animState].fps )
m_modelTime = 0.0f;


while( m_animTime >
( (m_currentFrame - MD2AnimationList[m_animState].begin + 1)
* 1000 / MD2AnimationList[m_animState].fps) ){
// advance to next frame
if (m_currentFrame >= m_endFrame){
m_currentFrame = m_startFrame; // wrap around to the start
m_animTime = 0.0f; // end of the animation, so animTime = 0.0f
}

m_nextFrame = m_currentFrame + 1; // assign the next frame to interpolate to

if (m_nextFrame >= m_endFrame || m_nextFrame >= m_numFrames)
m_nextFrame = m_startFrame; // wrap around to the start
}


updateInterpolation( m_modelTime / ( 1.0f / MD2AnimationList[m_animState].fps ) );
}


Where m_animTime is the total time for the animation, and m_modelTime is the time since the last frame.

Share this post


Link to post
Share on other sites
Well, yes, you may.

I'm using frame descriptors, but they're basically the same thing. They have: The index, the time (in ticks) into the animation they should have started, and their length (in ticks). So { 0, 0, 111 }, { 1, 111, 111 }, { 2, 222, 111 } would be the first three for an MD2 file.

You should probably note that for 30 seconds of lag, and this animation takes about 4 seconds, this loop would go over many times (quickly, mind), and in fact loop through the entire animation about 7 times.


//=====================================================================
// get the correct frames
//=====================================================================
// whilst the time relative to the start of the animtion is greater than
// the time the frame should have ended by...
while (animation_time > frame_desc.begin() + frame_desc.length())
{
// if we're the last frame in the animation...
if (frame_desc.index() >= animation->mFrameEnd)
{
// set us to the front of the animation
mCurrentFrame = animation->mFrameBegin;
// get our new frame descriptor
frame_desc = mSharedModelData->keyframeDescriptors()[mCurrentFrame];
// the animation just started again, add the total time of the
// animation to the time we began. This allows for _extreme_ lag,
// meaning if we paused for 30 seconds, we'll still update at the
// correct point afterwards.
mTimeAnimationBegan += animation->mTotalTime;
// the following is equal to:
// "animation_time = world_time - mTimeAnimationBegan".
// which recalculates the animation time
animation_time -= animation->mTotalTime;
}
// if we're NOT the last frame in the animation
else
{
// then just get the next frame descriptor
frame_desc = mSharedModelData->keyframeDescriptors()[++mCurrentFrame];
}
}

Share this post


Link to post
Share on other sites
Okay, let me just clear one thing up.

Quote:

If the animation time is more than that, then we should move to the next frame, and probably check again. I do - I have this code basically in a loop. That means that if we experience (oh god) 30 seconds of lag, then when we resume normal operation, we'll be at the right spot. This involves more complex stuff, like subracting the total animation time to the animation_start_time once we hit the end of the animation, where our animation time is still greater than the total length of our animation. I'll go over that if I need to.


So, if we do experience 30 seconds of lag, then the animation should be advanced by 30 seconds, right?

Share this post


Link to post
Share on other sites
Okay, well, since this thread was supposed to be about the speed that the model was animating at: linky.

This is the compiled exe and the model and texture. It's set to run at 50fps, so if you run it, could you let me know if the model is actually animating at the right speed for everything? It just cycles through frames 0-197.

Share this post


Link to post
Share on other sites
Quote:
Original post by Endar
Okay, let me just clear one thing up.

Quote:

If the animation time is more than that, then we should move to the next frame, and probably check again. I do - I have this code basically in a loop. That means that if we experience (oh god) 30 seconds of lag, then when we resume normal operation, we'll be at the right spot. This involves more complex stuff, like subracting the total animation time to the animation_start_time once we hit the end of the animation, where our animation time is still greater than the total length of our animation. I'll go over that if I need to.


So, if we do experience 30 seconds of lag, then the animation should be advanced by 30 seconds, right?


Um, basically. The loop would loop over and over again until it had "caught up". Keeping in mind the speed of the looping over and over again is negligable.

EDIT: I ran your program.

I think it's a little fast. Mine could be a little slow, but I'm 99% sure that my code is correct. Also, at the end, your program can't release the rendering context for OGL. Everything else looks spiffy though.

[Edited by - _goat on December 7, 2005 5:40:47 AM]

Share this post


Link to post
Share on other sites
Hey, you're a melbourne guy too? [smile]

Okay, looks like I have to work on that.... it seems that recently I've just been struck with an inability to write proper code.

Hopefully it won't continue too long!

Oh, did you check out the exe? Too fast, too slow? If you don't want the exe, I could paste the source code, but, 3700 lines is getting a little much to paste onto gamedev.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!