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

model animation

Started by Fluid FX Aug 3, 2002 at 9:10 AM 0 replies 500+ views
Original Post
Fluid FX
Fluid FX
Dear people, on most codes i saw for md2 or md3, they were not time based or anything like it.. so my question is, is this code the best? or .. int FramePerSecondA = 25; int FrameTick = 1/FramePerSecondA; int TStart, TEnd, TCounter; render() { start = timeGetTime(); TCounter += TEnd-TStart; if(TCounter => FrameTick){ UpdateModelFrames(); TCounter = TCounter - FrameTick; } render + models; end = timeGetTime(); } DrawModels() { here will be said that for example next frame should be drawn like : drawmodel(modelid,frame); } something like it .... Greetz sorry the code was at bit stupid [edited by - Fluid FX on August 3, 2002 10:19:16 AM]
JuNC
JuNC
Sure that works, however you should probably store the times as floats or doubles (1/25 < 1).

This is how I was doing it (note the frames & frame times were per-model-instance):


  
float framePeriod = 1 / framesPerSecond;
float currentTime = framePeriod; // do this in code really

int currentFrame = 0;

void MainLoop(void)
{
float end = timeGetTime();

while(1)
{
float start = timeGetTime();

Update(end - start);

end = start;
}

}

void Update(float deltaTime)
{
currentTime -= deltaTime;

if(currentTime <= 0.0)
{
currentTime += framePeriod;
currentFrame++;
// handle frame sequence wrapping etc. here

}


}

void RenderModel(void)
{
md2->DrawFrame(currentFrame);
}


[edited by - JuNC on August 4, 2002 10:05:46 AM]

Topic Locked

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

Sign in to reply to this topic.