I'm trying to figure out if I'm approaching my simple fixed-timestep implementation correctly, following examples such as: Gaffer (without RK4), and DeWitters
Currently, I have a game object which contains position and velocity data members, with position calculated by
position = position + (velocity * dt)
However, unless the velocity is set to a value of two decimal places, the update makes the position change in an instant (e.g. Velocity = 0.05 works, but this does not seem logical; to me Velocity should be >0?; even a value of 0.5 makes the update appear instant). Therefore, I have come to the conclusion that I have implemented by game loop incorrectly.
Note, I'm using SDL and C++, however the following is all Psuedocode:
bool quit = false;
World world;
Uint32 frameTime = SDL_GetTicks();
double accumulator = 0.0;
const double dt = 1.0 / 60.0;
int fCount = 0;
while(!quit){
fCount = 0;
double newTime = SDL_GetTicks();
double nextFrameTime = newTime - frameTime;
if(nextFrameTime > 0.25)
nextFrameTime = 0.25;
frameTime = nextFrameTime; //Line of error, should be frameTime = newTime
accumulator += nextFrameTime;
while(accumulator >= dt){
world.Update(dt); //A simple counter revealed Update being called 15-16 times during this loop
accumulator -= dt;
fCount++;
}
//fCount is equal to 15 when dt = 1.0/ 60.0, fCount = 8/9 when dt = 1.0/30.0
double interpol = accumulator / dt;
world.Render(interpol);
}
If there isn't any apparent issue with this code then perhaps I have messed up my position/physics calculations based on Update(dt).
Any help is appreciated