diff options
author | Thomas Herzog <therzog@mail.de> | 2018-08-16 12:52:38 +0200 |
---|---|---|
committer | Thomas Herzog <therzog@mail.de> | 2018-08-16 12:52:38 +0200 |
commit | 037f4638aba99981393edd247057f851e80db489 (patch) | |
tree | 70075682e7bd0666b69e4f78d9fac5292715de7e /core/math/vector3.h | |
parent | af93842f937270f5e25cd7270fba1cde18cd21c9 (diff) |
add project method to Vector2/3
Diffstat (limited to 'core/math/vector3.h')
-rw-r--r-- | core/math/vector3.h | 6 |
1 files changed, 6 insertions, 0 deletions
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)); |