【问题标题】:Closing towards a point, independent of the frame rate?接近一个点,与帧速率无关?
【发布时间】:2014-09-03 07:34:31
【问题描述】:

我正在制作一个 3D 相机类,它靠近一个点,放慢速度并逐渐停止。定期执行此操作非常简单:

// positions are vectors, dampening is a scalar, usually set to ~0.9

currentPosition += (targetPosition - currentPosition) * dampening;

但是,如果每帧只执行一次,这将锁定到帧速率。

如何最好地实现这种依赖于时间而不是帧速率或执行时间的行为?

【问题讨论】:

    标签: math 3d language-agnostic logic


    【解决方案1】:

    一个简短的实验(如果您需要一些归纳)表明,在 n 帧之后,您处于

    targetPosition*(1 - (1 - dampening)^n) + currentPosition*(1 - dampening)^n
    

    为了让这个时间依赖,写

    targetPosition*(1 - pow(1 - dampening, t)) + currentPosition*pow(1 - dampening, t)
    

    现在阻尼是每单位时间,时间甚至可能是分数。

    你的问题让我想起了Calculate speed by distance and friction

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-12
      • 1970-01-01
      • 2015-12-25
      • 1970-01-01
      相关资源
      最近更新 更多