From 3d377124c1c3b06f4a66e042de01dac4f71cbebe Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Sat, 28 Oct 2017 20:21:23 -1000 Subject: [PATCH] Implement CQuaternion::angleFrom() --- include/zeus/CQuaternion.hpp | 2 ++ src/CQuaternion.cpp | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/include/zeus/CQuaternion.hpp b/include/zeus/CQuaternion.hpp index b9b3d19..b539f55 100644 --- a/include/zeus/CQuaternion.hpp +++ b/include/zeus/CQuaternion.hpp @@ -274,6 +274,8 @@ public: zeus::CVector3f getImaginary() const { return {x, y, z}; } void setImaginary(const zeus::CVector3f& i) { x = i.x; y = i.y; z = i.z; } + CRelAngle angleFrom(const zeus::CQuaternion& other); + inline float& operator[](size_t idx) { return (&w)[idx]; } inline const float& operator[](size_t idx) const { return (&w)[idx]; } diff --git a/src/CQuaternion.cpp b/src/CQuaternion.cpp index c315b92..9297309 100644 --- a/src/CQuaternion.cpp +++ b/src/CQuaternion.cpp @@ -271,4 +271,10 @@ CQuaternion CQuaternion::buildEquivalent() const else return CQuaternion::fromAxisAngle(CUnitVector3f(x, y, z), tmp + 2.0 * M_PI); } + +CRelAngle CQuaternion::angleFrom(const zeus::CQuaternion& other) +{ + return std::acos(zeus::clamp(-1.f, dot(other), 1.f)); +} + }