summaryrefslogtreecommitdiff
path: root/core/math
diff options
context:
space:
mode:
authorAaron Franke <arnfranke@yahoo.com>2022-11-01 08:11:09 -0500
committerAaron Franke <arnfranke@yahoo.com>2022-11-01 09:28:12 -0500
commit83634119d42595498e42685556a577c12145e20b (patch)
treebdd670ec6732d4cf479f3185806331b16f3f6fc8 /core/math
parente6751549cf7247965d1744b8c464f5e901006f21 (diff)
Replace Quaternion Euler constructor with `from_euler` method
Diffstat (limited to 'core/math')
-rw-r--r--core/math/quaternion.cpp11
-rw-r--r--core/math/quaternion.h3
2 files changed, 7 insertions, 7 deletions
diff --git a/core/math/quaternion.cpp b/core/math/quaternion.cpp
index 6a5f29f3d8..79a4e62b56 100644
--- a/core/math/quaternion.cpp
+++ b/core/math/quaternion.cpp
@@ -330,7 +330,7 @@ Quaternion::Quaternion(const Vector3 &p_axis, real_t p_angle) {
// (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).
-Quaternion::Quaternion(const Vector3 &p_euler) {
+Quaternion Quaternion::from_euler(const Vector3 &p_euler) {
real_t half_a1 = p_euler.y * 0.5f;
real_t half_a2 = p_euler.x * 0.5f;
real_t half_a3 = p_euler.z * 0.5f;
@@ -346,8 +346,9 @@ Quaternion::Quaternion(const Vector3 &p_euler) {
real_t cos_a3 = Math::cos(half_a3);
real_t sin_a3 = Math::sin(half_a3);
- x = sin_a1 * cos_a2 * sin_a3 + cos_a1 * sin_a2 * cos_a3;
- y = sin_a1 * cos_a2 * cos_a3 - cos_a1 * sin_a2 * sin_a3;
- z = -sin_a1 * sin_a2 * cos_a3 + cos_a1 * cos_a2 * sin_a3;
- w = sin_a1 * sin_a2 * sin_a3 + cos_a1 * cos_a2 * cos_a3;
+ return Quaternion(
+ sin_a1 * cos_a2 * sin_a3 + cos_a1 * sin_a2 * cos_a3,
+ sin_a1 * cos_a2 * cos_a3 - cos_a1 * sin_a2 * sin_a3,
+ -sin_a1 * sin_a2 * cos_a3 + cos_a1 * cos_a2 * sin_a3,
+ sin_a1 * sin_a2 * sin_a3 + cos_a1 * cos_a2 * cos_a3);
}
diff --git a/core/math/quaternion.h b/core/math/quaternion.h
index 7aa400aa8c..7497f1643e 100644
--- a/core/math/quaternion.h
+++ b/core/math/quaternion.h
@@ -69,6 +69,7 @@ struct _NO_DISCARD_ Quaternion {
Vector3 get_euler_xyz() const;
Vector3 get_euler_yxz() const;
Vector3 get_euler() const { return get_euler_yxz(); };
+ static Quaternion from_euler(const Vector3 &p_euler);
Quaternion slerp(const Quaternion &p_to, const real_t &p_weight) const;
Quaternion slerpni(const Quaternion &p_to, const real_t &p_weight) const;
@@ -128,8 +129,6 @@ struct _NO_DISCARD_ Quaternion {
Quaternion(const Vector3 &p_axis, real_t p_angle);
- Quaternion(const Vector3 &p_euler);
-
Quaternion(const Quaternion &p_q) :
x(p_q.x),
y(p_q.y),