summaryrefslogtreecommitdiff
path: root/core/math/math_funcs.h
diff options
context:
space:
mode:
authorChaosus <chaosus89@gmail.com>2019-07-14 07:30:45 +0300
committerChaosus <chaosus89@gmail.com>2019-07-20 12:59:41 +0300
commit6694c119d069d8ff8dc5290d38d2d33625f07807 (patch)
tree085f1fd73f885c29d417993d1c1a8ff0a3380bd9 /core/math/math_funcs.h
parentc317a3ce16a35b21d85b250a0e810526bb89db38 (diff)
Added lerp_angles built-in function
Co-authored-by: Xrayez <https://github.com/Xrayez> Co-authored-by: DleanJeans <https://github.com/DleanJeans>
Diffstat (limited to 'core/math/math_funcs.h')
-rw-r--r--core/math/math_funcs.h11
1 files changed, 11 insertions, 0 deletions
diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h
index b6398712e4..b8b5151802 100644
--- a/core/math/math_funcs.h
+++ b/core/math/math_funcs.h
@@ -215,6 +215,17 @@ public:
static _ALWAYS_INLINE_ double lerp(double p_from, double p_to, double p_weight) { return p_from + (p_to - p_from) * p_weight; }
static _ALWAYS_INLINE_ float lerp(float p_from, float p_to, float p_weight) { return p_from + (p_to - p_from) * p_weight; }
+ 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;
+ return p_from + distance * p_weight;
+ }
+ static _ALWAYS_INLINE_ float lerp_angle(float p_from, float p_to, float p_weight) {
+ float difference = fmod(p_to - p_from, (float)Math_TAU);
+ float distance = fmod(2.0f * difference, (float)Math_TAU) - difference;
+ return p_from + distance * p_weight;
+ }
+
static _ALWAYS_INLINE_ double inverse_lerp(double p_from, double p_to, double p_value) { return (p_value - p_from) / (p_to - p_from); }
static _ALWAYS_INLINE_ float inverse_lerp(float p_from, float p_to, float p_value) { return (p_value - p_from) / (p_to - p_from); }