From 99ce0df3b1fedf2c83e90664bd426e71440f923c Mon Sep 17 00:00:00 2001 From: Hendrik Brucker Date: Mon, 27 Jun 2022 19:41:32 +0200 Subject: Refactor bezier interpolation functions --- editor/animation_bezier_editor.cpp | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) (limited to 'editor/animation_bezier_editor.cpp') 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); -- cgit v1.2.3