My object (the sun) needs to rotate constantly without a special event (user input, or others…). The object needs to circle the world every S seconds.
The object rotates on plane i[/i] and with radius of R.
I’ve no idea how to accomplish this. Any help would be highly appreciated!
Edit: I’m using Windows, and glut.
Edit: I thought of using glutIdleFunc to register a function that counts the seconds and every second rotate the object by some angle. Does any one have a better idea?
Solved it. I used glutTimerFunc function.
First, I called it in the main function
glutTimerFunc(25, timer, 0);
and then used timer function to update the angle and redraw the scene:
void timer(int value)
sun_angle = (sun_angle + 18) % 360;
glutTimerFunc(500, timer, 0);
This is one way, but doesn’t work so well when you don’t know what rate you redraws will be gated at. For instance, your redraws might be gated at 60Hz or 120Hz if you’re driving an LCD, 70Hz, 80Hz, 120Hz, etc. if you’re driving a CRT, random amounts of time if you’re breaking frame (overrunning your redraw budget) or free-running (running without sync-to-vblank).
A better solution is to use the system realtime clock to determine how much time has elapsed, and instigate events based on that.
That said, your timer update rate is pretty darn slow (0.5 sec) so you probably don’t care one way or the other. When your update rate is more on the order of your frame rate though, you’ll want a different approach.