Vector3: added angle_to(Vector3 other)

This commit is contained in:
J08nY 2016-10-01 21:20:09 +02:00
parent f468cfc379
commit deb36b44d1
No known key found for this signature in database
GPG key ID: 7F4A448FE68F329D
2 changed files with 9 additions and 5 deletions

View file

@ -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);

View file

@ -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());