Added signed_angle_to for Vector3
This commit is contained in:
committed by
Aaron Franke
parent
7b2bad9571
commit
2c71ff1119
@@ -110,6 +110,7 @@ struct Vector3 {
|
||||
_FORCE_INLINE_ Vector3 project(const Vector3 &p_to) const;
|
||||
|
||||
_FORCE_INLINE_ real_t angle_to(const Vector3 &p_to) const;
|
||||
_FORCE_INLINE_ real_t signed_angle_to(const Vector3 &p_to, const Vector3 &p_axis) const;
|
||||
_FORCE_INLINE_ Vector3 direction_to(const Vector3 &p_to) const;
|
||||
|
||||
_FORCE_INLINE_ Vector3 slide(const Vector3 &p_normal) const;
|
||||
@@ -230,6 +231,13 @@ real_t Vector3::angle_to(const Vector3 &p_to) const {
|
||||
return Math::atan2(cross(p_to).length(), dot(p_to));
|
||||
}
|
||||
|
||||
real_t Vector3::signed_angle_to(const Vector3 &p_to, const Vector3 &p_axis) const {
|
||||
Vector3 cross_to = cross(p_to);
|
||||
real_t unsigned_angle = Math::atan2(cross_to.length(), dot(p_to));
|
||||
real_t sign = cross_to.dot(p_axis);
|
||||
return (sign < 0) ? -unsigned_angle : unsigned_angle;
|
||||
}
|
||||
|
||||
Vector3 Vector3::direction_to(const Vector3 &p_to) const {
|
||||
Vector3 ret(p_to.x - x, p_to.y - y, p_to.z - z);
|
||||
ret.normalize();
|
||||
|
||||
@@ -1059,6 +1059,7 @@ static void _register_variant_builtin_methods() {
|
||||
bind_method(Vector3, min_axis, sarray(), varray());
|
||||
bind_method(Vector3, max_axis, sarray(), varray());
|
||||
bind_method(Vector3, angle_to, sarray("to"), varray());
|
||||
bind_method(Vector3, signed_angle_to, sarray("to", "axis"), varray());
|
||||
bind_method(Vector3, direction_to, sarray("b"), varray());
|
||||
bind_method(Vector3, distance_to, sarray("b"), varray());
|
||||
bind_method(Vector3, distance_squared_to, sarray("b"), varray());
|
||||
|
||||
Reference in New Issue
Block a user