diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2019-04-08 12:00:54 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-04-08 12:00:54 +0200 |
commit | 7f3373d79f017c17ad5ffd0eba877fc056ad649b (patch) | |
tree | b78f9874fe96e979edf8cab43da744dcb94bd0ab /core/math/vector2.h | |
parent | a994db62df731879bb9c54e65b4ddca32396e9d3 (diff) | |
parent | 55f3bd97a270b691c26d6eda70bc7c0a3ec8f4e8 (diff) | |
download | redot-engine-7f3373d79f017c17ad5ffd0eba877fc056ad649b.tar.gz |
Merge pull request #27452 from Chaosus/direction_to
Added method to retrieve a direction vector from one point to another
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; |