• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 ///////////////////////////////////////////////////////////////////////////////////
2 /// OpenGL Mathematics (glm.g-truc.net)
3 ///
4 /// Copyright (c) 2005 - 2014 G-Truc Creation (www.g-truc.net)
5 /// Permission is hereby granted, free of charge, to any person obtaining a copy
6 /// of this software and associated documentation files (the "Software"), to deal
7 /// in the Software without restriction, including without limitation the rights
8 /// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 /// copies of the Software, and to permit persons to whom the Software is
10 /// furnished to do so, subject to the following conditions:
11 ///
12 /// The above copyright notice and this permission notice shall be included in
13 /// all copies or substantial portions of the Software.
14 ///
15 /// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 /// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 /// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 /// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 /// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 /// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 /// THE SOFTWARE.
22 ///
23 /// @ref gtx_quaternion
24 /// @file glm/gtx/quaternion.hpp
25 /// @date 2005-12-21 / 2011-06-07
26 /// @author Christophe Riccio
27 ///
28 /// @see core (dependence)
29 /// @see gtx_extented_min_max (dependence)
30 ///
31 /// @defgroup gtx_quaternion GLM_GTX_quaternion
32 /// @ingroup gtx
33 ///
34 /// @brief Extented quaternion types and functions
35 ///
36 /// <glm/gtx/quaternion.hpp> need to be included to use these functionalities.
37 ///////////////////////////////////////////////////////////////////////////////////
38 
39 #ifndef GLM_GTX_quaternion
40 #define GLM_GTX_quaternion
41 
42 // Dependency:
43 #include "../glm.hpp"
44 #include "../gtc/constants.hpp"
45 #include "../gtc/quaternion.hpp"
46 #include "../gtx/norm.hpp"
47 
48 #if(defined(GLM_MESSAGES) && !defined(GLM_EXT_INCLUDED))
49 #	pragma message("GLM: GLM_GTX_quaternion extension included")
50 #endif
51 
52 namespace glm
53 {
54 	/// @addtogroup gtx_quaternion
55 	/// @{
56 
57 	//! Compute a cross product between a quaternion and a vector.
58 	///
59 	/// @see gtx_quaternion
60 	template<typename T, precision P>
61 	GLM_FUNC_DECL detail::tvec3<T, P> cross(
62 		detail::tquat<T, P> const & q,
63 		detail::tvec3<T, P> const & v);
64 
65 	//! Compute a cross product between a vector and a quaternion.
66 	///
67 	/// @see gtx_quaternion
68 	template<typename T, precision P>
69 	GLM_FUNC_DECL detail::tvec3<T, P> cross(
70 		detail::tvec3<T, P> const & v,
71 		detail::tquat<T, P> const & q);
72 
73 	//! Compute a point on a path according squad equation.
74 	//! q1 and q2 are control points; s1 and s2 are intermediate control points.
75 	///
76 	/// @see gtx_quaternion
77 	template<typename T, precision P>
78 	GLM_FUNC_DECL detail::tquat<T, P> squad(
79 		detail::tquat<T, P> const & q1,
80 		detail::tquat<T, P> const & q2,
81 		detail::tquat<T, P> const & s1,
82 		detail::tquat<T, P> const & s2,
83 		T const & h);
84 
85 	//! Returns an intermediate control point for squad interpolation.
86 	///
87 	/// @see gtx_quaternion
88 	template<typename T, precision P>
89 	GLM_FUNC_DECL detail::tquat<T, P> intermediate(
90 		detail::tquat<T, P> const & prev,
91 		detail::tquat<T, P> const & curr,
92 		detail::tquat<T, P> const & next);
93 
94 	//! Returns a exp of a quaternion.
95 	///
96 	/// @see gtx_quaternion
97 	template<typename T, precision P>
98 	GLM_FUNC_DECL detail::tquat<T, P> exp(
99 		detail::tquat<T, P> const & q);
100 
101 	//! Returns a log of a quaternion.
102 	///
103 	/// @see gtx_quaternion
104 	template<typename T, precision P>
105 	GLM_FUNC_DECL detail::tquat<T, P> log(
106 		detail::tquat<T, P> const & q);
107 
108 	/// Returns x raised to the y power.
109 	///
110 	/// @see gtx_quaternion
111 	template<typename T, precision P>
112 	GLM_FUNC_DECL detail::tquat<T, P> pow(
113 		detail::tquat<T, P> const & x,
114 		T const & y);
115 
116 	//! Returns quarternion square root.
117 	///
118 	/// @see gtx_quaternion
119 	//template<typename T, precision P>
120 	//detail::tquat<T, P> sqrt(
121 	//	detail::tquat<T, P> const & q);
122 
123 	//! Rotates a 3 components vector by a quaternion.
124 	///
125 	/// @see gtx_quaternion
126 	template<typename T, precision P>
127 	GLM_FUNC_DECL detail::tvec3<T, P> rotate(
128 		detail::tquat<T, P> const & q,
129 		detail::tvec3<T, P> const & v);
130 
131 	/// Rotates a 4 components vector by a quaternion.
132 	///
133 	/// @see gtx_quaternion
134 	template<typename T, precision P>
135 	GLM_FUNC_DECL detail::tvec4<T, P> rotate(
136 		detail::tquat<T, P> const & q,
137 		detail::tvec4<T, P> const & v);
138 
139 	/// Extract the real component of a quaternion.
140 	///
141 	/// @see gtx_quaternion
142 	template<typename T, precision P>
143 	GLM_FUNC_DECL T extractRealComponent(
144 		detail::tquat<T, P> const & q);
145 
146 	/// Converts a quaternion to a 3 * 3 matrix.
147 	///
148 	/// @see gtx_quaternion
149 	template<typename T, precision P>
toMat3(detail::tquat<T,P> const & x)150 	GLM_FUNC_DECL detail::tmat3x3<T, P> toMat3(
151 		detail::tquat<T, P> const & x){return mat3_cast(x);}
152 
153 	/// Converts a quaternion to a 4 * 4 matrix.
154 	///
155 	/// @see gtx_quaternion
156 	template<typename T, precision P>
toMat4(detail::tquat<T,P> const & x)157 	GLM_FUNC_DECL detail::tmat4x4<T, P> toMat4(
158 		detail::tquat<T, P> const & x){return mat4_cast(x);}
159 
160 	/// Converts a 3 * 3 matrix to a quaternion.
161 	///
162 	/// @see gtx_quaternion
163 	template<typename T, precision P>
toQuat(detail::tmat3x3<T,P> const & x)164 	GLM_FUNC_DECL detail::tquat<T, P> toQuat(
165 		detail::tmat3x3<T, P> const & x){return quat_cast(x);}
166 
167 	/// Converts a 4 * 4 matrix to a quaternion.
168 	///
169 	/// @see gtx_quaternion
170 	template<typename T, precision P>
toQuat(detail::tmat4x4<T,P> const & x)171 	GLM_FUNC_DECL detail::tquat<T, P> toQuat(
172 		detail::tmat4x4<T, P> const & x){return quat_cast(x);}
173 
174 	/// Quaternion interpolation using the rotation short path.
175 	///
176 	/// @see gtx_quaternion
177 	template<typename T, precision P>
178 	GLM_FUNC_DECL detail::tquat<T, P> shortMix(
179 		detail::tquat<T, P> const & x,
180 		detail::tquat<T, P> const & y,
181 		T const & a);
182 
183 	/// Quaternion normalized linear interpolation.
184 	///
185 	/// @see gtx_quaternion
186 	template<typename T, precision P>
187 	GLM_FUNC_DECL detail::tquat<T, P> fastMix(
188 		detail::tquat<T, P> const & x,
189 		detail::tquat<T, P> const & y,
190 		T const & a);
191 
192 	/// Compute the rotation between two vectors.
193 	/// param orig vector, needs to be normalized
194 	/// param dest vector, needs to be normalized
195 	///
196 	/// @see gtx_quaternion
197 	template<typename T, precision P>
198 	GLM_FUNC_DECL detail::tquat<T, P> rotation(
199 		detail::tvec3<T, P> const & orig,
200 		detail::tvec3<T, P> const & dest);
201 
202 	/// Returns the squared length of x.
203 	///
204 	/// @see gtx_quaternion
205 	template<typename T, precision P>
206 	GLM_FUNC_DECL T length2(detail::tquat<T, P> const & q);
207 
208 	/// @}
209 }//namespace glm
210 
211 #include "quaternion.inl"
212 
213 #endif//GLM_GTX_quaternion
214