From c068f22329d5cc722622a2183bbb22eef2093df7 Mon Sep 17 00:00:00 2001 From: Felix Morgner Date: Mon, 24 Aug 2026 11:16:07 +0200 Subject: initial import --- src/libraries/glm/gtc/quaternion.hpp | 381 +++++++++++++++++++++++++++++++++++ 1 file changed, 381 insertions(+) create mode 100755 src/libraries/glm/gtc/quaternion.hpp (limited to 'src/libraries/glm/gtc/quaternion.hpp') diff --git a/src/libraries/glm/gtc/quaternion.hpp b/src/libraries/glm/gtc/quaternion.hpp new file mode 100755 index 0000000..8e36a85 --- /dev/null +++ b/src/libraries/glm/gtc/quaternion.hpp @@ -0,0 +1,381 @@ +/////////////////////////////////////////////////////////////////////////////////// +/// OpenGL Mathematics (glm.g-truc.net) +/// +/// Copyright (c) 2005 - 2012 G-Truc Creation (www.g-truc.net) +/// Permission is hereby granted, free of charge, to any person obtaining a copy +/// of this software and associated documentation files (the "Software"), to deal +/// in the Software without restriction, including without limitation the rights +/// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +/// copies of the Software, and to permit persons to whom the Software is +/// furnished to do so, subject to the following conditions: +/// +/// The above copyright notice and this permission notice shall be included in +/// all copies or substantial portions of the Software. +/// +/// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +/// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +/// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +/// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +/// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +/// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +/// THE SOFTWARE. +/// +/// @ref gtc_quaternion +/// @file glm/gtc/quaternion.hpp +/// @date 2009-05-21 / 2012-12-20 +/// @author Christophe Riccio +/// +/// @see core (dependence) +/// @see gtc_half_float (dependence) +/// @see gtc_constants (dependence) +/// +/// @defgroup gtc_quaternion GLM_GTC_quaternion +/// @ingroup gtc +/// +/// @brief Defines a templated quaternion type and several quaternion operations. +/// +/// need to be included to use these functionalities. +/////////////////////////////////////////////////////////////////////////////////// + +#ifndef GLM_GTC_quaternion +#define GLM_GTC_quaternion GLM_VERSION + +// Dependency: +#include "../glm.hpp" +#include "../gtc/half_float.hpp" +#include "../gtc/constants.hpp" + +#if(defined(GLM_MESSAGES) && !defined(glm_ext)) +# pragma message("GLM: GLM_GTC_quaternion extension included") +#endif + +namespace glm{ +namespace detail +{ + template + struct tquat// : public genType + { + enum ctor{null}; + + typedef T value_type; + typedef std::size_t size_type; + + public: + value_type x, y, z, w; + + GLM_FUNC_DECL size_type length() const; + + // Constructors + tquat(); + explicit tquat( + value_type const & s, + glm::detail::tvec3 const & v); + explicit tquat( + value_type const & w, + value_type const & x, + value_type const & y, + value_type const & z); + + // Convertions + + /// Build a quaternion from euler angles (pitch, yaw, roll), in radians. + 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::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 + + /// @addtogroup gtc_quaternion + /// @{ + + /// Returns the length of the quaternion. + /// + /// @see gtc_quaternion + template + T length( + detail::tquat const & q); + + /// Returns the normalized quaternion. + /// + /// @see gtc_quaternion + 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] + ... + /// + /// @see gtc_quaternion + template + T dot( + detail::tquat const & q1, + detail::tquat const & q2); + + /// Spherical linear interpolation of two quaternions. + /// The interpolation is oriented and the rotation is performed at constant speed. + /// For short path spherical linear interpolation, use the slerp function. + /// + /// @param x A quaternion + /// @param y A quaternion + /// @param a Interpolation factor. The interpolation is defined beyond the range [0, 1]. + /// @tparam T Value type used to build the quaternion. Supported: half, float or double. + /// @see gtc_quaternion + /// @see - slerp(detail::tquat const & x, detail::tquat const & y, T const & a) + template + detail::tquat mix( + detail::tquat const & x, + detail::tquat const & y, + T const & a); + + /// Linear interpolation of two quaternions. + /// The interpolation is oriented. + /// + /// @param x A quaternion + /// @param y A quaternion + /// @param a Interpolation factor. The interpolation is defined in the range [0, 1]. + /// @tparam T Value type used to build the quaternion. Supported: half, float or double. + /// @see gtc_quaternion + template + detail::tquat lerp( + detail::tquat const & x, + detail::tquat const & y, + T const & a); + + /// Spherical linear interpolation of two quaternions. + /// The interpolation always take the short path and the rotation is performed at constant speed. + /// + /// @param x A quaternion + /// @param y A quaternion + /// @param a Interpolation factor. The interpolation is defined beyond the range [0, 1]. + /// @tparam T Value type used to build the quaternion. Supported: half, float or double. + /// @see gtc_quaternion + template + detail::tquat slerp( + detail::tquat const & x, + detail::tquat const & y, + T const & a); + + /// Returns the q conjugate. + /// + /// @see gtc_quaternion + template + detail::tquat conjugate( + detail::tquat const & q); + + /// Returns the q inverse. + /// + /// @see gtc_quaternion + template + detail::tquat inverse( + detail::tquat const & q); + + /// Rotates a quaternion from an vector of 3 components axis and an angle. + /// + /// @param q Source orientation + /// @param angle Angle expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise. + /// @param axis Axis of the rotation, must be normalized. + /// + /// @see gtc_quaternion + template + detail::tquat rotate( + detail::tquat const & q, + typename detail::tquat::value_type const & angle, + detail::tvec3 const & axis); + + /// Returns euler angles, yitch as x, yaw as y, roll as z. + /// + /// @see gtc_quaternion + template + detail::tvec3 eulerAngles( + detail::tquat const & x); + + /// Returns roll value of euler angles expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise. + /// + /// @see gtx_quaternion + template + valType roll( + detail::tquat const & x); + + /// Returns pitch value of euler angles expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise. + /// + /// @see gtx_quaternion + template + valType pitch( + detail::tquat const & x); + + /// Returns yaw value of euler angles expressed in radians if GLM_FORCE_RADIANS is define or degrees otherwise. + /// + /// @see gtx_quaternion + template + valType yaw( + detail::tquat const & x); + + /// Converts a quaternion to a 3 * 3 matrix. + /// + /// @see gtc_quaternion + template + detail::tmat3x3 mat3_cast( + detail::tquat const & x); + + /// Converts a quaternion to a 4 * 4 matrix. + /// + /// @see gtc_quaternion + template + detail::tmat4x4 mat4_cast( + detail::tquat const & x); + + /// Converts a 3 * 3 matrix to a quaternion. + /// + /// @see gtc_quaternion + template + detail::tquat quat_cast( + detail::tmat3x3 const & x); + + /// Converts a 4 * 4 matrix to a quaternion. + /// + /// @see gtc_quaternion + template + 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. + /// @param x x component of the x-axis, x, y, z must be a normalized axis + /// @param y y component of the y-axis, x, y, z must be a normalized axis + /// @param z z component of the z-axis, x, y, z must be a normalized axis + /// + /// @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 + typedef detail::tquat quat; + + /// Quaternion of half-precision floating-point numbers. + /// + /// @see gtc_quaternion + typedef detail::tquat hquat; + + /// Quaternion of single-precision floating-point numbers. + /// + /// @see gtc_quaternion + typedef detail::tquat fquat; + + /// Quaternion of double-precision floating-point numbers. + /// + /// @see gtc_quaternion + typedef detail::tquat dquat; + + /// Quaternion of low precision floating-point numbers. + /// + /// @see gtc_quaternion + typedef detail::tquat lowp_quat; + + /// Quaternion of medium precision floating-point numbers. + /// + /// @see gtc_quaternion + typedef detail::tquat mediump_quat; + + /// Quaternion of high precision floating-point numbers. + /// + /// @see gtc_quaternion + typedef detail::tquat highp_quat; + + /// @} +} //namespace glm + +#include "quaternion.inl" + +#endif//GLM_GTC_quaternion -- cgit v1.2.3