Decoupled Physics

I realize this has been asked multiple times before, and I spent most of today reading the forums and the gaffers article trying to figure it out, so forgive me if this is redundant.

I'm attempting to just do a basic decoupling of the physics from the graphics/fps so that the physics engine runs at essentially the same speed no matter how fast the game loop. This is what I have:

Code:
    const float dt = 0.015f;
    time_t currentTime = time(NULL);
    float accumulator = 0.0f;

   while(device->run()) {

        if (receiver.IsKeyDown(irr::KEY_ESCAPE))
            break;

        if (receiver.IsKeyDown(irr::KEY_SPACE) && totalboxes == 0) {
            worldObj box("box.x", 0.0f, 12.0f, 100.0f, 1.0f, 0.2f, 0.7f);
            boxes.push_back(box);
            totalboxes++;
        }

        time_t newTime = time(NULL);
        time_t deltaTime = difftime(newTime, currentTime);
        currentTime = newTime;

        accumulator += deltaTime;

        while (accumulator>=dt) {
              world->Step(dt, 8, 1);
              accumulator -= dt;
         }
    }


It works, sort of. The simulation seems to run at the same speed independent of the frame rate, but it does so in a very "jumpy" way. In that, a falling box will fall in large steps and not a smooth falling animation.

If anyone is willing to further explain this process, and perhaps show me what is wrong, I would be most grateful.

Thanks.
You're physics step is at 66hz. That means if you are getting a graphical framerate between 33 adn 66, which is likely, your simulation will be either 1 or two physics steps per frame. Which can look jerky. The gaffer article recommends interpolation to fix this, but, if you can handle variable length time steps, I prefer

Code:
accumulator += deltaTime;

        while (accumulator>=dt) {
              world->Step(dt, 8, 1);
              accumulator -= dt;
         }
         world->Step(accumulator, 8, 1);
         accumulator = 0;


Which is essentially making Box2D do the interpolation step for you as an extra physics step.

Original thread: https://box2d.org/forum/viewtopic.php?t=3538