PDA

View Full Version : Animation Event Loop



nexusone
01-17-2002, 06:59 AM
I want to create a event loop to update once a second the position of a Animated object.
How would I do that under glut?

Example:
glutTimeEvent(timeEvent)

void timeEvent()
{
.move object
.check for valid location
.redraw screen
}

Thug
01-17-2002, 08:44 AM
nex,

I am not sure of the type of the program you are programming but you can use the following code if and only if you are animating one object and one object only.




glutTimeEvent(timeEvent)

void timeEvent()
{
.move object
.check for valid location
.redraw screen
delay(1000) // delay thread for 1 second.
timeEvent();
}

nexusone
01-17-2002, 09:28 AM
I had a couple of things that I wanted to do, like spinning cubes, game object timming.
Also I thought that using a time based loop for Animating things, so that CPU speed would not effect the animation.



Originally posted by Thug:
nex,

I am not sure of the type of the program you are programming but you can use the following code if and only if you are animating one object and one object only.




glutTimeEvent(timeEvent)

void timeEvent()
{
.move object
.check for valid location
.redraw screen
delay(1000) // delay thread for 1 second.
timeEvent();
}

nexusone
01-17-2002, 11:59 AM
After looking I have come up with the glutTimerFunc( time in ms, func(Value), value)

But get an error trying to use it..

Example:
glutTimerFunc( 1000, TimerEvent, 1);

void TimerEvent()
{
do stuff
}