Jump to content
  • Advertisement
Sign in to follow this  
Dezachu

OpenGL Jumpy rotation animation?

This topic is 2078 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

Hey guys, bit of a noob with OpenGL (Only just started utilising it on my course!). C++.

Got this:

[source lang="cpp"]if((float)Clock.GetElapsedTime()>REFRESH_RATE){
// Clear colour and depth buffer
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

// reset the ModelView Transform matrix
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();


// Apply some transformations
glTranslatef(0.f, 0.f, -100.f);

//glRotatef(15.f,1.f,0.f,0.f);
glRotatef(i,0.f,1.f,0.f);
glRotatef(i-15,0.f,0.f,1.f);
glRotatef(i+15,1.f,0.f,0.f);

// ********************** //
drawCylinder(20,20,40);
// ********************** //

i++;

Clock.Reset();
}[/source]

The drawCylinder uses to TRIANGLE_FAN objects and then QUAD_STRIP's, all created via a for loop. The parameters passed in are radius, numberOfSides and height.

i++ is a float declared at the beginning of the program: float i = 30; (I know it should be called f for float, but more confusion to be made there that I was better off avoiding).


When I run the program, the animation is very jumpy as it rotates. Any clues as to why? Cheers :)


EDIT: Dropping the framrate from 0.03 to 0.01 has improved it somewhat. Still, I'd imagine the animation would be more stuttery than jumpy. The animation basically flashed back to the previous frame every so often, looked a bit daft. Edited by Dezachu

Share this post


Link to post
Share on other sites
Advertisement
If you remove the following line does it run smooth? :
[source lang="java"]if((float)Clock.GetElapsedTime()>REFRESH_RATE)[/source]
If so then it might be a problem with your clock rather than a problem with opengGL. Edited by Jaroy

Share this post


Link to post
Share on other sites
I agree, when your if((float)Clock.GetElapsedTime()>REFRESH_RATE) test fails, then you're doing a frame without even a glClear, so the frame buffer displayed is full of arbitrary junk. Usually the arbitrary junk it's full of is frame n-2 or frame n-3 (where the current frame is frame n), hence you're seeing your animation jump backwards.

I suggest that only i++; and Clock.Reset(); should be inside your if statement.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!