summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2017-08-22 00:31:46 +0200
committerGitHub <noreply@github.com>2017-08-22 00:31:46 +0200
commit135027a2f6271c4144feac117ae933c3c293fae3 (patch)
tree49834939877c5a93a9885321e7e9dbb2795f023e /core
parent9dd8d734826384ac123692f672a2c6e9a2b16377 (diff)
parentd28da86f9ff5a70284e4a2078fa08867d4858a57 (diff)
Merge pull request #10225 from Noshyaar/map
GDScript Built-in: add inverse_lerp & range_lerp
Diffstat (limited to 'core')
-rw-r--r--core/math/math_funcs.h10
1 files changed, 8 insertions, 2 deletions
diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h
index 45509a0808..2ce9a88622 100644
--- a/core/math/math_funcs.h
+++ b/core/math/math_funcs.h
@@ -153,8 +153,14 @@ public:
static _ALWAYS_INLINE_ double rad2deg(double p_y) { return p_y * 180.0 / Math_PI; }
static _ALWAYS_INLINE_ float rad2deg(float p_y) { return p_y * 180.0 / Math_PI; }
- static _ALWAYS_INLINE_ double lerp(double a, double b, double c) { return a + (b - a) * c; }
- static _ALWAYS_INLINE_ float lerp(float a, float b, float c) { return a + (b - a) * c; }
+ 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 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); }
+
+ static _ALWAYS_INLINE_ double range_lerp(double p_value, double p_istart, double p_istop, double p_ostart, double p_ostop) { return Math::lerp(p_ostart, p_ostop, Math::inverse_lerp(p_istart, p_istop, p_value)); }
+ static _ALWAYS_INLINE_ float range_lerp(float p_value, float p_istart, float p_istop, float p_ostart, float p_ostop) { return Math::lerp(p_ostart, p_ostop, Math::inverse_lerp(p_istart, p_istop, p_value)); }
static _ALWAYS_INLINE_ double linear2db(double p_linear) { return Math::log(p_linear) * 8.6858896380650365530225783783321; }
static _ALWAYS_INLINE_ float linear2db(float p_linear) { return Math::log(p_linear) * 8.6858896380650365530225783783321; }