animation rate

I’m drawing several things onscreen, and want them to have different animation rate. Right now I just have
glutTimerFunc(30, controlAnimate, 1);
and in controlAnimate, I call the animation method of each thing I’m drawing. As a result, everything is moving in the same rhythm, which is kinda lame. How can I change this?
Thanks!

Stan,

Just don’t call all the animation methods all the time in the controlAnimate method. Keep track of the relative speeds of each object and only call its animation method every nth call to controlAnimate.

HTH

Jean-Marc

Here is a simple example:
note that the for loop, could be replaced by if statments.

controlAnimate()
{
int x;

for(x=0; x < Total_objects; x++)// Number of objects to process.
{
if (my_object.rate_state < 0) // When rate_state reachs zero, it is time to update object.
{
Update_object( x ); // Which objects data is to be updated
my_object.rate_state = my_object.rate; Reset our objects rate state, to a preset value.
}else my_object.rate_state–; If not time to update decrease rate state
}
glutTimerFunc(30, controlAnimate, 1); Reset our timmer.
}

Originally posted by Stan:
I’m drawing several things onscreen, and want them to have different animation rate. Right now I just have
glutTimerFunc(30, controlAnimate, 1);
and in controlAnimate, I call the animation method of each thing I’m drawing. As a result, everything is moving in the same rhythm, which is kinda lame. How can I change this?
Thanks!

[This message has been edited by nexusone (edited 06-03-2002).]

Great! Thanks a lot, guys!