diff options
Diffstat (limited to 'tools/mq_editor/utils.js')
| -rw-r--r-- | tools/mq_editor/utils.js | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/tools/mq_editor/utils.js b/tools/mq_editor/utils.js index c38b1f5..96d807c 100644 --- a/tools/mq_editor/utils.js +++ b/tools/mq_editor/utils.js @@ -13,6 +13,19 @@ function evalBezier(curve, t) { u*u*u * curve.v3; } +// Evaluate amplitude component of unified bezier curve at time t +function evalBezierAmp(curve, t) { + const dt = curve.t3 - curve.t0; + if (dt <= 0) return curve.a0; + let u = (t - curve.t0) / dt; + u = Math.max(0, Math.min(1, u)); + const u1 = 1.0 - u; + return u1*u1*u1 * curve.a0 + + 3*u1*u1*u * curve.a1 + + 3*u1*u*u * curve.a2 + + u*u*u * curve.a3; +} + // Get canvas-relative {x, y} from a mouse event function getCanvasCoords(e, canvas) { const rect = canvas.getBoundingClientRect(); |
