Hello
I am wondering what sort of equations must be used to calculate
interpolation for a constant movement between different framerates.
I done various tests with SDL_gfx’s framerates function in my algorythm.
Here is my movement loop;
/**************************************************************************/
/*** .. some init stuff ... **/
SDL_initFramerate(p); //from SDL_framerate.h (SDL_gfx lib)
SDL_setFramerate(p, 60); //p is an FPSmanager, set to 60FPS
speed = 10; //set speed for movement
while(loop)
{
while(SDL_PollEvent(&ev))
{
switch(ev.type)
{
case SDL_KEYDOWN:
keystate[ev.key.keysym.sym] = 1;
break;
case SDL_KEYUP:
keystate[ev.key.keysym.sym] = 0;
break;
case SDL_QUIT:
loop=0;
break;
}
}
if(keystate[SDLK_LEFT])
angle-=5.0;
if(keystate[SDLK_RIGHT])
angle+=5.0;
//degrees_to_radiant(double) : converts the angle to rad //r : a
SDL_Rect struct
r.x += speed * cos(degrees_to_radiant(angle));
r.y += speed * sin(degrees_to_radiant(angle));
SDL_FillRect(screen,NULL,SDL_MapRGB(screen->format,0,0,0));
SDL_BlitSurface(obj, NULL, screen, &r);
SDL_Flip(screen);
SDL_framerateDelay(p); //delay for framerate
}
/**********************************************************************************/
From here all is simple, I display the animation at 60FPS
I did some tests between various FPS values to see variations. From
25FPS, movement seems like constant.
40px at 4FPS
60px at 5FPS
…
110px at 10FPS
120px at 11FPS
…
220px at 22FPS
240px at 23FPS
250px at 24FPS
260px at 25FPS
So we can see this doesn’t run same amount of pixels according with fps
My question is : How can a run the same amount of pixels in the same
amount of time, being FPS independant ?
cya