PDA

View Full Version : animation rate



Stan
06-03-2002, 12:04 AM
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!

JML
06-03-2002, 12:53 AM
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

nexusone
06-03-2002, 08:01 AM
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[x].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[x].rate_state = my_object[x].rate; Reset our objects rate state, to a preset value.
}else my_object[x].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).]

Stan
06-03-2002, 10:05 AM
Great! Thanks a lot, guys!