summaryrefslogtreecommitdiff
path: root/core/math
diff options
context:
space:
mode:
authorJ08nY <johny@neuromancer.sk>2016-10-01 21:20:09 +0200
committerJ08nY <johny@neuromancer.sk>2016-10-03 13:41:59 +0200
commitdeb36b44d1a67157a44695ed7519605f431a3d89 (patch)
treeceb03644dad28e308a43d9ca9e19d7d7f9709888 /core/math
parentf468cfc379ec74b802edf0bc89d3f65225d9250d (diff)
Vector3: added angle_to(Vector3 other)
Diffstat (limited to 'core/math')
-rw-r--r--core/math/vector3.h12
1 files changed, 7 insertions, 5 deletions
diff --git a/core/math/vector3.h b/core/math/vector3.h
index 9d5da03a22..06840be5e7 100644
--- a/core/math/vector3.h
+++ b/core/math/vector3.h
@@ -100,6 +100,7 @@ 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_ real_t angle_to(const Vector3& p_b) const;
_FORCE_INLINE_ Vector3 slide(const Vector3& p_vec) const;
@@ -183,17 +184,21 @@ Vector3 Vector3::linear_interpolate(const Vector3& p_b,float p_t) const {
);
}
-
-
real_t Vector3::distance_to(const Vector3& p_b) const {
return (p_b-*this).length();
}
+
real_t Vector3::distance_squared_to(const Vector3& p_b) const {
return (p_b-*this).length_squared();
}
+real_t Vector3::angle_to(const Vector3& p_b) const {
+
+ return Math::acos(this->dot(p_b) / Math::sqrt(this->length_squared() * p_b.length_squared()));
+}
+
/* Operators */
Vector3& Vector3::operator+=(const Vector3& p_v) {
@@ -221,8 +226,6 @@ Vector3 Vector3::operator-(const Vector3& p_v) const {
return Vector3(x-p_v.x, y-p_v.y, z- p_v.z);
}
-
-
Vector3& Vector3::operator*=(const Vector3& p_v) {
x*=p_v.x;
@@ -284,7 +287,6 @@ Vector3 Vector3::operator-() const {
return Vector3( -x, -y, -z );
}
-
bool Vector3::operator==(const Vector3& p_v) const {
return (x==p_v.x && y==p_v.y && z==p_v.z);