diff options
-rw-r--r-- | core/math/vector3.h | 12 | ||||
-rw-r--r-- | core/variant_call.cpp | 2 |
2 files changed, 9 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); diff --git a/core/variant_call.cpp b/core/variant_call.cpp index 5f052bce8e..845cee05db 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -375,6 +375,7 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var VCALL_LOCALMEM0R(Vector3, ceil); VCALL_LOCALMEM1R(Vector3, distance_to); VCALL_LOCALMEM1R(Vector3, distance_squared_to); + VCALL_LOCALMEM1R(Vector3, angle_to); VCALL_LOCALMEM1R(Vector3, slide); VCALL_LOCALMEM1R(Vector3, reflect); @@ -1487,6 +1488,7 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_cl ADDFUNC0(VECTOR3,VECTOR3,Vector3,ceil,varray()); ADDFUNC1(VECTOR3,REAL,Vector3,distance_to,VECTOR3,"b",varray()); ADDFUNC1(VECTOR3,REAL,Vector3,distance_squared_to,VECTOR3,"b",varray()); + ADDFUNC1(VECTOR3,REAL,Vector3,angle_to,VECTOR3,"to",varray()); ADDFUNC1(VECTOR3,VECTOR3,Vector3,slide,VECTOR3,"by",varray()); ADDFUNC1(VECTOR3,VECTOR3,Vector3,reflect,VECTOR3,"by",varray()); |