diff options
Diffstat (limited to 'core/math')
36 files changed, 165 insertions, 455 deletions
diff --git a/core/math/a_star.cpp b/core/math/a_star.cpp index 04e4383f03..21516ac768 100644 --- a/core/math/a_star.cpp +++ b/core/math/a_star.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/core/math/a_star.h b/core/math/a_star.h index ebf1407c17..d2d2166719 100644 --- a/core/math/a_star.h +++ b/core/math/a_star.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/core/math/audio_frame.cpp b/core/math/audio_frame.cpp index 30a50c8add..555d3536df 100644 --- a/core/math/audio_frame.cpp +++ b/core/math/audio_frame.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/core/math/audio_frame.h b/core/math/audio_frame.h index d54f622197..cfc7331767 100644 --- a/core/math/audio_frame.h +++ b/core/math/audio_frame.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/core/math/bsp_tree.cpp b/core/math/bsp_tree.cpp index e22bc2b05e..be950568cf 100644 --- a/core/math/bsp_tree.cpp +++ b/core/math/bsp_tree.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/core/math/bsp_tree.h b/core/math/bsp_tree.h index 8296e57943..2e762ba4de 100644 --- a/core/math/bsp_tree.h +++ b/core/math/bsp_tree.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/core/math/camera_matrix.cpp b/core/math/camera_matrix.cpp index a1666ccd8b..0512cdd798 100644 --- a/core/math/camera_matrix.cpp +++ b/core/math/camera_matrix.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -180,19 +180,7 @@ void CameraMatrix::set_orthogonal(real_t p_size, real_t p_aspect, real_t p_znear } void CameraMatrix::set_frustum(real_t p_left, real_t p_right, real_t p_bottom, real_t p_top, real_t p_near, real_t p_far) { -#if 0 - ///@TODO, give a check to this. I'm not sure if it's working. - set_identity(); - matrix[0][0]=(2*p_near) / (p_right-p_left); - matrix[0][2]=(p_right+p_left) / (p_right-p_left); - matrix[1][1]=(2*p_near) / (p_top-p_bottom); - matrix[1][2]=(p_top+p_bottom) / (p_top-p_bottom); - matrix[2][2]=-(p_far+p_near) / ( p_far-p_near); - matrix[2][3]=-(2*p_far*p_near) / (p_far-p_near); - matrix[3][2]=-1; - matrix[3][3]=0; -#else real_t *te = &matrix[0][0]; real_t x = 2 * p_near / (p_right - p_left); real_t y = 2 * p_near / (p_top - p_bottom); @@ -218,8 +206,6 @@ void CameraMatrix::set_frustum(real_t p_left, real_t p_right, real_t p_bottom, r te[13] = 0; te[14] = d; te[15] = 0; - -#endif } real_t CameraMatrix::get_z_far() const { diff --git a/core/math/camera_matrix.h b/core/math/camera_matrix.h index 4be8ffab8c..175d0cdb1b 100644 --- a/core/math/camera_matrix.h +++ b/core/math/camera_matrix.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/core/math/face3.cpp b/core/math/face3.cpp index 0e292500bf..748faad28f 100644 --- a/core/math/face3.cpp +++ b/core/math/face3.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/core/math/face3.h b/core/math/face3.h index 3d02ae4014..8e4a25fb7a 100644 --- a/core/math/face3.h +++ b/core/math/face3.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/core/math/geometry.cpp b/core/math/geometry.cpp index 2bea514d37..7c8fb6f17d 100644 --- a/core/math/geometry.cpp +++ b/core/math/geometry.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -1076,8 +1076,8 @@ void Geometry::make_atlas(const Vector<Size2i> &p_rects, Vector<Point2i> &r_resu for (int i = 0; i < results.size(); i++) { - real_t h = nearest_power_of_2(results[i].max_h); - real_t w = nearest_power_of_2(results[i].max_w); + real_t h = next_power_of_2(results[i].max_h); + real_t w = next_power_of_2(results[i].max_w); real_t aspect = h > w ? h / w : w / h; if (aspect < best_aspect) { best = i; diff --git a/core/math/geometry.h b/core/math/geometry.h index 909d8164c3..cd069bd7a3 100644 --- a/core/math/geometry.h +++ b/core/math/geometry.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -105,7 +105,7 @@ public: } static void get_closest_points_between_segments(const Vector3 &p1, const Vector3 &p2, const Vector3 &q1, const Vector3 &q2, Vector3 &c1, Vector3 &c2) { -#if 1 + //do the function 'd' as defined by pb. I think is is dot product of some sort #define d_of(m, n, o, p) ((m.x - n.x) * (o.x - p.x) + (m.y - n.y) * (o.y - p.y) + (m.z - n.z) * (o.z - p.z)) @@ -120,33 +120,6 @@ public: if (mub > 1) mub = 1; c1 = p1.linear_interpolate(p2, mua); c2 = q1.linear_interpolate(q2, mub); -#else - //this is broken do not use - Vector3 u = p2 - p1; - Vector3 v = q2 - q1; - Vector3 w = p1 - q1; - float a = u.dot(u); - float b = u.dot(v); - float c = v.dot(v); // always >= 0 - float d = u.dot(w); - float e = v.dot(w); - float D = a * c - b * b; // always >= 0 - float sc, tc; - - // compute the line parameters of the two closest points - if (D < CMP_EPSILON) { // the lines are almost parallel - sc = 0.0; - tc = (b > c ? d / b : e / c); // use the largest denominator - } else { - sc = (b * e - c * d) / D; - tc = (a * e - b * d) / D; - } - - c1 = w + sc * u; - c2 = w + tc * v; -// get the difference of the two closest points -//Vector dP = w + (sc * u) - (tc * v); // = L1(sc) - L2(tc) -#endif } static real_t get_closest_distance_between_segments(const Vector3 &p_from_a, const Vector3 &p_to_a, const Vector3 &p_from_b, const Vector3 &p_to_b) { diff --git a/core/math/math_2d.cpp b/core/math/math_2d.cpp index 52e240ed47..c77fe96ff2 100644 --- a/core/math/math_2d.cpp +++ b/core/math/math_2d.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -205,33 +205,6 @@ Vector2 Vector2::clamped(real_t p_len) const { return v; } -Vector2 Vector2::cubic_interpolate_soft(const Vector2 &p_b, const Vector2 &p_pre_a, const Vector2 &p_post_b, real_t p_t) const { -#if 0 - k[0] = ((*this) (vi[0] + 1, vi[1], vi[2])) - ((*this) (vi[0], - vi[1],vi[2])); //fk = a0 - k[1] = (((*this) (vi[0] + 1, vi[1], vi[2])) - ((*this) ((int) (v(0) - - 1), vi[1],vi[2])))*0.5; //dk = a1 - k[2] = (((*this) ((int) (v(0) + 2), vi[1], vi[2])) - ((*this) (vi[0], - vi[1],vi[2])))*0.5; //dk+1 - k[3] = k[0]*3 - k[1]*2 - k[2];//a2 - k[4] = k[1] + k[2] - k[0]*2;//a3 - - //ip = a3(t-tk)³ + a2(t-tk)² + a1(t-tk) + a0 - // - //a3 = dk + dk+1 - Dk - //a2 = 3Dk - 2dk - dk+1 - //a1 = dk - //a0 = fk - // - //dk = (fk+1 - fk-1)*0.5 - //Dk = (fk+1 - fk) - - real_t dk = -#endif - - return Vector2(); -} - Vector2 Vector2::cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, const Vector2 &p_post_b, real_t p_t) const { Vector2 p0 = p_pre_a; @@ -281,22 +254,22 @@ Vector2 Vector2::cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, c } // slide returns the component of the vector along the given plane, specified by its normal vector. -Vector2 Vector2::slide(const Vector2 &p_n) const { +Vector2 Vector2::slide(const Vector2 &p_normal) const { #ifdef MATH_CHECKS - ERR_FAIL_COND_V(p_n.is_normalized() == false, Vector2()); + ERR_FAIL_COND_V(p_normal.is_normalized() == false, Vector2()); #endif - return *this - p_n * this->dot(p_n); + return *this - p_normal * this->dot(p_normal); } -Vector2 Vector2::bounce(const Vector2 &p_n) const { - return -reflect(p_n); +Vector2 Vector2::bounce(const Vector2 &p_normal) const { + return -reflect(p_normal); } -Vector2 Vector2::reflect(const Vector2 &p_n) const { +Vector2 Vector2::reflect(const Vector2 &p_normal) const { #ifdef MATH_CHECKS - ERR_FAIL_COND_V(p_n.is_normalized() == false, Vector2()); + ERR_FAIL_COND_V(p_normal.is_normalized() == false, Vector2()); #endif - return 2.0 * p_n * this->dot(p_n) - *this; + return 2.0 * p_normal * this->dot(p_normal) - *this; } bool Rect2::intersects_segment(const Point2 &p_from, const Point2 &p_to, Point2 *r_pos, Point2 *r_normal) const { diff --git a/core/math/math_2d.h b/core/math/math_2d.h index b679371e03..d215df8a43 100644 --- a/core/math/math_2d.h +++ b/core/math/math_2d.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -43,6 +43,14 @@ enum Margin { MARGIN_BOTTOM }; +enum Corner { + + CORNER_TOP_LEFT, + CORNER_TOP_RIGHT, + CORNER_BOTTOM_RIGHT, + CORNER_BOTTOM_LEFT +}; + enum Orientation { HORIZONTAL, @@ -105,11 +113,10 @@ struct Vector2 { _FORCE_INLINE_ static Vector2 linear_interpolate(const Vector2 &p_a, const Vector2 &p_b, real_t p_t); _FORCE_INLINE_ Vector2 linear_interpolate(const Vector2 &p_b, real_t p_t) const; Vector2 cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, const Vector2 &p_post_b, real_t p_t) const; - Vector2 cubic_interpolate_soft(const Vector2 &p_b, const Vector2 &p_pre_a, const Vector2 &p_post_b, real_t p_t) const; - Vector2 slide(const Vector2 &p_vec) const; - Vector2 bounce(const Vector2 &p_vec) const; - Vector2 reflect(const Vector2 &p_vec) const; + Vector2 slide(const Vector2 &p_normal) const; + Vector2 bounce(const Vector2 &p_normal) const; + Vector2 reflect(const Vector2 &p_normal) const; Vector2 operator+(const Vector2 &p_v) const; void operator+=(const Vector2 &p_v); @@ -621,9 +628,9 @@ struct Transform2D { void affine_invert(); Transform2D affine_inverse() const; - void set_rotation(real_t p_phi); + void set_rotation(real_t p_rot); real_t get_rotation() const; - _FORCE_INLINE_ void set_rotation_and_scale(real_t p_phi, const Size2 &p_scale); + _FORCE_INLINE_ void set_rotation_and_scale(real_t p_rot, const Size2 &p_scale); void rotate(real_t p_phi); void scale(const Size2 &p_scale); @@ -660,8 +667,8 @@ struct Transform2D { _FORCE_INLINE_ Vector2 basis_xform_inv(const Vector2 &p_vec) const; _FORCE_INLINE_ Vector2 xform(const Vector2 &p_vec) const; _FORCE_INLINE_ Vector2 xform_inv(const Vector2 &p_vec) const; - _FORCE_INLINE_ Rect2 xform(const Rect2 &p_vec) const; - _FORCE_INLINE_ Rect2 xform_inv(const Rect2 &p_vec) const; + _FORCE_INLINE_ Rect2 xform(const Rect2 &p_rect) const; + _FORCE_INLINE_ Rect2 xform_inv(const Rect2 &p_rect) const; operator String() const; @@ -833,25 +840,25 @@ next4: return true; } -Vector2 Transform2D::basis_xform(const Vector2 &v) const { +Vector2 Transform2D::basis_xform(const Vector2 &p_vec) const { return Vector2( - tdotx(v), - tdoty(v)); + tdotx(p_vec), + tdoty(p_vec)); } -Vector2 Transform2D::basis_xform_inv(const Vector2 &v) const { +Vector2 Transform2D::basis_xform_inv(const Vector2 &p_vec) const { return Vector2( - elements[0].dot(v), - elements[1].dot(v)); + elements[0].dot(p_vec), + elements[1].dot(p_vec)); } -Vector2 Transform2D::xform(const Vector2 &v) const { +Vector2 Transform2D::xform(const Vector2 &p_vec) const { return Vector2( - tdotx(v), - tdoty(v)) + + tdotx(p_vec), + tdoty(p_vec)) + elements[2]; } Vector2 Transform2D::xform_inv(const Vector2 &p_vec) const { diff --git a/core/math/math_defs.h b/core/math/math_defs.h index 3d9eb63e11..904cbc1abc 100644 --- a/core/math/math_defs.h +++ b/core/math/math_defs.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/core/math/math_funcs.cpp b/core/math/math_funcs.cpp index 9f5a9c193a..6fb688f16b 100644 --- a/core/math/math_funcs.cpp +++ b/core/math/math_funcs.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -28,16 +28,13 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "math_funcs.h" + #include "core/os/os.h" pcg32_random_t Math::default_pcg = { 12047754176567800795ULL, PCG_DEFAULT_INC_64 }; #define PHI 0x9e3779b9 -#if 0 -static uint32_t Q[4096]; -#endif - // TODO: we should eventually expose pcg.inc too uint32_t Math::rand_from_seed(uint64_t *seed) { pcg32_random_t pcg = { *seed, PCG_DEFAULT_INC_64 }; diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h index 45509a0808..9651e37f3e 100644 --- a/core/math/math_funcs.h +++ b/core/math/math_funcs.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -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..9732a1ff37 100644 --- a/core/math/matrix3.cpp +++ b/core/math/matrix3.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -107,6 +107,13 @@ bool Basis::is_orthogonal() const { return is_equal_approx(id, m); } +bool Basis::is_diagonal() const { + return ( + Math::is_equal_approx(elements[0][1], 0) && Math::is_equal_approx(elements[0][2], 0) && + Math::is_equal_approx(elements[1][0], 0) && Math::is_equal_approx(elements[1][2], 0) && + Math::is_equal_approx(elements[2][0], 0) && Math::is_equal_approx(elements[2][1], 0)); +} + bool Basis::is_rotation() const { return Math::is_equal_approx(determinant(), 1) && is_orthogonal(); } @@ -241,12 +248,13 @@ Vector3 Basis::get_scale() const { // This may lead to confusion for some users though. // // The convention we use here is to absorb the sign flip into the scaling matrix. - // The same convention is also used in other similar functions such as set_scale, - // get_rotation_axis_angle, get_rotation, set_rotation_axis_angle, set_rotation_euler, ... + // The same convention is also used in other similar functions such as get_rotation_axis_angle, get_rotation, ... // // A proper way to get rid of this issue would be to store the scaling values (or at least their signs) // as a part of Basis. However, if we go that path, we need to disable direct (write) access to the // matrix elements. + // + // The rotation part of this decomposition is returned by get_rotation* functions. real_t det_sign = determinant() > 0 ? 1 : -1; return det_sign * Vector3( Vector3(elements[0][0], elements[1][0], elements[2][0]).length(), @@ -254,15 +262,24 @@ Vector3 Basis::get_scale() const { Vector3(elements[0][2], elements[1][2], elements[2][2]).length()); } -// Sets scaling while preserving rotation. -// This requires some care when working with matrices with negative determinant, -// since we're using a particular convention for "polar" decomposition in get_scale and get_rotation. -// For details, see the explanation in get_scale. -void Basis::set_scale(const Vector3 &p_scale) { - Vector3 e = get_euler(); - Basis(); // reset to identity - scale(p_scale); - rotate(e); +// Decomposes a Basis into a rotation-reflection matrix (an element of the group O(3)) and a positive scaling matrix as B = O.S. +// Returns the rotation-reflection matrix via reference argument, and scaling information is returned as a Vector3. +// This (internal) function is too specıfıc and named too ugly to expose to users, and probably there's no need to do so. +Vector3 Basis::rotref_posscale_decomposition(Basis &rotref) const { +#ifdef MATH_CHECKS + ERR_FAIL_COND_V(determinant() == 0, Vector3()); + + Basis m = transposed() * (*this); + ERR_FAIL_COND_V(m.is_diagonal() == false, Vector3()); +#endif + Vector3 scale = get_scale(); + Basis inv_scale = Basis().scaled(scale.inverse()); // this will also absorb the sign of scale + rotref = (*this) * inv_scale; + +#ifdef MATH_CHECKS + ERR_FAIL_COND_V(rotref.is_orthogonal() == false, Vector3()); +#endif + return scale.abs(); } // Multiplies the matrix from left by the rotation matrix: M -> R.M @@ -316,28 +333,6 @@ void Basis::get_rotation_axis_angle(Vector3 &p_axis, real_t &p_angle) const { m.get_axis_angle(p_axis, p_angle); } -// Sets rotation while preserving scaling. -// This requires some care when working with matrices with negative determinant, -// since we're using a particular convention for "polar" decomposition in get_scale and get_rotation. -// For details, see the explanation in get_scale. -void Basis::set_rotation_euler(const Vector3 &p_euler) { - Vector3 s = get_scale(); - Basis(); // reset to identity - scale(s); - rotate(p_euler); -} - -// Sets rotation while preserving scaling. -// This requires some care when working with matrices with negative determinant, -// since we're using a particular convention for "polar" decomposition in get_scale and get_rotation. -// For details, see the explanation in get_scale. -void Basis::set_rotation_axis_angle(const Vector3 &p_axis, real_t p_angle) { - Vector3 s = get_scale(); - Basis(); // reset to identity - scale(s); - rotate(p_axis, p_angle); -} - // get_euler_xyz returns a vector containing the Euler angles in the format // (a1,a2,a3), where a3 is the angle of the first rotation, and a1 is the last // (following the convention they are commonly defined in the literature). @@ -364,15 +359,12 @@ Vector3 Basis::get_euler_xyz() const { euler.y = Math::asin(elements[0][2]); 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) { + // is this a pure Y rotation? + if (elements[1][0] == 0.0 && elements[0][1] == 0.0 && elements[1][2] == 0 && elements[2][1] == 0 && elements[1][1] == 1) { + // return the simplest form 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 +428,12 @@ 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); + // is this a pure X rotation? + if (elements[1][0] == 0 && elements[0][1] == 0 && elements[0][2] == 0 && elements[2][0] == 0 && elements[0][0] == 1) { + // return the simplest form + 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]); diff --git a/core/math/matrix3.h b/core/math/matrix3.h index 74e6564578..9c9080ac46 100644 --- a/core/math/matrix3.h +++ b/core/math/matrix3.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -81,8 +81,7 @@ public: Vector3 get_rotation() const; void get_rotation_axis_angle(Vector3 &p_axis, real_t &p_angle) const; - void set_rotation_euler(const Vector3 &p_euler); - void set_rotation_axis_angle(const Vector3 &p_axis, real_t p_angle); + Vector3 rotref_posscale_decomposition(Basis &rotref) const; Vector3 get_euler_xyz() const; void set_euler_xyz(const Vector3 &p_euler); @@ -99,7 +98,6 @@ public: Basis scaled(const Vector3 &p_scale) const; Vector3 get_scale() const; - void set_scale(const Vector3 &p_scale); // transposed dot products _FORCE_INLINE_ real_t tdotx(const Vector3 &v) const { @@ -132,6 +130,7 @@ public: void set_orthogonal_index(int p_index); bool is_orthogonal() const; + bool is_diagonal() const; bool is_rotation() const; operator String() const; diff --git a/core/math/octree.h b/core/math/octree.h index 010c1b18f7..95a67943fd 100644 --- a/core/math/octree.h +++ b/core/math/octree.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -351,7 +351,7 @@ private: }; void _cull_convex(Octant *p_octant, _CullConvexData *p_cull); - void _cull_AABB(Octant *p_octant, const Rect3 &p_aabb, T **p_result_array, int *p_result_idx, int p_result_max, int *p_subindex_array, uint32_t p_mask); + void _cull_aabb(Octant *p_octant, const Rect3 &p_aabb, T **p_result_array, int *p_result_idx, int p_result_max, int *p_subindex_array, uint32_t p_mask); void _cull_segment(Octant *p_octant, const Vector3 &p_from, const Vector3 &p_to, T **p_result_array, int *p_result_idx, int p_result_max, int *p_subindex_array, uint32_t p_mask); void _cull_point(Octant *p_octant, const Vector3 &p_point, T **p_result_array, int *p_result_idx, int p_result_max, int *p_subindex_array, uint32_t p_mask); @@ -380,7 +380,7 @@ public: int get_subindex(OctreeElementID p_id) const; int cull_convex(const Vector<Plane> &p_convex, T **p_result_array, int p_result_max, uint32_t p_mask = 0xFFFFFFFF); - int cull_AABB(const Rect3 &p_aabb, T **p_result_array, int p_result_max, int *p_subindex_array = NULL, uint32_t p_mask = 0xFFFFFFFF); + int cull_aabb(const Rect3 &p_aabb, T **p_result_array, int p_result_max, int *p_subindex_array = NULL, uint32_t p_mask = 0xFFFFFFFF); int cull_segment(const Vector3 &p_from, const Vector3 &p_to, T **p_result_array, int p_result_max, int *p_subindex_array = NULL, uint32_t p_mask = 0xFFFFFFFF); int cull_point(const Vector3 &p_point, T **p_result_array, int p_result_max, int *p_subindex_array = NULL, uint32_t p_mask = 0xFFFFFFFF); @@ -851,28 +851,6 @@ void Octree<T, use_pairs, AL>::move(OctreeElementID p_id, const Rect3 &p_aabb) { ERR_FAIL_COND(!E); Element &e = E->get(); -#if 0 - - pass++; - if (!e.aabb.has_no_surface()) { - _remove_element(&e); - } - - e.aabb=p_aabb; - - if (!e.aabb.has_no_surface()) { - _ensure_valid_root(p_aabb); - - _insert_element(&e,root); - if (use_pairs) - _element_check_pairs(&e); - - } - - _optimize(); - -#else - bool old_has_surf = !e.aabb.has_no_surface(); bool new_has_surf = !p_aabb.has_no_surface(); @@ -979,7 +957,6 @@ void Octree<T, use_pairs, AL>::move(OctreeElementID p_id, const Rect3 &p_aabb) { } _optimize(); -#endif } template <class T, bool use_pairs, class AL> @@ -1095,7 +1072,7 @@ void Octree<T, use_pairs, AL>::_cull_convex(Octant *p_octant, _CullConvexData *p } template <class T, bool use_pairs, class AL> -void Octree<T, use_pairs, AL>::_cull_AABB(Octant *p_octant, const Rect3 &p_aabb, T **p_result_array, int *p_result_idx, int p_result_max, int *p_subindex_array, uint32_t p_mask) { +void Octree<T, use_pairs, AL>::_cull_aabb(Octant *p_octant, const Rect3 &p_aabb, T **p_result_array, int *p_result_idx, int p_result_max, int *p_subindex_array, uint32_t p_mask) { if (*p_result_idx == p_result_max) return; //pointless @@ -1160,7 +1137,7 @@ void Octree<T, use_pairs, AL>::_cull_AABB(Octant *p_octant, const Rect3 &p_aabb, for (int i = 0; i < 8; i++) { if (p_octant->children[i] && p_octant->children[i]->aabb.intersects_inclusive(p_aabb)) { - _cull_AABB(p_octant->children[i], p_aabb, p_result_array, p_result_idx, p_result_max, p_subindex_array, p_mask); + _cull_aabb(p_octant->children[i], p_aabb, p_result_array, p_result_idx, p_result_max, p_subindex_array, p_mask); } } } @@ -1336,14 +1313,14 @@ int Octree<T, use_pairs, AL>::cull_convex(const Vector<Plane> &p_convex, T **p_r } template <class T, bool use_pairs, class AL> -int Octree<T, use_pairs, AL>::cull_AABB(const Rect3 &p_aabb, T **p_result_array, int p_result_max, int *p_subindex_array, uint32_t p_mask) { +int Octree<T, use_pairs, AL>::cull_aabb(const Rect3 &p_aabb, T **p_result_array, int p_result_max, int *p_subindex_array, uint32_t p_mask) { if (!root) return 0; int result_count = 0; pass++; - _cull_AABB(root, p_aabb, p_result_array, &result_count, p_result_max, p_subindex_array, p_mask); + _cull_aabb(root, p_aabb, p_result_array, &result_count, p_result_max, p_subindex_array, p_mask); return result_count; } diff --git a/core/math/plane.cpp b/core/math/plane.cpp index f5e92866c4..08395ed07b 100644 --- a/core/math/plane.cpp +++ b/core/math/plane.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -103,7 +103,7 @@ bool Plane::intersect_3(const Plane &p_plane1, const Plane &p_plane2, Vector3 *r return true; } -bool Plane::intersects_ray(Vector3 p_from, Vector3 p_dir, Vector3 *p_intersection) const { +bool Plane::intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *p_intersection) const { Vector3 segment = p_dir; real_t den = normal.dot(segment); @@ -128,7 +128,7 @@ bool Plane::intersects_ray(Vector3 p_from, Vector3 p_dir, Vector3 *p_intersectio return true; } -bool Plane::intersects_segment(Vector3 p_begin, Vector3 p_end, Vector3 *p_intersection) const { +bool Plane::intersects_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 *p_intersection) const { Vector3 segment = p_begin - p_end; real_t den = normal.dot(segment); diff --git a/core/math/plane.h b/core/math/plane.h index 92ebcd8024..559a735817 100644 --- a/core/math/plane.h +++ b/core/math/plane.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -56,8 +56,8 @@ public: /* intersections */ bool intersect_3(const Plane &p_plane1, const Plane &p_plane2, Vector3 *r_result = 0) const; - bool intersects_ray(Vector3 p_from, Vector3 p_dir, Vector3 *p_intersection) const; - bool intersects_segment(Vector3 p_begin, Vector3 p_end, Vector3 *p_intersection) const; + bool intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *p_intersection) const; + bool intersects_segment(const Vector3 &p_begin, const Vector3 &p_end, Vector3 *p_intersection) const; _FORCE_INLINE_ Vector3 project(const Vector3 &p_point) const { diff --git a/core/math/quat.cpp b/core/math/quat.cpp index 5984cdf657..cebc5b9522 100644 --- a/core/math/quat.cpp +++ b/core/math/quat.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -139,48 +139,6 @@ Quat Quat::inverse() const { Quat Quat::slerp(const Quat &q, const real_t &t) const { -#if 0 - - - Quat dst=q; - Quat src=*this; - - src.normalize(); - dst.normalize(); - - real_t cosine = dst.dot(src); - - if (cosine < 0 && true) { - cosine = -cosine; - dst = -dst; - } else { - dst = dst; - } - - if (Math::abs(cosine) < 1 - CMP_EPSILON) { - // Standard case (slerp) - real_t sine = Math::sqrt(1 - cosine*cosine); - real_t angle = Math::atan2(sine, cosine); - real_t inv_sine = 1.0 / sine; - real_t coeff_0 = Math::sin((1.0 - t) * angle) * inv_sine; - real_t coeff_1 = Math::sin(t * angle) * inv_sine; - Quat ret= src * coeff_0 + dst * coeff_1; - - return ret; - } else { - // There are two situations: - // 1. "rkP" and "q" are very close (cosine ~= +1), so we can do a linear - // interpolation safely. - // 2. "rkP" and "q" are almost invedste of each other (cosine ~= -1), there - // are an infinite number of possibilities interpolation. but we haven't - // have method to fix this case, so just use linear interpolation here. - Quat ret = src * (1.0 - t) + dst *t; - // taking the complement requires renormalisation - ret.normalize(); - return ret; - } -#else - Quat to1; real_t omega, cosom, sinom, scale0, scale1; @@ -221,7 +179,6 @@ Quat Quat::slerp(const Quat &q, const real_t &t) const { scale0 * y + scale1 * to1.y, scale0 * z + scale1 * to1.z, scale0 * w + scale1 * to1.w); -#endif } Quat Quat::slerpni(const Quat &q, const real_t &t) const { @@ -241,53 +198,6 @@ Quat Quat::slerpni(const Quat &q, const real_t &t) const { invFactor * from.y + newFactor * q.y, invFactor * from.z + newFactor * q.z, invFactor * from.w + newFactor * q.w); - -#if 0 - real_t to1[4]; - real_t omega, cosom, sinom, scale0, scale1; - - - // calc cosine - cosom = x * q.x + y * q.y + z * q.z - + w * q.w; - - - // adjust signs (if necessary) - if ( cosom <0.0 && false) { - cosom = -cosom;to1[0] = - q.x; - to1[1] = - q.y; - to1[2] = - q.z; - to1[3] = - q.w; - } else { - to1[0] = q.x; - to1[1] = q.y; - to1[2] = q.z; - to1[3] = q.w; - } - - - // calculate coefficients - - if ( (1.0 - cosom) > CMP_EPSILON ) { - // standard case (slerp) - omega = Math::acos(cosom); - sinom = Math::sin(omega); - scale0 = Math::sin((1.0 - t) * omega) / sinom; - scale1 = Math::sin(t * omega) / sinom; - } else { - // "from" and "to" quaternions are very close - // ... so we can do a linear interpolation - scale0 = 1.0 - t; - scale1 = t; - } - // calculate final values - return Quat( - scale0 * x + scale1 * to1[0], - scale0 * y + scale1 * to1[1], - scale0 * z + scale1 * to1[2], - scale0 * w + scale1 * to1[3] - ); -#endif } Quat Quat::cubic_slerp(const Quat &q, const Quat &prep, const Quat &postq, const real_t &t) const { diff --git a/core/math/quat.h b/core/math/quat.h index 0e378eb4e4..9668f8c7a3 100644 --- a/core/math/quat.h +++ b/core/math/quat.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/core/math/quick_hull.cpp b/core/math/quick_hull.cpp index 54b97ac38c..e9a383df40 100644 --- a/core/math/quick_hull.cpp +++ b/core/math/quick_hull.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/core/math/quick_hull.h b/core/math/quick_hull.h index 49600649e3..47ed22615b 100644 --- a/core/math/quick_hull.h +++ b/core/math/quick_hull.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/core/math/rect3.cpp b/core/math/rect3.cpp index 973607f565..6f01000f61 100644 --- a/core/math/rect3.cpp +++ b/core/math/rect3.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/core/math/rect3.h b/core/math/rect3.h index e5d7462009..c3a2f5fbfb 100644 --- a/core/math/rect3.h +++ b/core/math/rect3.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -47,12 +47,12 @@ public: real_t get_area() const; /// get area _FORCE_INLINE_ bool has_no_area() const { - return (size.x <= CMP_EPSILON || size.y <= CMP_EPSILON || size.z <= CMP_EPSILON); + return (size.x <= 0 || size.y <= 0 || size.z <= 0); } _FORCE_INLINE_ bool has_no_surface() const { - return (size.x <= CMP_EPSILON && size.y <= CMP_EPSILON && size.z <= CMP_EPSILON); + return (size.x <= 0 && size.y <= 0 && size.z <= 0); } const Vector3 &get_position() const { return position; } @@ -72,9 +72,9 @@ public: Rect3 intersection(const Rect3 &p_aabb) const; ///get box where two intersect, empty if no intersection occurs bool intersects_segment(const Vector3 &p_from, const Vector3 &p_to, Vector3 *r_clip = NULL, Vector3 *r_normal = NULL) const; bool intersects_ray(const Vector3 &p_from, const Vector3 &p_dir, Vector3 *r_clip = NULL, Vector3 *r_normal = NULL) const; - _FORCE_INLINE_ bool smits_intersect_ray(const Vector3 &from, const Vector3 &p_dir, real_t t0, real_t t1) const; + _FORCE_INLINE_ bool smits_intersect_ray(const Vector3 &p_from, const Vector3 &p_dir, real_t t0, real_t t1) const; - _FORCE_INLINE_ bool intersects_convex_shape(const Plane *p_plane, int p_plane_count) const; + _FORCE_INLINE_ bool intersects_convex_shape(const Plane *p_planes, int p_plane_count) const; bool intersects_plane(const Plane &p_plane) const; _FORCE_INLINE_ bool has_point(const Vector3 &p_point) const; @@ -189,8 +189,6 @@ Vector3 Rect3::get_endpoint(int p_point) const { bool Rect3::intersects_convex_shape(const Plane *p_planes, int p_plane_count) const { -#if 1 - Vector3 half_extents = size * 0.5; Vector3 ofs = position + half_extents; @@ -206,42 +204,6 @@ bool Rect3::intersects_convex_shape(const Plane *p_planes, int p_plane_count) co } return true; -#else - //cache all points to check against! - // #warning should be easy to optimize, just use the same as when taking the support and use only that point - Vector3 points[8] = { - Vector3(position.x, position.y, position.z), - Vector3(position.x, position.y, position.z + size.z), - Vector3(position.x, position.y + size.y, position.z), - Vector3(position.x, position.y + size.y, position.z + size.z), - Vector3(position.x + size.x, position.y, position.z), - Vector3(position.x + size.x, position.y, position.z + size.z), - Vector3(position.x + size.x, position.y + size.y, position.z), - Vector3(position.x + size.x, position.y + size.y, position.z + size.z), - }; - - for (int i = 0; i < p_plane_count; i++) { //for each plane - - const Plane &plane = p_planes[i]; - bool all_points_over = true; - //test if it has all points over! - - for (int j = 0; j < 8; j++) { - - if (!plane.is_point_over(points[j])) { - - all_points_over = false; - break; - } - } - - if (all_points_over) { - - return false; - } - } - return true; -#endif } bool Rect3::has_point(const Vector3 &p_point) const { @@ -326,27 +288,27 @@ inline real_t Rect3::get_shortest_axis_size() const { return max_size; } -bool Rect3::smits_intersect_ray(const Vector3 &from, const Vector3 &dir, real_t t0, real_t t1) const { +bool Rect3::smits_intersect_ray(const Vector3 &p_from, const Vector3 &p_dir, real_t t0, real_t t1) const { - real_t divx = 1.0 / dir.x; - real_t divy = 1.0 / dir.y; - real_t divz = 1.0 / dir.z; + real_t divx = 1.0 / p_dir.x; + real_t divy = 1.0 / p_dir.y; + real_t divz = 1.0 / p_dir.z; Vector3 upbound = position + size; real_t tmin, tmax, tymin, tymax, tzmin, tzmax; - if (dir.x >= 0) { - tmin = (position.x - from.x) * divx; - tmax = (upbound.x - from.x) * divx; + if (p_dir.x >= 0) { + tmin = (position.x - p_from.x) * divx; + tmax = (upbound.x - p_from.x) * divx; } else { - tmin = (upbound.x - from.x) * divx; - tmax = (position.x - from.x) * divx; + tmin = (upbound.x - p_from.x) * divx; + tmax = (position.x - p_from.x) * divx; } - if (dir.y >= 0) { - tymin = (position.y - from.y) * divy; - tymax = (upbound.y - from.y) * divy; + if (p_dir.y >= 0) { + tymin = (position.y - p_from.y) * divy; + tymax = (upbound.y - p_from.y) * divy; } else { - tymin = (upbound.y - from.y) * divy; - tymax = (position.y - from.y) * divy; + tymin = (upbound.y - p_from.y) * divy; + tymax = (position.y - p_from.y) * divy; } if ((tmin > tymax) || (tymin > tmax)) return false; @@ -354,12 +316,12 @@ bool Rect3::smits_intersect_ray(const Vector3 &from, const Vector3 &dir, real_t tmin = tymin; if (tymax < tmax) tmax = tymax; - if (dir.z >= 0) { - tzmin = (position.z - from.z) * divz; - tzmax = (upbound.z - from.z) * divz; + if (p_dir.z >= 0) { + tzmin = (position.z - p_from.z) * divz; + tzmax = (upbound.z - p_from.z) * divz; } else { - tzmin = (upbound.z - from.z) * divz; - tzmax = (position.z - from.z) * divz; + tzmin = (upbound.z - p_from.z) * divz; + tzmax = (position.z - p_from.z) * divz; } if ((tmin > tzmax) || (tzmin > tmax)) return false; diff --git a/core/math/transform.cpp b/core/math/transform.cpp index 3a86fbfc6c..60df69a509 100644 --- a/core/math/transform.cpp +++ b/core/math/transform.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/core/math/transform.h b/core/math/transform.h index 48467f2ed7..566bf482a9 100644 --- a/core/math/transform.h +++ b/core/math/transform.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -154,8 +154,7 @@ _FORCE_INLINE_ Plane Transform::xform_inv(const Plane &p_plane) const { } _FORCE_INLINE_ Rect3 Transform::xform(const Rect3 &p_aabb) const { -/* define vertices */ -#if 1 + /* define vertices */ Vector3 x = basis.get_axis(0) * p_aabb.size.x; Vector3 y = basis.get_axis(1) * p_aabb.size.y; Vector3 z = basis.get_axis(2) * p_aabb.size.z; @@ -171,31 +170,8 @@ _FORCE_INLINE_ Rect3 Transform::xform(const Rect3 &p_aabb) const { new_aabb.expand_to(pos + y + z); new_aabb.expand_to(pos + x + y + z); return new_aabb; -#else - - Vector3 vertices[8] = { - Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z + p_aabb.size.z), - Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z), - Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y, p_aabb.position.z + p_aabb.size.z), - Vector3(p_aabb.position.x + p_aabb.size.x, p_aabb.position.y, p_aabb.position.z), - Vector3(p_aabb.position.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z + p_aabb.size.z), - Vector3(p_aabb.position.x, p_aabb.position.y + p_aabb.size.y, p_aabb.position.z), - Vector3(p_aabb.position.x, p_aabb.position.y, p_aabb.position.z + p_aabb.size.z), - Vector3(p_aabb.position.x, p_aabb.position.y, p_aabb.position.z) - }; - - AABB ret; - - ret.pos = xform(vertices[0]); - - for (int i = 1; i < 8; i++) { - - ret.expand_to(xform(vertices[i])); - } - - return ret; -#endif } + _FORCE_INLINE_ Rect3 Transform::xform_inv(const Rect3 &p_aabb) const { /* define vertices */ @@ -222,4 +198,4 @@ _FORCE_INLINE_ Rect3 Transform::xform_inv(const Rect3 &p_aabb) const { return ret; } -#endif +#endif // TRANSFORM_H diff --git a/core/math/triangle_mesh.cpp b/core/math/triangle_mesh.cpp index 1df3c8c298..614104f698 100644 --- a/core/math/triangle_mesh.cpp +++ b/core/math/triangle_mesh.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/core/math/triangle_mesh.h b/core/math/triangle_mesh.h index 166f10c577..2bf67fffcb 100644 --- a/core/math/triangle_mesh.h +++ b/core/math/triangle_mesh.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/core/math/triangulate.cpp b/core/math/triangulate.cpp index 4a5d0a078e..b20f2e06d5 100644 --- a/core/math/triangulate.cpp +++ b/core/math/triangulate.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/core/math/triangulate.h b/core/math/triangulate.h index 3f0ad00033..21e148249e 100644 --- a/core/math/triangulate.h +++ b/core/math/triangulate.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ diff --git a/core/math/vector3.cpp b/core/math/vector3.cpp index efffacb36e..144234f4d1 100644 --- a/core/math/vector3.cpp +++ b/core/math/vector3.cpp @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -125,51 +125,6 @@ Vector3 Vector3::cubic_interpolate(const Vector3 &p_b, const Vector3 &p_pre_a, c return out; } -#if 0 -Vector3 Vector3::cubic_interpolate(const Vector3& p_b,const Vector3& p_pre_a, const Vector3& p_post_b,real_t p_t) const { - - Vector3 p0=p_pre_a; - Vector3 p1=*this; - Vector3 p2=p_b; - Vector3 p3=p_post_b; - - if (true) { - - real_t ab = p0.distance_to(p1); - real_t bc = p1.distance_to(p2); - real_t cd = p2.distance_to(p3); - - //if (ab>bc) { - if (ab>0) - p0 = p1+(p0-p1)*(bc/ab); - //} - - //if (cd>bc) { - if (cd>0) - p3 = p2+(p3-p2)*(bc/cd); - //} - } - - real_t t = p_t; - real_t t2 = t * t; - real_t t3 = t2 * t; - - Vector3 out; - out.x = 0.5 * ( ( 2.0 * p1.x ) + - ( -p0.x + p2.x ) * t + - ( 2.0 * p0.x - 5.0 * p1.x + 4 * p2.x - p3.x ) * t2 + - ( -p0.x + 3.0 * p1.x - 3.0 * p2.x + p3.x ) * t3 ); - out.y = 0.5 * ( ( 2.0 * p1.y ) + - ( -p0.y + p2.y ) * t + - ( 2.0 * p0.y - 5.0 * p1.y + 4 * p2.y - p3.y ) * t2 + - ( -p0.y + 3.0 * p1.y - 3.0 * p2.y + p3.y ) * t3 ); - out.z = 0.5 * ( ( 2.0 * p1.z ) + - ( -p0.z + p2.z ) * t + - ( 2.0 * p0.z - 5.0 * p1.z + 4 * p2.z - p3.z ) * t2 + - ( -p0.z + 3.0 * p1.z - 3.0 * p2.z + p3.z ) * t3 ); - return out; -} -#endif Vector3::operator String() const { return (rtos(x) + ", " + rtos(y) + ", " + rtos(z)); diff --git a/core/math/vector3.h b/core/math/vector3.h index 6a7974681e..74c822fcd7 100644 --- a/core/math/vector3.h +++ b/core/math/vector3.h @@ -3,7 +3,7 @@ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ -/* http://www.godotengine.org */ +/* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */ @@ -108,9 +108,9 @@ struct Vector3 { _FORCE_INLINE_ real_t angle_to(const Vector3 &p_b) const; - _FORCE_INLINE_ Vector3 slide(const Vector3 &p_vec) const; - _FORCE_INLINE_ Vector3 bounce(const Vector3 &p_vec) const; - _FORCE_INLINE_ Vector3 reflect(const Vector3 &p_vec) const; + _FORCE_INLINE_ Vector3 slide(const Vector3 &p_normal) const; + _FORCE_INLINE_ Vector3 bounce(const Vector3 &p_normal) const; + _FORCE_INLINE_ Vector3 reflect(const Vector3 &p_normal) const; /* Operators */ @@ -410,22 +410,22 @@ void Vector3::zero() { } // slide returns the component of the vector along the given plane, specified by its normal vector. -Vector3 Vector3::slide(const Vector3 &p_n) const { +Vector3 Vector3::slide(const Vector3 &p_normal) const { #ifdef MATH_CHECKS - ERR_FAIL_COND_V(p_n.is_normalized() == false, Vector3()); + ERR_FAIL_COND_V(p_normal.is_normalized() == false, Vector3()); #endif - return *this - p_n * this->dot(p_n); + return *this - p_normal * this->dot(p_normal); } -Vector3 Vector3::bounce(const Vector3 &p_n) const { - return -reflect(p_n); +Vector3 Vector3::bounce(const Vector3 &p_normal) const { + return -reflect(p_normal); } -Vector3 Vector3::reflect(const Vector3 &p_n) const { +Vector3 Vector3::reflect(const Vector3 &p_normal) const { #ifdef MATH_CHECKS - ERR_FAIL_COND_V(p_n.is_normalized() == false, Vector3()); + ERR_FAIL_COND_V(p_normal.is_normalized() == false, Vector3()); #endif - return 2.0 * p_n * this->dot(p_n) - *this; + return 2.0 * p_normal * this->dot(p_normal) - *this; } #endif |