View Full Version : changing position of an object continuously

10-20-2013, 11:34 AM
I have a circle in the center of the screen and i want to continuously change its X position. I made a function

void move()

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??

carsten neumann
10-20-2013, 12:20 PM
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).

10-20-2013, 09:36 PM
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..

10-21-2013, 05:53 AM
Hey... I got it .. Fiddled around a little and your process worked :) Thanks.....