Results 1 to 3 of 3

Thread: Make object circle a world every Y seconds

  1. #1
    Junior Member Newbie
    Join Date
    Apr 2014
    Posts
    9

    Question 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. #2
    Junior Member Newbie
    Join Date
    Apr 2014
    Posts
    9
    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. #3
    Senior Member OpenGL Guru
    Join Date
    Oct 2004
    Posts
    4,654
    Quote Originally Posted by xorserq View Post
    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.

Similar Threads

  1. Make sphere move in a circle
    By uberweiss in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 04-21-2010, 12:07 AM
  2. I want to make a circle
    By in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 07-16-2002, 06:31 AM
  3. Easy way to make a circle?
    By in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 09-12-2001, 05:40 PM
  4. How do you make a Circle?
    By CanEHdien in forum OpenGL: Basic Coding
    Replies: 2
    Last Post: 09-08-2001, 08:36 PM
  5. how to make a nurb circle or cylinder?
    By in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 05-24-2000, 09:34 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean