From 3b55888fa125177f49588107746e881038c3b04c Mon Sep 17 00:00:00 2001 From: Diren D Bharwani Date: Fri, 16 Dec 2022 23:19:44 +0800 Subject: [PATCH] Added conversions to and from wxyz quaternion representations --- SHADE_Engine/src/Math/SHQuaternion.cpp | 12 ++++++++++++ SHADE_Engine/src/Math/SHQuaternion.h | 9 ++++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/SHADE_Engine/src/Math/SHQuaternion.cpp b/SHADE_Engine/src/Math/SHQuaternion.cpp index 8904cb05..1fa4e246 100644 --- a/SHADE_Engine/src/Math/SHQuaternion.cpp +++ b/SHADE_Engine/src/Math/SHQuaternion.cpp @@ -443,4 +443,16 @@ namespace SHADE return result; } + SHQuaternion SHQuaternion::FromWXYZ(float w, float x, float y, float z) noexcept + { + return SHQuaternion{ x, y, z, w }; + } + + void SHQuaternion::ToWXYZ(const SHQuaternion& from, float& w, float& x, float& y, float& z) noexcept + { + x = from.x; + y = from.y; + z = from.z; + w = from.w; + } } // namespace SHADE \ No newline at end of file diff --git a/SHADE_Engine/src/Math/SHQuaternion.h b/SHADE_Engine/src/Math/SHQuaternion.h index fa5b5d36..29f6df7e 100644 --- a/SHADE_Engine/src/Math/SHQuaternion.h +++ b/SHADE_Engine/src/Math/SHQuaternion.h @@ -125,9 +125,12 @@ namespace SHADE [[nodiscard]] static SHQuaternion ClampedLerp (const SHQuaternion& q1, const SHQuaternion& q2, float t, float tMin = 0.0f, float tMax = 1.0f) noexcept; [[nodiscard]] static SHQuaternion ClampedSlerp (const SHQuaternion& q1, const SHQuaternion& q2, float t, float tMin = 0.0f, float tMax = 1.0f) noexcept; - [[nodiscard]] static SHQuaternion FromToRotation (const SHVec3& from, const SHVec3& to) noexcept; - [[nodiscard]] static SHQuaternion LookRotation (const SHVec3& forward, const SHVec3& up) noexcept; - [[nodiscard]] static SHQuaternion RotateTowards (const SHQuaternion& from, const SHQuaternion& to, float maxAngleInRad) noexcept; + [[nodiscard]] static SHQuaternion FromToRotation (const SHVec3& from, const SHVec3& to) noexcept; + [[nodiscard]] static SHQuaternion LookRotation (const SHVec3& forward, const SHVec3& up) noexcept; + [[nodiscard]] static SHQuaternion RotateTowards (const SHQuaternion& from, const SHQuaternion& to, float maxAngleInRad) noexcept; + + [[nodiscard]] static SHQuaternion FromWXYZ (float w, float x, float y, float z) noexcept; + static void ToWXYZ (const SHQuaternion& from, float& w, float& x, float& y, float& z) noexcept; }; SHQuaternion operator*(float lhs, const SHQuaternion& rhs) noexcept;