diff options
Diffstat (limited to 'core/math')
| -rw-r--r-- | core/math/geometry.h | 28 | ||||
| -rw-r--r-- | core/math/math_2d.cpp | 7 | ||||
| -rw-r--r-- | core/math/math_2d.h | 3 | ||||
| -rw-r--r-- | core/math/math_funcs.h | 1 | ||||
| -rw-r--r-- | core/math/plane.cpp | 5 | ||||
| -rw-r--r-- | core/math/plane.h | 1 | ||||
| -rw-r--r-- | core/math/quat.cpp | 19 | ||||
| -rw-r--r-- | core/math/quat.h | 2 | ||||
| -rw-r--r-- | core/math/vector3.cpp | 11 | ||||
| -rw-r--r-- | core/math/vector3.h | 1 |
10 files changed, 30 insertions, 48 deletions
diff --git a/core/math/geometry.h b/core/math/geometry.h index 13cbbdce6f..1dd7df038d 100644 --- a/core/math/geometry.h +++ b/core/math/geometry.h @@ -109,6 +109,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 0 //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) ) @@ -123,6 +124,33 @@ public: if (mub > 1) mub = 1; c1 = p1.linear_interpolate(p2,mua); c2 = q1.linear_interpolate(q2,mub); +#endif + + 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) } 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 995cb0834a..76eeece688 100644 --- a/core/math/math_2d.cpp +++ b/core/math/math_2d.cpp @@ -157,13 +157,6 @@ bool Vector2::operator!=(const Vector2& p_vec2) const { return x!=p_vec2.x || y!=p_vec2.y; } -bool Vector2::nan_equals(const Vector2& p_vec2) const { - - return (x==p_vec2.x && y==p_vec2.y) || - (x==p_vec2.x && isnan(y) && isnan(p_vec2.y)) || - (isnan(x) && isnan(p_vec2.x) && y == p_vec2.y); -} - Vector2 Vector2::floor() const { return Vector2( Math::floor(x), Math::floor(y) ); diff --git a/core/math/math_2d.h b/core/math/math_2d.h index 6dd8799ba2..a24c4266ee 100644 --- a/core/math/math_2d.h +++ b/core/math/math_2d.h @@ -133,7 +133,6 @@ struct Vector2 { bool operator<(const Vector2& p_vec2) const { return (x==p_vec2.x)?(y<p_vec2.y):(x<p_vec2.x); } bool operator<=(const Vector2& p_vec2) const { return (x==p_vec2.x)?(y<=p_vec2.y):(x<=p_vec2.x); } - bool nan_equals(const Vector2& p_vec2) const; real_t angle() const; void set_rotation(real_t p_radians) { @@ -320,8 +319,6 @@ struct Rect2 { bool operator==(const Rect2& p_rect) const { return pos==p_rect.pos && size==p_rect.size; } bool operator!=(const Rect2& p_rect) const { return pos!=p_rect.pos || size!=p_rect.size; } - bool nan_equals(const Rect2& p_rect) const { return pos.nan_equals(p_rect.pos) && size == p_rect.size; } - inline Rect2 grow(real_t p_by) const { Rect2 g=*this; diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h index 511af91835..51877891e3 100644 --- a/core/math/math_funcs.h +++ b/core/math/math_funcs.h @@ -39,6 +39,7 @@ #define Math_PI 3.14159265358979323846 #define Math_SQRT12 0.7071067811865475244008443621048490 #define Math_LN2 0.693147180559945309417 +#define Math_NAN NAN class Math { diff --git a/core/math/plane.cpp b/core/math/plane.cpp index 0d446059c4..2a97932049 100644 --- a/core/math/plane.cpp +++ b/core/math/plane.cpp @@ -164,8 +164,3 @@ Plane::operator String() const { return normal.operator String() + ", " + rtos(d); } - -bool Plane::nan_equals(const Plane& p_plane) const { - - return normal.nan_equals(p_plane.normal) && d == p_plane.d; -} diff --git a/core/math/plane.h b/core/math/plane.h index 13cfc265bc..8235c59135 100644 --- a/core/math/plane.h +++ b/core/math/plane.h @@ -73,7 +73,6 @@ public: _FORCE_INLINE_ bool operator==(const Plane& p_plane) const; _FORCE_INLINE_ bool operator!=(const Plane& p_plane) const; - bool nan_equals(const Plane& p_plane) const; operator String() const; _FORCE_INLINE_ Plane() { d=0; } diff --git a/core/math/quat.cpp b/core/math/quat.cpp index 5ba5a7706b..4085f9b84a 100644 --- a/core/math/quat.cpp +++ b/core/math/quat.cpp @@ -284,22 +284,3 @@ Quat::Quat(const Vector3& axis, const real_t& angle) { cos_angle); } } - -bool Quat::nan_equals(const Quat& q2) const { - return (x == q2.x && y == q2.y && z == q2.z && w == q2.w) || - (x == q2.x && y == q2.y && z == q2.z && isnan(w) && isnan(q2.w)) || - (x == q2.x && y == q2.y && isnan(z) && isnan(q2.z) && w == q2.w) || - (x == q2.x && y == q2.y && isnan(z) && isnan(q2.z) && isnan(w) && isnan(q2.w)) || - (x == q2.x && isnan(y) && isnan(q2.y) && z == q2.z && w == q2.w) || - (x == q2.x && isnan(y) && isnan(q2.y) && z == q2.z && isnan(w) && isnan(q2.w)) || - (x == q2.x && isnan(y) && isnan(q2.y) && isnan(z) && isnan(q2.z) && w == q2.w) || - (x == q2.x && isnan(y) && isnan(q2.y) && isnan(z) && isnan(q2.z) && isnan(w) && isnan(q2.w)) || - (isnan(x) && isnan(q2.x) && y == q2.y && z == q2.z && w == q2.w) || - (isnan(x) && isnan(q2.x) && y == q2.y && z == q2.z && isnan(w) && isnan(q2.w)) || - (isnan(x) && isnan(q2.x) && y == q2.y && isnan(z) && isnan(q2.z) && w == q2.w) || - (isnan(x) && isnan(q2.x) && y == q2.y && isnan(z) && isnan(q2.z) && isnan(w) && isnan(q2.w)) || - (isnan(x) && isnan(q2.x) && isnan(y) && isnan(q2.y) && z == q2.z && w == q2.w) || - (isnan(x) && isnan(q2.x) && isnan(y) && isnan(q2.y) && z == q2.z && isnan(w) && isnan(q2.w)) || - (isnan(x) && isnan(q2.x) && isnan(y) && isnan(q2.y) && isnan(z) && isnan(q2.z) && w == q2.w) || - (isnan(x) && isnan(q2.x) && isnan(y) && isnan(q2.y) && isnan(z) && isnan(q2.z) && isnan(w) && isnan(q2.w)); -} diff --git a/core/math/quat.h b/core/math/quat.h index 5d91bb1d36..d3a50343a3 100644 --- a/core/math/quat.h +++ b/core/math/quat.h @@ -93,7 +93,6 @@ public: _FORCE_INLINE_ Quat operator*(const real_t& s) const; _FORCE_INLINE_ Quat operator/(const real_t& s) const; - bool nan_equals(const Quat& q2) const; _FORCE_INLINE_ bool operator==(const Quat& p_quat) const; _FORCE_INLINE_ bool operator!=(const Quat& p_quat) const; @@ -194,4 +193,5 @@ bool Quat::operator!=(const Quat& p_quat) const { return x!=p_quat.x || y!=p_quat.y || z!=p_quat.z || w!=p_quat.w; } + #endif diff --git a/core/math/vector3.cpp b/core/math/vector3.cpp index 7fdb54bb69..2ab5fa0465 100644 --- a/core/math/vector3.cpp +++ b/core/math/vector3.cpp @@ -176,17 +176,6 @@ Vector3 Vector3::cubic_interpolate(const Vector3& p_b,const Vector3& p_pre_a, co return out; } # endif -bool Vector3::nan_equals(const Vector3& p_v) const { - return (x == p_v.x && y == p_v.y && z == p_v.z) || - (x == p_v.x && y == p_v.y && isnan(z) && isnan(p_v.z)) || - (x == p_v.x && isnan(y) && isnan(p_v.y) && z == p_v.z) || - (isnan(x) && isnan(p_v.x) && y == p_v.y && z == p_v.z) || - (x == p_v.x && isnan(y) && isnan(p_v.y) && isnan(z) && isnan(p_v.z)) || - (isnan(x) && isnan(p_v.x) && y == p_v.y && isnan(z) && isnan(p_v.z)) || - (isnan(x) && isnan(p_v.x) && isnan(y) && isnan(p_v.y) && z == p_v.z) || - (isnan(x) && isnan(p_v.x) && isnan(y) && isnan(p_v.y) && isnan(z) && isnan(p_v.z)); -} - Vector3::operator String() const { return (rtos(x)+", "+rtos(y)+", "+rtos(z)); diff --git a/core/math/vector3.h b/core/math/vector3.h index 938b1b16cb..a289f9bf4c 100644 --- a/core/math/vector3.h +++ b/core/math/vector3.h @@ -134,7 +134,6 @@ struct Vector3 { _FORCE_INLINE_ bool operator<(const Vector3& p_v) const; _FORCE_INLINE_ bool operator<=(const Vector3& p_v) const; - bool nan_equals(const Vector3& p_v) const; operator String() const; _FORCE_INLINE_ Vector3() { x=y=z=0; } |