diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2022-11-03 12:07:33 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2022-11-03 12:07:33 +0100 |
commit | d0b7b698b00bd7ac93858d838b3f6a24d3f8fc30 (patch) | |
tree | c46edb2a889660836e987cb87e3cd393c1908914 /core | |
parent | 3cde6c0432d33ccc5f2c2cd9e2419a7f4c03502a (diff) | |
parent | 9e952c83869cd2c1d928beeb6493e635e2b690ff (diff) |
Merge pull request #68191 from aaronfranke/quat-euler-order
Allow getting Quaternion rotation in different Euler orders
Diffstat (limited to 'core')
-rw-r--r-- | core/math/quaternion.cpp | 18 | ||||
-rw-r--r-- | core/math/quaternion.h | 4 | ||||
-rw-r--r-- | core/variant/variant_call.cpp | 2 |
3 files changed, 4 insertions, 20 deletions
diff --git a/core/math/quaternion.cpp b/core/math/quaternion.cpp index 42b61f6dfe..942a0b766e 100644 --- a/core/math/quaternion.cpp +++ b/core/math/quaternion.cpp @@ -38,25 +38,11 @@ real_t Quaternion::angle_to(const Quaternion &p_to) const { return Math::acos(CLAMP(d * d * 2 - 1, -1, 1)); } -// get_euler_xyz returns a vector containing the Euler angles in the format -// (ax,ay,az), where ax is the angle of rotation around x axis, -// and similar for other axes. -// This implementation uses XYZ convention (Z is the first rotation). -Vector3 Quaternion::get_euler_xyz() const { - Basis m(*this); - return m.get_euler(EulerOrder::XYZ); -} - -// get_euler_yxz returns a vector containing the Euler angles in the format -// (ax,ay,az), where ax is the angle of rotation around x axis, -// and similar for other axes. -// This implementation uses YXZ convention (Z is the first rotation). -Vector3 Quaternion::get_euler_yxz() const { +Vector3 Quaternion::get_euler(EulerOrder p_order) const { #ifdef MATH_CHECKS ERR_FAIL_COND_V_MSG(!is_normalized(), Vector3(0, 0, 0), "The quaternion must be normalized."); #endif - Basis m(*this); - return m.get_euler(EulerOrder::YXZ); + return Basis(*this).get_euler(p_order); } void Quaternion::operator*=(const Quaternion &p_q) { diff --git a/core/math/quaternion.h b/core/math/quaternion.h index 7497f1643e..c5af2121d9 100644 --- a/core/math/quaternion.h +++ b/core/math/quaternion.h @@ -66,9 +66,7 @@ struct _NO_DISCARD_ Quaternion { _FORCE_INLINE_ real_t dot(const Quaternion &p_q) const; real_t angle_to(const Quaternion &p_to) const; - Vector3 get_euler_xyz() const; - Vector3 get_euler_yxz() const; - Vector3 get_euler() const { return get_euler_yxz(); }; + Vector3 get_euler(EulerOrder p_order = EulerOrder::YXZ) const; static Quaternion from_euler(const Vector3 &p_euler); Quaternion slerp(const Quaternion &p_to, const real_t &p_weight) const; diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp index f32233d808..7da46a2d05 100644 --- a/core/variant/variant_call.cpp +++ b/core/variant/variant_call.cpp @@ -1805,7 +1805,7 @@ static void _register_variant_builtin_methods() { bind_method(Quaternion, slerpni, sarray("to", "weight"), varray()); bind_method(Quaternion, spherical_cubic_interpolate, sarray("b", "pre_a", "post_b", "weight"), varray()); bind_method(Quaternion, spherical_cubic_interpolate_in_time, sarray("b", "pre_a", "post_b", "weight", "b_t", "pre_a_t", "post_b_t"), varray()); - bind_method(Quaternion, get_euler, sarray(), varray()); + bind_method(Quaternion, get_euler, sarray("order"), varray((int64_t)EulerOrder::YXZ)); bind_static_method(Quaternion, from_euler, sarray("euler"), varray()); bind_method(Quaternion, get_axis, sarray(), varray()); bind_method(Quaternion, get_angle, sarray(), varray()); |