具有固定时间步长和插值渲染的游戏循环口吃

我从Gaffer Fix your timestep得到了以下游戏循环:

double t = 0.0;
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;
    currentTime = newTime;

    accumulator += frameTime;

    while ( accumulator >= dt )
    {
        previousState = currentState;
        integrate( currentState,t,dt ); // integration
        t += dt;
        accumulator -= dt;
    }

    const double alpha = accumulator / dt;

    State state = currentState * alpha + 
    previousState * ( 1.0 - alpha );

    render( state );
}

我的问题是,随着时间的推移,累加器将足够大,可以在一帧中模拟2个物理步骤,这将迫​​使渲染器在前一个上下文和当前上下文之间产生很大的跳跃。知道如何解决这个问题吗?

yourthing 回答:具有固定时间步长和插值渲染的游戏循环口吃

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/2953380.html

大家都在问