I've been recently attempting to create a simple example game using both sfml and box2d. To get simple framework together, I wanted to implement a fixed timestep and I've pretty much based the fixed timestep code off this
http://www.unagames.com/blog/daniele/2010/06/fixed-time-step-implementation-box2d . At the moment its simple demo with a square box that you can move with wasd keys. The problem is that when ever I attempt to move the square, I get this odd blur on the square (almost like its stretching) whilst moving. I've tried a few things from this forum and even attempting to just set the frame rate to 60, but it doesn't seem to change any thing.
Below is my fixed timestep:
void B2DWorld::update(float dt, ActionController<std::string>& actionController){
m_fixedTimestepAccumulator += dt;
const int steps = floor(m_fixedTimestepAccumulator / FIXED_TIMESTEP);
if (steps > 0)
{
m_fixedTimestepAccumulator -= steps * FIXED_TIMESTEP;
}
assertAccumilation();
m_fixedTimestepAccumulatorRatio = m_fixedTimestepAccumulator / FIXED_TIMESTEP;
const int clampedSteps = std::min(steps, MAX_STEPS);
for (int i = 0; i < clampedSteps; ++ i)
{
resetStates();
actionController.triggerCallbacks(m_fixedTimestepAccumulatorRatio);
step(FIXED_TIMESTEP);
}
interpolateStates();
m_world.DrawDebugData();
}
void B2DWorld::step(float dt){
m_world.Step(dt, VELOCITY_ITERATIONS, POSITION_ITERATIONS);
}
void B2DWorld::interpolateStates(){
const float oneMinusRatio = 1.0f - m_fixedTimestepAccumulatorRatio;
for (b2Body * b = m_world.GetBodyList (); b != NULL; b = b->GetNext ())
{
if (b->GetType () == b2_staticBody)
{
continue;
}
PhysicsComponent *c = (PhysicsComponent*) b->GetUserData();
c->smoothedPosition =
m_fixedTimestepAccumulatorRatio * b->GetPosition () +
oneMinusRatio * c->previousPosition;
c->smoothedAngle =
m_fixedTimestepAccumulatorRatio * b->GetAngle () +
oneMinusRatio * c->previousAngle;
}
}
Here's the full code:
https://github.com/SundeepK/Clone/tree/wip/fix_time_stepAny suggestions on what be causing the issue or other example code/projects that implement fixed timestep with sfml?