# Thread: Make object circle a world every Y seconds

1. ## Make object circle a world every Y seconds

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 (x,y,z) 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?

2. Solved it. I used glutTimerFunc function.
First, I called it in the main function
Code :
`glutTimerFunc(25, timer, 0);`

and then used timer function to update the angle and redraw the scene:
Code :
```void timer(int value)
{
sun_angle = (sun_angle + 18) % 360;
glutPostRedisplay();
glutTimerFunc(500, timer, 0);
}```

3. Originally Posted by xorserq
Solved it. I used glutTimerFunc function.
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.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•