View Full Version : Multiple timer funcs
05-04-2004, 09:20 AM
Can i have multiple timer funcs.
Here is the problem, my main window i have set the timer to 200ms and it works ok, i.e. animates slowly but when using the camera it also waits 200ms between each rotation and zoom.
I'd like to have a way to set the camera timer so it is instant but keep the animation slow.
05-04-2004, 09:50 AM
If I understand correctly you are updating your display 5 times per second. That is not the corect way to do an animation. You should update the display as fast as you can, and use the time difference to update the movement of your objects.
Here is an example: suppose you display a rotating cube and you want the cube to rotate 90/sec.
try something like this:
static bool first = true;
first = false;
double time = (double)(currentTime.QuadPart - startTime.QuadPart) / (double)frequency.QuadPart;
//this rotates the cube with 90 degrees every second
glRotatef(time * 90. , 0., 1., 0.);
draw the cube
That is basically it. This way you can update the display 10000 times per second and still have the cube rotate with only 90 degrees per second. You should adapt this code to your situation, of course...
I hope this helps.
05-04-2004, 09:58 AM
ok, so let me try and understand what you are saying, i should set my animation to not be based on the timerfunc but on actual time, so if i want the object to grow, as that is what it does, to grow every second i should compare the times of now and before and then update the object???
is that roughtly what you are saying???
05-04-2004, 10:12 AM
since you want your object to grow you're performing a scale.
let's say, for example, that you want your cube to double in size every second.
here's what you would want to do:
render as fast as possible but before each render get a tick count since the first render.
tickcount = CurrentTickcount-firstTickCount;
use the passing time to come up with an interpolated value of how much the object scaled.
ex: 250ms since first render = .25sec.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.