summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorBastiaan Olij <mux213@gmail.com>2020-06-09 17:24:04 +1000
committerGitHub <noreply@github.com>2020-06-09 17:24:04 +1000
commit2bb3a7e19c4fd84117b409d061d336b70b8db4ca (patch)
tree452cffa90382189acdbfab80fd23035af65a667f /include
parentceae5be727cf58f7ff5d4856ceeedfccfd8b84b4 (diff)
parent78f5496f4b9986bb390926fb4cb78e646c89c972 (diff)
downloadredot-cpp-2bb3a7e19c4fd84117b409d061d336b70b8db4ca.tar.gz
Merge pull request #412 from Zylann/direction_to
Add missing Vector3::direction_to() and Vector2::direction_to()
Diffstat (limited to 'include')
-rw-r--r--include/core/Vector2.hpp6
-rw-r--r--include/core/Vector3.hpp6
2 files changed, 12 insertions, 0 deletions
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));
}