/////////////////////////////////////////////////////////////////////////////////////////////////// // OpenGL Mathematics Copyright (c) 2005 - 2011 G-Truc Creation (www.g-truc.net) /////////////////////////////////////////////////////////////////////////////////////////////////// // Created : 2009-05-21 // Updated : 2010-02-04 // Licence : This source is under MIT License // File : glm/gtc/quaternion.hpp /////////////////////////////////////////////////////////////////////////////////////////////////// // Dependency: // - GLM core // - GLM_GTC_half_float /////////////////////////////////////////////////////////////////////////////////////////////////// // ToDo: // - Study constructors with angles and axis // - Study constructors with vec3 that are the imaginary component of quaternion /////////////////////////////////////////////////////////////////////////////////////////////////// #ifndef glm_gtc_quaternion #define glm_gtc_quaternion // Dependency: #include "../glm.hpp" #include "../gtc/half_float.hpp" #if(defined(GLM_MESSAGES) && !defined(glm_ext)) # pragma message("GLM: GLM_GTC_quaternion extension included") #endif namespace glm{ namespace detail { //! \brief Template for quaternion. //! From GLM_GTC_quaternion extension. /// \ingroup gtc_quaternion template struct tquat// : public genType { typedef T value_type; public: value_type x, y, z, w; // Constructors tquat(); explicit tquat( value_type const & s, tvec3 const & v); explicit tquat( value_type const & w, value_type const & x, value_type const & y, value_type const & z); // Convertions //explicit tquat(valType const & pitch, valType const & yaw, valType const & roll); //! pitch, yaw, roll explicit tquat( tvec3 const & eulerAngles); explicit tquat( tmat3x3 const & m); explicit tquat( tmat4x4 const & m); // Accesses value_type & operator[](int i); value_type const & operator[](int i) const; // Operators tquat & operator*=(value_type const & s); tquat & operator/=(value_type const & s); }; template detail::tquat operator- ( detail::tquat const & q); template detail::tquat operator* ( detail::tquat const & q, detail::tquat const & p); template detail::tvec3 operator* ( detail::tquat const & q, detail::tvec3 const & v); template detail::tvec3 operator* ( detail::tvec3 const & v, detail::tquat const & q); template detail::tvec4 operator* ( detail::tquat const & q, detail::tvec4 const & v); template detail::tvec4 operator* ( detail::tvec4 const & v, detail::tquat const & q); template detail::tquat operator* ( detail::tquat const & q, typename detail::tquat::value_type const & s); template detail::tquat operator* ( typename detail::tquat::value_type const & s, detail::tquat const & q); template detail::tquat operator/ ( detail::tquat const & q, typename detail::tquat::value_type const & s); } //namespace detail namespace gtc{ namespace quaternion ///< GLM_GTC_quaternion extension: Quaternion types and functions { /// \addtogroup gtc_quaternion ///@{ //! Returns the length of the quaternion x. //! From GLM_GTC_quaternion extension. template typename detail::tquat::value_type length( detail::tquat const & q); //! Returns the normalized quaternion of from x. //! From GLM_GTC_quaternion extension. template detail::tquat normalize( detail::tquat const & q); //! Returns dot product of q1 and q2, i.e., q1[0] * q2[0] + q1[1] * q2[1] + ... //! From GLM_GTC_quaternion extension. template typename detail::tquat::value_type dot( detail::tquat const & q1, detail::tquat const & q2); //! Returns the cross product of q1 and q2. //! From GLM_GTC_quaternion extension. template GLM_DEPRECATED detail::tquat cross( detail::tquat const & q1, detail::tquat const & q2); //! Returns a SLERP interpolated quaternion of x and y according a. //! From GLM_GTC_quaternion extension. template detail::tquat mix( detail::tquat const & x, detail::tquat const & y, typename detail::tquat::value_type const & a); //! Returns the q conjugate. //! From GLM_GTC_quaternion extension. template detail::tquat conjugate( detail::tquat const & q); //! Returns the q inverse. //! From GLM_GTC_quaternion extension. template detail::tquat inverse( detail::tquat const & q); //! Rotates a quaternion from an vector of 3 components axis and an angle expressed in degrees. //! From GLM_GTC_quaternion extension. template detail::tquat rotate( detail::tquat const & q, typename detail::tquat::value_type const & angle, detail::tvec3 const & v); //! Converts a quaternion to a 3 * 3 matrix. //! From GLM_GTC_quaternion extension. template detail::tmat3x3 mat3_cast( detail::tquat const & x); //! Converts a quaternion to a 4 * 4 matrix. //! From GLM_GTC_quaternion extension. template detail::tmat4x4 mat4_cast( detail::tquat const & x); //! Converts a 3 * 3 matrix to a quaternion. //! From GLM_GTC_quaternion extension. template detail::tquat quat_cast( detail::tmat3x3 const & x); //! Converts a 4 * 4 matrix to a quaternion. //! From GLM_GTC_quaternion extension. template detail::tquat quat_cast( detail::tmat4x4 const & x); //! Quaternion of floating-point numbers. //! From GLM_GTC_quaternion extension. typedef detail::tquat quat; //! Quaternion of half-precision floating-point numbers. //! From GLM_GTC_quaternion extension. typedef detail::tquat hquat; //! Quaternion of single-precision floating-point numbers. //! From GLM_GTC_quaternion extension. typedef detail::tquat fquat; //! Quaternion of double-precision floating-point numbers. //! From GLM_GTC_quaternion extension. typedef detail::tquat dquat; ///@} } //namespace quaternion } //namespace gtc } //namespace glm #include "quaternion.inl" namespace glm{using namespace gtc::quaternion;} #endif//glm_gtc_quaternion