PDA

View Full Version : Time based movement problem



Balta66
03-29-2015, 03:04 PM
Hi,

I'm currently working on a school project in OpenGL 2.X and I'm trying to make a cube rotate based on time and not on FPS so I did this :


int main(void)
{
Input input;
Uint32 lastTime = SDL_GetTicks();
Uint32 currentTime, ellapsedTime, frames, time;

SDL_Init(SDL_INIT_VIDEO);
SDL_WM_SetCaption("Nibble", NULL);
SDL_SetVideoMode(640, 480, 32, SDL_OPENGL);
glMatrixMode(GL_PROJECTION);
glLoadIdentity( );
gluPerspective(70,(double)640/480,1,1000);
glEnable(GL_DEPTH_TEST);
frames = 0;
time = 0;
while (!input.getEvent(SDLK_ESCAPE) && !input.quit())
{
input.updateEvents();

currentTime = SDL_GetTicks();
ellapsedTime = currentTime - lastTime;
time += ellapsedTime;
lastTime = currentTime;

angleZ += (0.01 * ellapsedTime);
angleX += (0.01 * ellapsedTime);

drawCube();
++frames;
if (time >= 1000)
{
std::cout << "Frames = " << frames << std::endl;
time = 0;
frames = 0;
}
}
SDL_Quit();
return (0);
}


But the animation is not fluid at all (jerky). If someone could tell me what is wrong.

Thank You.