Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 );
- }
Advertisement
Add Comment
Please, Sign In to add comment