diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2022-11-24 10:51:07 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2022-11-24 10:51:07 +0100 |
commit | f16c5b564b569497d04deb965a4fd63b3ea2ab2f (patch) | |
tree | 1a32664ee30ef467cc4d9f12ee0dc3ff3ceeb6cf /core/math/math_funcs.h | |
parent | f319123af9bac7279edcaa1c17e8f84a615c5aa2 (diff) | |
parent | f9fa182abc5209671cb4fbadc2dc173157d6f939 (diff) | |
download | redot-engine-f16c5b564b569497d04deb965a4fd63b3ea2ab2f.tar.gz |
Merge pull request #69043 from xiongyaohua/path3d_bake_refactor_fix
`Curve3D` bake refactor continue
Diffstat (limited to 'core/math/math_funcs.h')
-rw-r--r-- | core/math/math_funcs.h | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h index 0af529ad98..8dff8e6e7e 100644 --- a/core/math/math_funcs.h +++ b/core/math/math_funcs.h @@ -364,6 +364,26 @@ public: return p_start * omt3 + p_control_1 * omt2 * p_t * 3.0f + p_control_2 * omt * t2 * 3.0f + p_end * t3; } + static _ALWAYS_INLINE_ double bezier_derivative(double p_start, double p_control_1, double p_control_2, double p_end, double p_t) { + /* Formula from Wikipedia article on Bezier curves. */ + double omt = (1.0 - p_t); + double omt2 = omt * omt; + double t2 = p_t * p_t; + + double d = (p_control_1 - p_start) * 3.0 * omt2 + (p_control_2 - p_control_1) * 6.0 * omt * p_t + (p_end - p_control_2) * 3.0 * t2; + return d; + } + + static _ALWAYS_INLINE_ float bezier_derivative(float p_start, float p_control_1, float p_control_2, float p_end, float p_t) { + /* Formula from Wikipedia article on Bezier curves. */ + float omt = (1.0f - p_t); + float omt2 = omt * omt; + float t2 = p_t * p_t; + + float d = (p_control_1 - p_start) * 3.0f * omt2 + (p_control_2 - p_control_1) * 6.0f * omt * p_t + (p_end - p_control_2) * 3.0f * t2; + return d; + } + static _ALWAYS_INLINE_ double lerp_angle(double p_from, double p_to, double p_weight) { double difference = fmod(p_to - p_from, Math_TAU); double distance = fmod(2.0 * difference, Math_TAU) - difference; |