type_quat.hpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. /// @ref gtc_quaternion
  2. /// @file glm/gtc/quaternion.hpp
  3. ///
  4. /// @see core (dependence)
  5. /// @see gtc_constants (dependence)
  6. ///
  7. /// @defgroup gtc_quaternion GLM_GTC_quaternion
  8. /// @ingroup gtc
  9. ///
  10. /// Include <glm/gtc/quaternion.hpp> to use the features of this extension.
  11. ///
  12. /// Defines a templated quaternion type and several quaternion operations.
  13. #pragma once
  14. // Dependency:
  15. #include "../detail/type_mat3x3.hpp"
  16. #include "../detail/type_mat4x4.hpp"
  17. #include "../detail/type_vec3.hpp"
  18. #include "../detail/type_vec4.hpp"
  19. #include "../ext/vector_relational.hpp"
  20. #include "../ext/quaternion_relational.hpp"
  21. #include "../gtc/constants.hpp"
  22. #include "../gtc/matrix_transform.hpp"
  23. namespace glm
  24. {
  25. /// @addtogroup gtc_quaternion
  26. /// @{
  27. template<typename T, qualifier Q>
  28. struct qua
  29. {
  30. // -- Implementation detail --
  31. typedef qua<T, Q> type;
  32. typedef T value_type;
  33. // -- Data --
  34. # if GLM_SILENT_WARNINGS == GLM_ENABLE
  35. # if GLM_COMPILER & GLM_COMPILER_GCC
  36. # pragma GCC diagnostic push
  37. # pragma GCC diagnostic ignored "-Wpedantic"
  38. # elif GLM_COMPILER & GLM_COMPILER_CLANG
  39. # pragma clang diagnostic push
  40. # pragma clang diagnostic ignored "-Wgnu-anonymous-struct"
  41. # pragma clang diagnostic ignored "-Wnested-anon-types"
  42. # elif GLM_COMPILER & GLM_COMPILER_VC
  43. # pragma warning(push)
  44. # pragma warning(disable: 4201) // nonstandard extension used : nameless struct/union
  45. # endif
  46. # endif
  47. # if GLM_LANG & GLM_LANG_CXXMS_FLAG
  48. union
  49. {
  50. struct { T x, y, z, w;};
  51. typename detail::storage<4, T, detail::is_aligned<Q>::value>::type data;
  52. };
  53. # else
  54. T x, y, z, w;
  55. # endif
  56. # if GLM_SILENT_WARNINGS == GLM_ENABLE
  57. # if GLM_COMPILER & GLM_COMPILER_CLANG
  58. # pragma clang diagnostic pop
  59. # elif GLM_COMPILER & GLM_COMPILER_GCC
  60. # pragma GCC diagnostic pop
  61. # elif GLM_COMPILER & GLM_COMPILER_VC
  62. # pragma warning(pop)
  63. # endif
  64. # endif
  65. // -- Component accesses --
  66. typedef length_t length_type;
  67. /// Return the count of components of a quaternion
  68. GLM_FUNC_DECL static GLM_CONSTEXPR length_type length(){return 4;}
  69. GLM_FUNC_DECL GLM_CONSTEXPR T & operator[](length_type i);
  70. GLM_FUNC_DECL GLM_CONSTEXPR T const& operator[](length_type i) const;
  71. // -- Implicit basic constructors --
  72. GLM_FUNC_DECL GLM_CONSTEXPR qua() GLM_DEFAULT;
  73. GLM_FUNC_DECL GLM_CONSTEXPR qua(qua<T, Q> const& q) GLM_DEFAULT;
  74. template<qualifier P>
  75. GLM_FUNC_DECL GLM_CONSTEXPR qua(qua<T, P> const& q);
  76. // -- Explicit basic constructors --
  77. GLM_FUNC_DECL GLM_CONSTEXPR qua(T s, vec<3, T, Q> const& v);
  78. GLM_FUNC_DECL GLM_CONSTEXPR qua(T w, T x, T y, T z);
  79. // -- Conversion constructors --
  80. template<typename U, qualifier P>
  81. GLM_FUNC_DECL GLM_CONSTEXPR GLM_EXPLICIT qua(qua<U, P> const& q);
  82. /// Explicit conversion operators
  83. # if GLM_HAS_EXPLICIT_CONVERSION_OPERATORS
  84. GLM_FUNC_DECL explicit operator mat<3, 3, T, Q>();
  85. GLM_FUNC_DECL explicit operator mat<4, 4, T, Q>();
  86. # endif
  87. /// Create a quaternion from two normalized axis
  88. ///
  89. /// @param u A first normalized axis
  90. /// @param v A second normalized axis
  91. /// @see gtc_quaternion
  92. /// @see http://lolengine.net/blog/2013/09/18/beautiful-maths-quaternion-from-vectors
  93. GLM_FUNC_DECL qua(vec<3, T, Q> const& u, vec<3, T, Q> const& v);
  94. /// Build a quaternion from euler angles (pitch, yaw, roll), in radians.
  95. GLM_FUNC_DECL GLM_EXPLICIT qua(vec<3, T, Q> const& eulerAngles);
  96. GLM_FUNC_DECL GLM_EXPLICIT qua(mat<3, 3, T, Q> const& q);
  97. GLM_FUNC_DECL GLM_EXPLICIT qua(mat<4, 4, T, Q> const& q);
  98. // -- Unary arithmetic operators --
  99. GLM_FUNC_DECL qua<T, Q>& operator=(qua<T, Q> const& q) GLM_DEFAULT;
  100. template<typename U>
  101. GLM_FUNC_DECL qua<T, Q>& operator=(qua<U, Q> const& q);
  102. template<typename U>
  103. GLM_FUNC_DECL qua<T, Q>& operator+=(qua<U, Q> const& q);
  104. template<typename U>
  105. GLM_FUNC_DECL qua<T, Q>& operator-=(qua<U, Q> const& q);
  106. template<typename U>
  107. GLM_FUNC_DECL qua<T, Q>& operator*=(qua<U, Q> const& q);
  108. template<typename U>
  109. GLM_FUNC_DECL qua<T, Q>& operator*=(U s);
  110. template<typename U>
  111. GLM_FUNC_DECL qua<T, Q>& operator/=(U s);
  112. };
  113. // -- Unary bit operators --
  114. template<typename T, qualifier Q>
  115. GLM_FUNC_DECL qua<T, Q> operator+(qua<T, Q> const& q);
  116. template<typename T, qualifier Q>
  117. GLM_FUNC_DECL qua<T, Q> operator-(qua<T, Q> const& q);
  118. // -- Binary operators --
  119. template<typename T, qualifier Q>
  120. GLM_FUNC_DECL qua<T, Q> operator+(qua<T, Q> const& q, qua<T, Q> const& p);
  121. template<typename T, qualifier Q>
  122. GLM_FUNC_DECL qua<T, Q> operator-(qua<T, Q> const& q, qua<T, Q> const& p);
  123. template<typename T, qualifier Q>
  124. GLM_FUNC_DECL qua<T, Q> operator*(qua<T, Q> const& q, qua<T, Q> const& p);
  125. template<typename T, qualifier Q>
  126. GLM_FUNC_DECL vec<3, T, Q> operator*(qua<T, Q> const& q, vec<3, T, Q> const& v);
  127. template<typename T, qualifier Q>
  128. GLM_FUNC_DECL vec<3, T, Q> operator*(vec<3, T, Q> const& v, qua<T, Q> const& q);
  129. template<typename T, qualifier Q>
  130. GLM_FUNC_DECL vec<4, T, Q> operator*(qua<T, Q> const& q, vec<4, T, Q> const& v);
  131. template<typename T, qualifier Q>
  132. GLM_FUNC_DECL vec<4, T, Q> operator*(vec<4, T, Q> const& v, qua<T, Q> const& q);
  133. template<typename T, qualifier Q>
  134. GLM_FUNC_DECL qua<T, Q> operator*(qua<T, Q> const& q, T const& s);
  135. template<typename T, qualifier Q>
  136. GLM_FUNC_DECL qua<T, Q> operator*(T const& s, qua<T, Q> const& q);
  137. template<typename T, qualifier Q>
  138. GLM_FUNC_DECL qua<T, Q> operator/(qua<T, Q> const& q, T const& s);
  139. // -- Boolean operators --
  140. template<typename T, qualifier Q>
  141. GLM_FUNC_DECL GLM_CONSTEXPR bool operator==(qua<T, Q> const& q1, qua<T, Q> const& q2);
  142. template<typename T, qualifier Q>
  143. GLM_FUNC_DECL GLM_CONSTEXPR bool operator!=(qua<T, Q> const& q1, qua<T, Q> const& q2);
  144. /// @}
  145. } //namespace glm
  146. #include "type_quat.inl"