PDA

View Full Version : Rendering correctly according to time

hulapupp
04-05-2005, 02:57 AM
OK, here is the case:

I am currently using the OpenInventor libraries for C++, and i want to draw a scene where something happens, e.g. a person walking.

I know that it takes 1 second for a person to take a step forward, because i have coordinate files that tell me the exact position of the limbs at which times. The coordinates are stored on a fileformat which i read into C++ and convert into translations on the person, using the Inventor libraries.

THe problem is the following; i do not want the scene to be rendered too fast. it is important that when i render, it takes exactly one second for the person to take that step.

I want the highest framerate possible at all times in the animation. How do i find out how many fps i can get at a particular state of the scene? Given ofc. the resolution an color depth of the scene to be rendered.

God, this is confusing. I'm not even sure that i understood what i just wrote here :p Some help or hints to how i can do this would be greatly appreciated;)

- hulapupp

sqrt[-1]
04-05-2005, 03:14 AM
The standard way most games and apps do this is to use the time delta from the previous frame. (some use the average of the last x frames) This is usually clamped to prevent huge time deltas. (framerate spikes can occur depending on what you are doing)

knackered
04-05-2005, 04:48 AM
An interpolation from the previous time delta usually works well.
Simple example:

static DWORD nowPrevious = GetTickCount();
static DWORD smoothDelta = 0;

#ifndef LIRP
#define LIRP(X,Y,A) ((1.0f-(A))*(float)(X)) + ((A)*(float)(Y))
#endif

DWORD now = GetTickCount();
DWORD nowDelta = now - nowPrevious;
nowPrevious = now;

if (smoothDelta)
smoothDelta = LIRP(smoothDelta, nowDelta, 0.2f);
else
smoothDelta = nowDelta;smoothDelta now has a smoothed value for the number of milliseconds since the last time the code was executed.
Convert smoothDelta to seconds:-
float secs = float(smoothDelta)/1000.0f;

There are better timer functions than GetTickCount, such as QueryPerformanceCounter....but they involve a bit more work.