From 78f5496f4b9986bb390926fb4cb78e646c89c972 Mon Sep 17 00:00:00 2001 From: Marc Gilleron Date: Fri, 5 Jun 2020 19:07:56 +0100 Subject: [PATCH] Add missing Vector3::direction_to() and Vector2::direction_to() --- include/core/Vector2.hpp | 6 ++++++ include/core/Vector3.hpp | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/include/core/Vector2.hpp b/include/core/Vector2.hpp index 99ac60f..2a4f5fe 100644 --- a/include/core/Vector2.hpp +++ b/include/core/Vector2.hpp @@ -138,6 +138,12 @@ struct Vector2 { return atan2(y - p_vector2.y, x - p_vector2.x); } + inline Vector2 direction_to(const Vector2 &p_b) const { + Vector2 ret(p_b.x - x, p_b.y - y); + ret.normalize(); + return ret; + } + inline real_t dot(const Vector2 &p_other) const { return x * p_other.x + y * p_other.y; } diff --git a/include/core/Vector3.hpp b/include/core/Vector3.hpp index 2d78f21..7e2c302 100644 --- a/include/core/Vector3.hpp +++ b/include/core/Vector3.hpp @@ -203,6 +203,12 @@ struct Vector3 { return std::atan2(cross(b).length(), dot(b)); } + inline Vector3 direction_to(const Vector3 &p_b) const { + Vector3 ret(p_b.x - x, p_b.y - y, p_b.z - z); + ret.normalize(); + return ret; + } + inline Vector3 floor() const { return Vector3(::floor(x), ::floor(y), ::floor(z)); }