Original Post
Hello, I am writing some simple physics for my game. I have read this article about how/why to fix your timestep. But, I'm a little confused about the end, in the section "The Final Touch." The author is demonstrating how to interpolate between two physics states. Here's the source snippet from the article in question: If I understand the code correctly, when the author interpolates between the two physics states, he is getting a state that actually isn't what the state should be. Shouldn't he be calculating the "current" physics state and the next physics state after it so that he can interpolate ahead of the "current" physics state to the actual physics state. Instead, it appears he is going back before the "current" physics state to the previous physics state. Please, shed some light on this. Slaru
float t = 0.0f;
const float dt = 0.01f;
float currentTime = 0.0f;
float accumulator = 0.0f;
State previous;
State current;
while (!quit)
{
float newTime = time();
float deltaTime = newTime - currentTime;
currentTime = newTime;
accumulator += deltaTime;
while (accumulator>=dt)
{
previousState = currentState;
integrate(currentState, t, dt);
t += dt;
accumulator -= dt;
}
const float alpha = accumulator / dt;
State state = currentState*alpha + previousState*(1.0f-alpha);
render(state);
}