From cb017c5bca62e7798daa8a2f204ddeb0b31544a5 Mon Sep 17 00:00:00 2001 From: Christophe Riccio Date: Fri, 6 Apr 2012 21:04:46 +0100 Subject: [PATCH] Promoted angle axis interaction with quaternion --- glm/gtc/quaternion.hpp | 37 +++++++++++++++++++++++++ glm/gtc/quaternion.inl | 61 ++++++++++++++++++++++++++++++++++++++++++ glm/gtx/quaternion.hpp | 37 ------------------------- glm/gtx/quaternion.inl | 61 ------------------------------------------ 4 files changed, 98 insertions(+), 98 deletions(-) diff --git a/glm/gtc/quaternion.hpp b/glm/gtc/quaternion.hpp index 2a76ea00..a740f76d 100644 --- a/glm/gtc/quaternion.hpp +++ b/glm/gtc/quaternion.hpp @@ -241,6 +241,43 @@ namespace detail detail::tquat quat_cast( detail::tmat4x4 const & x); + /// Returns the quaternion rotation angle. + /// + /// @see gtc_quaternion + template + valType angle( + detail::tquat const & x); + + /// Returns the q rotation axis. + /// + /// @see gtc_quaternion + template + detail::tvec3 axis( + detail::tquat const & x); + + /// Build a quaternion from an angle and a normalized axis. + /// + /// @param angle Angle expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise. + /// + /// @see gtc_quaternion + template + detail::tquat angleAxis( + valType const & angle, + valType const & x, + valType const & y, + valType const & z); + + /// Build a quaternion from an angle and a normalized axis. + /// + /// @param angle Angle expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise. + /// @param axis Axis of the quaternion, must be normalized. + /// + /// @see gtc_quaternion + template + detail::tquat angleAxis( + valType const & angle, + detail::tvec3 const & axis); + /// Quaternion of floating-point numbers. /// /// @see gtc_quaternion diff --git a/glm/gtc/quaternion.inl b/glm/gtc/quaternion.inl index 046efb3e..e58acdf8 100644 --- a/glm/gtc/quaternion.inl +++ b/glm/gtc/quaternion.inl @@ -615,4 +615,65 @@ namespace detail return quat_cast(detail::tmat3x3(m4)); } + template + GLM_FUNC_QUALIFIER T angle + ( + detail::tquat const & x + ) + { +#ifdef GLM_FORCE_RADIANS + return acos(x.w) * T(2); +#else + return glm::degrees(acos(x.w) * T(2)); +#endif + } + + template + GLM_FUNC_QUALIFIER detail::tvec3 axis + ( + detail::tquat const & x + ) + { + T tmp1 = T(1) - x.w * x.w; + if(tmp1 <= T(0)) + return detail::tvec3(0, 0, 1); + T tmp2 = T(1) / sqrt(tmp1); + return detail::tvec3(x.x * tmp2, x.y * tmp2, x.z * tmp2); + } + + template + GLM_FUNC_QUALIFIER detail::tquat angleAxis + ( + valType const & angle, + valType const & x, + valType const & y, + valType const & z + ) + { + return angleAxis(angle, detail::tvec3(x, y, z)); + } + + template + GLM_FUNC_QUALIFIER detail::tquat angleAxis + ( + valType const & angle, + detail::tvec3 const & v + ) + { + detail::tquat result; + +#ifdef GLM_FORCE_RADIANS + valType a(angle); +#else + valType a(glm::radians(angle)); +#endif + valType s = glm::sin(a * valType(0.5)); + + result.w = glm::cos(a * valType(0.5)); + result.x = v.x * s; + result.y = v.y * s; + result.z = v.z * s; + return result; + } + }//namespace glm diff --git a/glm/gtx/quaternion.hpp b/glm/gtx/quaternion.hpp index 822ee5ab..21dd3039 100644 --- a/glm/gtx/quaternion.hpp +++ b/glm/gtx/quaternion.hpp @@ -134,43 +134,6 @@ namespace glm detail::tvec4 rotate( detail::tquat const & q, detail::tvec4 const & v); - - /// Returns the quaternion rotation angle. - /// - /// @see gtx_quaternion - template - valType angle( - detail::tquat const & x); - - /// Returns the q rotation axis. - /// - /// @see gtx_quaternion - template - detail::tvec3 axis( - detail::tquat const & x); - - /// Build a quaternion from an angle and a normalized axis. - /// - /// @param angle Angle expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise. - /// - /// @see gtx_quaternion - template - detail::tquat angleAxis( - valType const & angle, - valType const & x, - valType const & y, - valType const & z); - - /// Build a quaternion from an angle and a normalized axis. - /// - /// @param angle Angle expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise. - /// @param axis Axis of the quaternion, must be normalized. - /// - /// @see gtx_quaternion - template - detail::tquat angleAxis( - valType const & angle, - detail::tvec3 const & axis); /// Extract the real component of a quaternion. /// diff --git a/glm/gtx/quaternion.inl b/glm/gtx/quaternion.inl index b2e0efce..bf95f80f 100644 --- a/glm/gtx/quaternion.inl +++ b/glm/gtx/quaternion.inl @@ -141,67 +141,6 @@ namespace glm return q * v; } - template - GLM_FUNC_QUALIFIER T angle - ( - detail::tquat const & x - ) - { -#ifdef GLM_FORCE_RADIANS - return acos(x.w) * T(2); -#else - return glm::degrees(acos(x.w) * T(2)); -#endif - } - - template - GLM_FUNC_QUALIFIER detail::tvec3 axis - ( - detail::tquat const & x - ) - { - T tmp1 = T(1) - x.w * x.w; - if(tmp1 <= T(0)) - return detail::tvec3(0, 0, 1); - T tmp2 = T(1) / sqrt(tmp1); - return detail::tvec3(x.x * tmp2, x.y * tmp2, x.z * tmp2); - } - - template - GLM_FUNC_QUALIFIER detail::tquat angleAxis - ( - valType const & angle, - valType const & x, - valType const & y, - valType const & z - ) - { - return angleAxis(angle, detail::tvec3(x, y, z)); - } - - template - GLM_FUNC_QUALIFIER detail::tquat angleAxis - ( - valType const & angle, - detail::tvec3 const & v - ) - { - detail::tquat result; - -#ifdef GLM_FORCE_RADIANS - valType a(angle); -#else - valType a(glm::radians(angle)); -#endif - valType s = glm::sin(a * valType(0.5)); - - result.w = glm::cos(a * valType(0.5)); - result.x = v.x * s; - result.y = v.y * s; - result.z = v.z * s; - return result; - } - template GLM_FUNC_QUALIFIER T extractRealComponent (