如何将计时函数从线性转换为三次 Bézier?
我有一个动画序列,显示一个又一个特定的帧。最初的规格是:
- 我们将为您提供动画的总持续时间
- 将每个连续帧显示的时间减少 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论