summaryrefslogtreecommitdiff
path: root/core/math
diff options
context:
space:
mode:
Diffstat (limited to 'core/math')
-rw-r--r--core/math/math_funcs.h10
-rw-r--r--core/math/matrix3.cpp17
2 files changed, 12 insertions, 15 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; }
diff --git a/core/math/matrix3.cpp b/core/math/matrix3.cpp
index f2f6ff93cf..ec82bd30d4 100644
--- a/core/math/matrix3.cpp
+++ b/core/math/matrix3.cpp
@@ -365,14 +365,10 @@ Vector3 Basis::get_euler_xyz() const {
if (euler.y < Math_PI * 0.5) {
if (euler.y > -Math_PI * 0.5) {
//if rotation is Y-only, return a proper -pi,pi range like in x or z for the same case.
- if (elements[1][0] == 0.0 && elements[0][1] == 0.0 && elements[0][0] < 0.0) {
+ if (elements[1][0] == 0.0 && elements[0][1] == 0.0 && elements[1][2] == 0 && elements[2][1] == 0 && elements[1][1] == 1) {
euler.x = 0;
+ euler.y = atan2(elements[0][2], elements[0][0]);
euler.z = 0;
-
- if (euler.y > 0.0)
- euler.y = Math_PI - euler.y;
- else
- euler.y = -(Math_PI + euler.y);
} else {
euler.x = Math::atan2(-elements[1][2], elements[2][2]);
euler.z = Math::atan2(-elements[0][1], elements[0][0]);
@@ -436,15 +432,10 @@ Vector3 Basis::get_euler_yxz() const {
if (m12 < 1) {
if (m12 > -1) {
- if (elements[1][0] == 0 && elements[0][1] == 0 && elements[2][2] < 0) { // use pure x rotation
- real_t x = asin(-m12);
+ if (elements[1][0] == 0 && elements[0][1] == 0 && elements[0][2] == 0 && elements[2][0] == 0 && elements[0][0] == 1) { // use pure x rotation
+ euler.x = atan2(-m12, elements[1][1]);
euler.y = 0;
euler.z = 0;
-
- if (x > 0.0)
- euler.x = Math_PI - x;
- else
- euler.x = -(Math_PI + x);
} else {
euler.x = asin(-m12);
euler.y = atan2(elements[0][2], elements[2][2]);