Advertisement Jump to content


This topic is now archived and is closed to further replies.


timer movements & GLUT_ELAPSED_TIME

This topic is 5368 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi Guys, I''m a total beginner, so stick with me.... I''m trying to set up a rotation using a timer instead of just increasing an angle etc...(BTW, I''m using GLUT) My render code is a simple: ..... glRotatef(rot, 0.0f, 1.0f, 0.0f); Cube code etc. ..... I''ve created a update function: ..... int Time; time = glutGet(GLUT_ELAPSED_TIME); ..... Firstly, can i use GLUT_ELAPSED_TIME to set up timed movements/rotations? If so, how do I use my variable ''time'' to alter ''rot''? I just barking up the wrong tree with the above code and is there a better way to do it....(note, i am a beginner) Any help would be greatly received...

Share this post

Link to post
Share on other sites
In fact is is pretty simple:

store the old time in timePrec, then each time you ask your Rendering function do

time = glutGet(GLUT_ELAPSED_TIME);

and then timediff=time - timeprec;

then you have the time elapsed in milliseocnds during the rendering of the two frames.

You have now to know the speed of the rotation of your angle.
For example we will take one complete rotation per 5 seconds

angle += 360*(timediff/5000)

Try this one it should work
And don''t forget to initialize timeprec during the main()
(timeprec = glutGet(GLUT_ELAPSED_TIME) just before calling the GlutMainLoop();

timeprec = glutGet(GLUT_ELAPSED_TIME);

time = glutGet(GLUT_ELAPSED_TIME);
timediff=time - timeprec;


angle += 360*(timediff/5000);



Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!