master
ブランチ master
ShaderPlayground / deps / glm / glm / gtx / quaternion.hpp
4.4 KB、174行 生 Blame 履歴
1/// @ref gtx_quaternion
2/// @file glm/gtx/quaternion.hpp
3///
4/// @see core (dependence)
5/// @see gtx_extented_min_max (dependence)
6///
7/// @defgroup gtx_quaternion GLM_GTX_quaternion
8/// @ingroup gtx
9///
10/// Include <glm/gtx/quaternion.hpp> to use the features of this extension.
11///
12/// Extented quaternion types and functions
13
14#pragma once
15
16// Dependency:
17#include "../glm.hpp"
18#include "../gtc/constants.hpp"
19#include "../gtc/quaternion.hpp"
20#include "../ext/quaternion_exponential.hpp"
21#include "../gtx/norm.hpp"
22
23#ifndef GLM_ENABLE_EXPERIMENTAL
24# error "GLM: GLM_GTX_quaternion is an experimental extension and may change in the future. Use #define GLM_ENABLE_EXPERIMENTAL before including it, if you really want to use it."
25#endif
26
27#if GLM_MESSAGES == GLM_ENABLE && !defined(GLM_EXT_INCLUDED)
28# pragma message("GLM: GLM_GTX_quaternion extension included")
29#endif
30
31namespace glm
32{
33 /// @addtogroup gtx_quaternion
34 /// @{
35
36 /// Create an identity quaternion.
37 ///
38 /// @see gtx_quaternion
39 template<typename T, qualifier Q>
40 GLM_FUNC_DECL qua<T, Q> quat_identity();
41
42 /// Compute a cross product between a quaternion and a vector.
43 ///
44 /// @see gtx_quaternion
45 template<typename T, qualifier Q>
46 GLM_FUNC_DECL vec<3, T, Q> cross(
47 qua<T, Q> const& q,
48 vec<3, T, Q> const& v);
49
50 //! Compute a cross product between a vector and a quaternion.
51 ///
52 /// @see gtx_quaternion
53 template<typename T, qualifier Q>
54 GLM_FUNC_DECL vec<3, T, Q> cross(
55 vec<3, T, Q> const& v,
56 qua<T, Q> const& q);
57
58 //! Compute a point on a path according squad equation.
59 //! q1 and q2 are control points; s1 and s2 are intermediate control points.
60 ///
61 /// @see gtx_quaternion
62 template<typename T, qualifier Q>
63 GLM_FUNC_DECL qua<T, Q> squad(
64 qua<T, Q> const& q1,
65 qua<T, Q> const& q2,
66 qua<T, Q> const& s1,
67 qua<T, Q> const& s2,
68 T const& h);
69
70 //! Returns an intermediate control point for squad interpolation.
71 ///
72 /// @see gtx_quaternion
73 template<typename T, qualifier Q>
74 GLM_FUNC_DECL qua<T, Q> intermediate(
75 qua<T, Q> const& prev,
76 qua<T, Q> const& curr,
77 qua<T, Q> const& next);
78
79 //! Returns quarternion square root.
80 ///
81 /// @see gtx_quaternion
82 //template<typename T, qualifier Q>
83 //qua<T, Q> sqrt(
84 // qua<T, Q> const& q);
85
86 //! Rotates a 3 components vector by a quaternion.
87 ///
88 /// @see gtx_quaternion
89 template<typename T, qualifier Q>
90 GLM_FUNC_DECL vec<3, T, Q> rotate(
91 qua<T, Q> const& q,
92 vec<3, T, Q> const& v);
93
94 /// Rotates a 4 components vector by a quaternion.
95 ///
96 /// @see gtx_quaternion
97 template<typename T, qualifier Q>
98 GLM_FUNC_DECL vec<4, T, Q> rotate(
99 qua<T, Q> const& q,
100 vec<4, T, Q> const& v);
101
102 /// Extract the real component of a quaternion.
103 ///
104 /// @see gtx_quaternion
105 template<typename T, qualifier Q>
106 GLM_FUNC_DECL T extractRealComponent(
107 qua<T, Q> const& q);
108
109 /// Converts a quaternion to a 3 * 3 matrix.
110 ///
111 /// @see gtx_quaternion
112 template<typename T, qualifier Q>
113 GLM_FUNC_DECL mat<3, 3, T, Q> toMat3(
114 qua<T, Q> const& x){return mat3_cast(x);}
115
116 /// Converts a quaternion to a 4 * 4 matrix.
117 ///
118 /// @see gtx_quaternion
119 template<typename T, qualifier Q>
120 GLM_FUNC_DECL mat<4, 4, T, Q> toMat4(
121 qua<T, Q> const& x){return mat4_cast(x);}
122
123 /// Converts a 3 * 3 matrix to a quaternion.
124 ///
125 /// @see gtx_quaternion
126 template<typename T, qualifier Q>
127 GLM_FUNC_DECL qua<T, Q> toQuat(
128 mat<3, 3, T, Q> const& x){return quat_cast(x);}
129
130 /// Converts a 4 * 4 matrix to a quaternion.
131 ///
132 /// @see gtx_quaternion
133 template<typename T, qualifier Q>
134 GLM_FUNC_DECL qua<T, Q> toQuat(
135 mat<4, 4, T, Q> const& x){return quat_cast(x);}
136
137 /// Quaternion interpolation using the rotation short path.
138 ///
139 /// @see gtx_quaternion
140 template<typename T, qualifier Q>
141 GLM_FUNC_DECL qua<T, Q> shortMix(
142 qua<T, Q> const& x,
143 qua<T, Q> const& y,
144 T const& a);
145
146 /// Quaternion normalized linear interpolation.
147 ///
148 /// @see gtx_quaternion
149 template<typename T, qualifier Q>
150 GLM_FUNC_DECL qua<T, Q> fastMix(
151 qua<T, Q> const& x,
152 qua<T, Q> const& y,
153 T const& a);
154
155 /// Compute the rotation between two vectors.
156 /// param orig vector, needs to be normalized
157 /// param dest vector, needs to be normalized
158 ///
159 /// @see gtx_quaternion
160 template<typename T, qualifier Q>
161 GLM_FUNC_DECL qua<T, Q> rotation(
162 vec<3, T, Q> const& orig,
163 vec<3, T, Q> const& dest);
164
165 /// Returns the squared length of x.
166 ///
167 /// @see gtx_quaternion
168 template<typename T, qualifier Q>
169 GLM_FUNC_DECL T length2(qua<T, Q> const& q);
170
171 /// @}
172}//namespace glm
173
174#include "quaternion.inl"