diff options
Diffstat (limited to 'core/math')
-rw-r--r-- | core/math/vector2.cpp | 7 | ||||
-rw-r--r-- | core/math/vector2.h | 2 | ||||
-rw-r--r-- | core/math/vector3.h | 6 |
3 files changed, 9 insertions, 6 deletions
diff --git a/core/math/vector2.cpp b/core/math/vector2.cpp index 441e7d8907..75d9b8b311 100644 --- a/core/math/vector2.cpp +++ b/core/math/vector2.cpp @@ -121,11 +121,8 @@ Vector2 Vector2::rotated(real_t p_by) const { return v; } -Vector2 Vector2::project(const Vector2 &p_vec) const { - - Vector2 v1 = p_vec; - Vector2 v2 = *this; - return v2 * (v1.dot(v2) / v2.dot(v2)); +Vector2 Vector2::project(const Vector2 &p_b) const { + return p_b * (dot(p_b) / p_b.dot(p_b)); } Vector2 Vector2::snapped(const Vector2 &p_by) const { diff --git a/core/math/vector2.h b/core/math/vector2.h index 7c8882f6e2..fbcdc80b60 100644 --- a/core/math/vector2.h +++ b/core/math/vector2.h @@ -68,7 +68,7 @@ struct Vector2 { real_t dot(const Vector2 &p_other) const; real_t cross(const Vector2 &p_other) const; - Vector2 project(const Vector2 &p_vec) const; + Vector2 project(const Vector2 &p_b) const; Vector2 plane_project(real_t p_d, const Vector2 &p_vec) const; diff --git a/core/math/vector3.h b/core/math/vector3.h index 433adf09ee..a719e3965d 100644 --- a/core/math/vector3.h +++ b/core/math/vector3.h @@ -109,6 +109,8 @@ struct Vector3 { _FORCE_INLINE_ real_t distance_to(const Vector3 &p_b) const; _FORCE_INLINE_ real_t distance_squared_to(const Vector3 &p_b) const; + _FORCE_INLINE_ Vector3 project(const Vector3 &p_b) const; + _FORCE_INLINE_ real_t angle_to(const Vector3 &p_b) const; _FORCE_INLINE_ Vector3 slide(const Vector3 &p_normal) const; @@ -238,6 +240,10 @@ real_t Vector3::distance_squared_to(const Vector3 &p_b) const { return (p_b - *this).length_squared(); } +Vector3 Vector3::project(const Vector3 &p_b) const { + return p_b * (dot(p_b) / p_b.dot(p_b)); +} + real_t Vector3::angle_to(const Vector3 &p_b) const { return Math::atan2(cross(p_b).length(), dot(p_b)); |