• ### What is your GameDev Story?

#### Archived

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.

## 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''? Or...am 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 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);....RenderScene(){time = glutGet(GLUT_ELAPSED_TIME);timediff=time - timeprec;timeprec=time;....angle += 360*(timediff/5000);...}

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 10
• 11
• 13
• 9
• 11
• ### Forum Statistics

• Total Topics
634088
• Total Posts
3015453
×