View Full Version : How to update a certain value dependent on time, but not on the frame rate?

11-03-2006, 09:54 PM
Hi, I am trying to figure out how to change the update parameter for my animation, so that it is independent of the framerate. Because I noticed the animation going faster if the framerate is going faster if i use this (simplified version, placed in renderscene):

time = glutGet(GLUT_ELAPSED_TIME);
if (time - timebase > speed) {
timebase = time;
}but now the timestep is incremented faster when the frame rate is faster, how can I make that independent of the framerate?

11-04-2006, 12:55 AM
This code is not independent on the frame rate because it forgets any time that goes beyond the value of the speed variable. So if one frame takes 1.5 * speed, the 0.5 * speed will be forgotten in each loop and animation will play slower.

What you need is something like:

time = glutGet(GLUT_ELAPSED_TIME);
while ( ( time - timebase ) > speed ) {
timebase += speed ;
}or matematical equivalent of the loop.

11-04-2006, 01:24 AM
It works! thanks!