Jump to content
  • Advertisement

Archived

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

fallingbrickwork

timer movements & GLUT_ELAPSED_TIME

This topic is 5273 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''? 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 this post


Link to post
Share on other sites
Advertisement
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);

...

}


Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!