Created
September 23, 2011 09:26
-
-
Save epreston/9ce98e3748841c2024cb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
double t = 0.0; | |
const double dt = 0.01; | |
double currentTime = hires_time_in_seconds(); | |
double accumulator = 0.0; | |
State previous; | |
State current; | |
while ( !quit ) | |
{ | |
double newTime = time(); | |
double frameTime = newTime - currentTime; | |
if ( frameTime > 0.25 ) | |
frameTime = 0.25; // note: max frame time to avoid spiral of death | |
currentTime = newTime; | |
accumulator += frameTime; | |
while ( accumulator >= dt ) | |
{ | |
previousState = currentState; | |
integrate( currentState, t, dt ); | |
t += dt; | |
accumulator -= dt; | |
} | |
const double alpha = accumulator / dt; | |
State state = currentState*alpha + previousState * ( 1.0 - alpha ); | |
render( state ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment