diff options
author | Chaosus <chaosus89@gmail.com> | 2019-03-27 13:51:05 +0300 |
---|---|---|
committer | Chaosus <chaosus89@gmail.com> | 2019-04-05 17:09:57 +0300 |
commit | 55f3bd97a270b691c26d6eda70bc7c0a3ec8f4e8 (patch) | |
tree | 2026f7241b7e7670ffb97ceff22962ce90b432f7 /core/math/vector2.h | |
parent | 6574c557c962d9e4dd726b494322aea246a0245a (diff) | |
download | redot-engine-55f3bd97a270b691c26d6eda70bc7c0a3ec8f4e8.tar.gz |
Added direction_to method to vectors
Diffstat (limited to 'core/math/vector2.h')
-rw-r--r-- | core/math/vector2.h | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/core/math/vector2.h b/core/math/vector2.h index a20326f667..ae2d1ec660 100644 --- a/core/math/vector2.h +++ b/core/math/vector2.h @@ -65,6 +65,7 @@ struct Vector2 { real_t distance_squared_to(const Vector2 &p_vector2) const; real_t angle_to(const Vector2 &p_vector2) const; real_t angle_to_point(const Vector2 &p_vector2) const; + _FORCE_INLINE_ Vector2 direction_to(const Vector2 &p_b) const; real_t dot(const Vector2 &p_other) const; real_t cross(const Vector2 &p_other) const; @@ -236,6 +237,12 @@ Vector2 Vector2::slerp(const Vector2 &p_b, real_t p_t) const { return rotated(theta * p_t); } +Vector2 Vector2::direction_to(const Vector2 &p_b) const { + Vector2 ret(p_b.x - x, p_b.y - y); + ret.normalize(); + return ret; +} + Vector2 Vector2::linear_interpolate(const Vector2 &p_a, const Vector2 &p_b, real_t p_t) { Vector2 res = p_a; |