Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 4 of 4

Thread: changing position of an object continuously

  1. #1
    Newbie Newbie
    Join Date
    Oct 2013
    Posts
    3

    changing position of an object continuously

    I have a circle in the center of the screen and i want to continuously change its X position. I made a function

    Code :
    void move()
    {
      while(1)
       posX+=0.001;
    }

    And i was trying to call it from main(); but the program freezes.. If i call it without the while(1) loop then the call is made to the function once. But i want it to be called continuously.. How to do that??
    Last edited by david419; 10-20-2013 at 11:50 AM.

  2. #2
    Advanced Member Frequent Contributor
    Join Date
    Apr 2010
    Posts
    716
    Just doing a loop that updates the objects position is not enough: in order to see the object move you also need to draw a new frame with the object at it's new position. So you basically want the following to happen continuously: update position, redraw frame, update position, redraw frame, ...
    If you are using GLUT you should update the object's position at the beginning of your display function (before drawing) and additionally register an idle function (with glutIdleFunction) that simply calls glutPostRedisplay (this tells glut that something in the application has changed and you want to draw a new frame to show the updated state).

  3. #3
    Newbie Newbie
    Join Date
    Oct 2013
    Posts
    3
    Thanks for the reply.... But i am a noob at this.. If you could provide a sample code that does this job.. I can understand much better..

  4. #4
    Newbie Newbie
    Join Date
    Oct 2013
    Posts
    3
    Hey... I got it .. Fiddled around a little and your process worked Thanks.....

Posting Permissions

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