diff options
Diffstat (limited to 'core/math')
-rw-r--r-- | core/math/face3.cpp | 2 | ||||
-rw-r--r-- | core/math/geometry.cpp | 4 | ||||
-rw-r--r-- | core/math/geometry.h | 2 | ||||
-rw-r--r-- | core/math/matrix3.cpp | 4 | ||||
-rw-r--r-- | core/math/plane.cpp | 2 | ||||
-rw-r--r-- | core/math/rect3.h | 2 | ||||
-rw-r--r-- | core/math/vector3.h | 7 |
7 files changed, 15 insertions, 8 deletions
diff --git a/core/math/face3.cpp b/core/math/face3.cpp index d9d99b0384..6a15feefe1 100644 --- a/core/math/face3.cpp +++ b/core/math/face3.cpp @@ -136,7 +136,7 @@ Face3::Side Face3::get_side_of(const Face3 &p_face, ClockDirection p_clock_dir) const Vector3 &v = p_face.vertex[i]; - if (plane.has_point(v)) //coplanar, dont bother + if (plane.has_point(v)) //coplanar, don't bother continue; if (plane.is_point_over(v)) diff --git a/core/math/geometry.cpp b/core/math/geometry.cpp index ec4d352a8f..97579e41ef 100644 --- a/core/math/geometry.cpp +++ b/core/math/geometry.cpp @@ -990,7 +990,7 @@ void Geometry::make_atlas(const Vector<Size2i> &p_rects, Vector<Point2i> &r_resu //super simple, almost brute force scanline stacking fitter //it's pretty basic for now, but it tries to make sure that the aspect ratio of the - //resulting atlas is somehow square. This is necesary because video cards have limits + //resulting atlas is somehow square. This is necessary because video cards have limits //on texture size (usually 2048 or 4096), so the more square a texture, the more chances //it will work in every hardware. // for example, it will prioritize a 1024x1024 atlas (works everywhere) instead of a @@ -1057,7 +1057,7 @@ void Geometry::make_atlas(const Vector<Size2i> &p_rects, Vector<Point2i> &r_resu if (end_w > max_w) max_w = end_w; - if (ofs == 0 || end_h > limit_h) //while h limit not reched, keep stacking + if (ofs == 0 || end_h > limit_h) //while h limit not reached, keep stacking ofs += wrects[j].s.width; } diff --git a/core/math/geometry.h b/core/math/geometry.h index 93ab0be2e0..26f977e6eb 100644 --- a/core/math/geometry.h +++ b/core/math/geometry.h @@ -108,7 +108,7 @@ public: //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)) - //caluclate the parpametric position on the 2 curves, mua and mub + //calculate the parametric position on the 2 curves, mua and mub real_t mua = ( d_of(p1,q1,q2,q1) * d_of(q2,q1,p2,p1) - d_of(p1,q1,p2,p1) * d_of(q2,q1,q2,q1) ) / ( d_of(p2,p1,p2,p1) * d_of(q2,q1,q2,q1) - d_of(q2,q1,p2,p1) * d_of(q2,q1,p2,p1) ); real_t mub = ( d_of(p1,q1,q2,q1) + mua * d_of(q2,q1,p2,p1) ) / d_of(q2,q1,q2,q1); diff --git a/core/math/matrix3.cpp b/core/math/matrix3.cpp index 5f73d91ef3..b31df2fadb 100644 --- a/core/math/matrix3.cpp +++ b/core/math/matrix3.cpp @@ -229,7 +229,7 @@ Vector3 Basis::get_scale() const { // FIXME: We eventually need a proper polar decomposition. // As a cheap workaround until then, to ensure that R is a proper rotation matrix with determinant +1 // (such that it can be represented by a Quat or Euler angles), we absorb the sign flip into the scaling matrix. - // As such, it works in conjuction with get_rotation(). + // As such, it works in conjunction with get_rotation(). real_t det_sign = determinant() > 0 ? 1 : -1; return det_sign * Vector3( Vector3(elements[0][0], elements[1][0], elements[2][0]).length(), @@ -575,6 +575,8 @@ Basis::Basis(const Quat &p_quat) { Basis::Basis(const Vector3 &p_axis, real_t p_phi) { // Rotation matrix from axis and angle, see https://en.wikipedia.org/wiki/Rotation_matrix#Rotation_matrix_from_axis_and_angle + ERR_FAIL_COND(p_axis.is_normalized() == false); + Vector3 axis_sq(p_axis.x * p_axis.x, p_axis.y * p_axis.y, p_axis.z * p_axis.z); real_t cosine = Math::cos(p_phi); diff --git a/core/math/plane.cpp b/core/math/plane.cpp index 29e7f2e75c..bef5c3ab06 100644 --- a/core/math/plane.cpp +++ b/core/math/plane.cpp @@ -116,7 +116,7 @@ bool Plane::intersects_ray(Vector3 p_from, Vector3 p_dir, Vector3 *p_intersectio real_t dist = (normal.dot(p_from) - d) / den; //printf("dist is %i\n",dist); - if (dist > CMP_EPSILON) { //this is a ray, before the emiting pos (p_from) doesnt exist + if (dist > CMP_EPSILON) { //this is a ray, before the emitting pos (p_from) doesn't exist return false; } diff --git a/core/math/rect3.h b/core/math/rect3.h index 26198537c2..0b11cd7b52 100644 --- a/core/math/rect3.h +++ b/core/math/rect3.h @@ -95,7 +95,7 @@ public: Rect3 expand(const Vector3 &p_vector) const; _FORCE_INLINE_ void project_range_in_plane(const Plane &p_plane, real_t &r_min, real_t &r_max) const; - _FORCE_INLINE_ void expand_to(const Vector3 &p_vector); /** expand to contain a point if necesary */ + _FORCE_INLINE_ void expand_to(const Vector3 &p_vector); /** expand to contain a point if necessary */ operator String() const; diff --git a/core/math/vector3.h b/core/math/vector3.h index fc02e66c33..951380e898 100644 --- a/core/math/vector3.h +++ b/core/math/vector3.h @@ -75,6 +75,7 @@ struct Vector3 { _FORCE_INLINE_ void normalize(); _FORCE_INLINE_ Vector3 normalized() const; + _FORCE_INLINE_ bool is_normalized() const; _FORCE_INLINE_ Vector3 inverse() const; _FORCE_INLINE_ void zero(); @@ -214,7 +215,7 @@ real_t Vector3::distance_squared_to(const Vector3 &p_b) const { real_t Vector3::angle_to(const Vector3 &p_b) const { - return Math::acos(this->dot(p_b) / Math::sqrt(this->length_squared() * p_b.length_squared())); + return Math::atan2(cross(p_b).length(), dot(p_b)); } /* Operators */ @@ -385,6 +386,10 @@ Vector3 Vector3::normalized() const { return v; } +bool Vector3::is_normalized() const { + return Math::isequal_approx(length(), (real_t)1.0); +} + Vector3 Vector3::inverse() const { return Vector3(1.0 / x, 1.0 / y, 1.0 / z); |