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 /scene/resources/animation.cpp | |
parent | c79aad0257fc0ce92248f1525cd4a8d19e761d62 (diff) | |
parent | 99ce0df3b1fedf2c83e90664bd426e71440f923c (diff) |
Merge pull request #62458 from Geometror/interpolation-function-cleanup
Refactor Bezier interpolation functions
Diffstat (limited to 'scene/resources/animation.cpp')
-rw-r--r-- | scene/resources/animation.cpp | 17 |
1 files changed, 3 insertions, 14 deletions
diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp index 8ae4872d14..7183accc66 100644 --- a/scene/resources/animation.cpp +++ b/scene/resources/animation.cpp @@ -3379,17 +3379,6 @@ Vector2 Animation::bezier_track_get_key_out_handle(int p_track, int p_index) con return bt->values[p_index].value.out_handle; } -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; -} - real_t Animation::bezier_track_interpolate(int p_track, double p_time) const { //this uses a different interpolation scheme ERR_FAIL_INDEX_V(p_track, tracks.size(), 0); @@ -3438,7 +3427,7 @@ real_t Animation::bezier_track_interpolate(int p_track, double p_time) const { for (int i = 0; i < iterations; i++) { real_t middle = (low + high) / 2; - Vector2 interp = _bezier_interp(middle, start, start_out, end_in, end); + Vector2 interp = start.bezier_interpolate(start_out, end_in, end, middle); if (interp.x < t) { low = middle; @@ -3448,8 +3437,8 @@ real_t Animation::bezier_track_interpolate(int p_track, double p_time) const { } //interpolate the result: - Vector2 low_pos = _bezier_interp(low, start, start_out, end_in, end); - Vector2 high_pos = _bezier_interp(high, start, start_out, end_in, end); + Vector2 low_pos = start.bezier_interpolate(start_out, end_in, end, low); + Vector2 high_pos = start.bezier_interpolate(start_out, end_in, end, high); real_t c = (t - low_pos.x) / (high_pos.x - low_pos.x); return low_pos.lerp(high_pos, c).y; |