如何将计时函数从线性转换为三次 Bézier?

发布于 2024-12-10 22:52:36 字数 867 浏览 0 评论 0原文

我有一个动画序列,显示一个又一个特定的帧。最初的规格是:

  • 我们将为您提供动画的总持续时间
  • 将每个连续帧显示的时间减少 20ms

所以我写了这个线性计时函数:

/**
 * Get the delay until the next animation frame.
 *
 * @returns the number of ms until the next animation frame.
 */
getNextTiming: function () {
    var n = this.getLength(), // total number of frames
        t = this.animationDuration,
        x = this.durationDelta, // 20 ms, according to spec
        d = ((n * n * x) - (n * x) + (2 * t)) / (2 * n),
        c = this.cursor; // current frame
    // d is the duration of the first frame of animation.
    return d - c * x;
},

当然,艺术家不高兴。他们希望动画遵循曲线。当然,他们不知道到底是什么曲线,所以我需要写一些可以在数字上进行调整的东西,直到他们满意为止。在我看来,我应该看看三次贝塞尔函数,但我能找到的函数要么具有我发现难以解析的抽象符号,要么被定义为 p(t),而不是 Δt/Δp。

我曾经擅长数学,但现在我陷入了困境。我可以朝正确的方向用力推。如何重写上述函数,以便可以向其提供三次贝塞尔曲线控制点 P1 和 P2 并获得每个连续帧的时间作为输出?

I have an animation sequence that shows one specific frame after another. The original specifications were:

  • We will give you a total duration for the animation
  • Reduce the time each consecutive frame is shown by 20ms

So I wrote this linear timing function:

/**
 * Get the delay until the next animation frame.
 *
 * @returns the number of ms until the next animation frame.
 */
getNextTiming: function () {
    var n = this.getLength(), // total number of frames
        t = this.animationDuration,
        x = this.durationDelta, // 20 ms, according to spec
        d = ((n * n * x) - (n * x) + (2 * t)) / (2 * n),
        c = this.cursor; // current frame
    // d is the duration of the first frame of animation.
    return d - c * x;
},

Naturally, the artists aren't happy. They want the animation to follow a curve. Of course, they don't know exactly what curve, so I need to write something I can tweak numerically until they're happy. It seems to me I should be looking at cubic Bézier functions, but the ones that I can find either have abstract notation that I'm finding difficult to parse, or they're defined as p(t), instead of Δt/Δp.

I used to be good at math, but right now I'm stuck. I could use a shove in the right direction. How can I rewrite the above function so that I can feed it cubic Bézier control points P1 and P2 and get as output the time for each consecutive frame?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文