diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2022-06-27 23:25:33 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-06-27 23:25:33 +0200 |
commit | 25baa32db068af49cda1d79ea211c9df6c47a547 (patch) | |
tree | b5e3f3da2b343a17e10156fcbb87de1b5ffa6c67 /editor/animation_bezier_editor.cpp | |
parent | c79aad0257fc0ce92248f1525cd4a8d19e761d62 (diff) | |
parent | 99ce0df3b1fedf2c83e90664bd426e71440f923c (diff) |
Merge pull request #62458 from Geometror/interpolation-function-cleanup
Refactor Bezier interpolation functions
Diffstat (limited to 'editor/animation_bezier_editor.cpp')
-rw-r--r-- | editor/animation_bezier_editor.cpp | 17 |
1 files changed, 3 insertions, 14 deletions
diff --git a/editor/animation_bezier_editor.cpp b/editor/animation_bezier_editor.cpp index f0650ee446..391cd009f1 100644 --- a/editor/animation_bezier_editor.cpp +++ b/editor/animation_bezier_editor.cpp @@ -44,17 +44,6 @@ float AnimationBezierTrackEdit::_bezier_h_to_pixel(float p_h) { return h; } -static _FORCE_INLINE_ Vector2 _bezier_interp(real_t t, const Vector2 &start, const Vector2 &control_1, const Vector2 &control_2, const Vector2 &end) { - /* Formula from Wikipedia article on Bezier curves. */ - real_t omt = (1.0 - t); - real_t omt2 = omt * omt; - real_t omt3 = omt2 * omt; - real_t t2 = t * t; - real_t t3 = t2 * t; - - return start * omt3 + control_1 * omt2 * t * 3.0 + control_2 * omt * t2 * 3.0 + end * t3; -} - void AnimationBezierTrackEdit::_draw_track(int p_track, const Color &p_color) { float scale = timeline->get_zoom_scale(); @@ -151,7 +140,7 @@ void AnimationBezierTrackEdit::_draw_track(int p_track, const Color &p_color) { for (int k = 0; k < iterations; k++) { float middle = (low + high) / 2; - Vector2 interp = _bezier_interp(middle, start, out_handle, in_handle, end); + Vector2 interp = start.bezier_interpolate(out_handle, in_handle, end, middle); if (interp.x < t) { low = middle; @@ -161,8 +150,8 @@ void AnimationBezierTrackEdit::_draw_track(int p_track, const Color &p_color) { } //interpolate the result: - Vector2 low_pos = _bezier_interp(low, start, out_handle, in_handle, end); - Vector2 high_pos = _bezier_interp(high, start, out_handle, in_handle, end); + Vector2 low_pos = start.bezier_interpolate(out_handle, in_handle, end, low); + Vector2 high_pos = start.bezier_interpolate(out_handle, in_handle, end, high); float c = (t - low_pos.x) / (high_pos.x - low_pos.x); |