Jumpy rotation animation?

Started by
1 comment, last by C0lumbo 11 years, 5 months ago
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.

BSc Computer Games Programming (De Montfort University) Graduate

Worked on Angry Birds Go! at Exient Ltd

Co-founder of Stormburst Studios

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

This topic is closed to new replies.

Advertisement