0.9.6
simd_quat.hpp
Go to the documentation of this file.
1 
42 #pragma once
43 
44 // Dependency:
45 #include "../glm.hpp"
46 #include "../gtc/quaternion.hpp"
47 #include "../gtx/fast_trigonometry.hpp"
48 
49 #if(GLM_ARCH != GLM_ARCH_PURE)
50 
51 #if(GLM_ARCH & GLM_ARCH_SSE2)
52 # include "../gtx/simd_mat4.hpp"
53 #else
54 # error "GLM: GLM_GTX_simd_quat requires compiler support of SSE2 through intrinsics"
55 #endif
56 
57 #if(defined(GLM_MESSAGES) && !defined(GLM_EXT_INCLUDED))
58 # pragma message("GLM: GLM_GTX_simd_quat extension included")
59 #endif
60 
61 // Warning silencer for nameless struct/union.
62 #if (GLM_COMPILER & GLM_COMPILER_VC)
63 # pragma warning(push)
64 # pragma warning(disable:4201) // warning C4201: nonstandard extension used : nameless struct/union
65 #endif
66 
67 namespace glm{
68 namespace detail
69 {
70  GLM_ALIGNED_STRUCT(16) fquatSIMD
71  {
72  typedef __m128 value_type;
73  typedef std::size_t size_type;
74  static size_type value_size();
75 
76  typedef fquatSIMD type;
77  typedef tquat<bool, defaultp> bool_type;
78 
79 #ifdef GLM_SIMD_ENABLE_XYZW_UNION
80  union
81  {
82  __m128 Data;
83  struct {float x, y, z, w;};
84  };
85 #else
86  __m128 Data;
87 #endif
88 
90  // Implicit basic constructors
91 
92  fquatSIMD();
93  fquatSIMD(__m128 const & Data);
94  fquatSIMD(fquatSIMD const & q);
95 
97  // Explicit basic constructors
98 
99  explicit fquatSIMD(
100  ctor);
101  explicit fquatSIMD(
102  float const & w,
103  float const & x,
104  float const & y,
105  float const & z);
106  explicit fquatSIMD(
107  quat const & v);
108  explicit fquatSIMD(
109  vec3 const & eulerAngles);
110 
111 
113  // Unary arithmetic operators
114 
115  fquatSIMD& operator =(fquatSIMD const & q);
116  fquatSIMD& operator*=(float const & s);
117  fquatSIMD& operator/=(float const & s);
118  };
119 
120 
122  // Arithmetic operators
123 
124  detail::fquatSIMD operator- (
125  detail::fquatSIMD const & q);
126 
127  detail::fquatSIMD operator+ (
128  detail::fquatSIMD const & q,
129  detail::fquatSIMD const & p);
130 
131  detail::fquatSIMD operator* (
132  detail::fquatSIMD const & q,
133  detail::fquatSIMD const & p);
134 
135  detail::fvec4SIMD operator* (
136  detail::fquatSIMD const & q,
137  detail::fvec4SIMD const & v);
138 
139  detail::fvec4SIMD operator* (
140  detail::fvec4SIMD const & v,
141  detail::fquatSIMD const & q);
142 
143  detail::fquatSIMD operator* (
144  detail::fquatSIMD const & q,
145  float s);
146 
147  detail::fquatSIMD operator* (
148  float s,
149  detail::fquatSIMD const & q);
150 
151  detail::fquatSIMD operator/ (
152  detail::fquatSIMD const & q,
153  float s);
154 
155 }//namespace detail
156 
159 
160  typedef glm::detail::fquatSIMD simdQuat;
161 
164  quat quat_cast(
165  detail::fquatSIMD const & x);
166 
169  detail::fquatSIMD quatSIMD_cast(
170  detail::fmat4x4SIMD const & m);
171 
174  template <typename T, precision P>
175  detail::fquatSIMD quatSIMD_cast(
176  tmat4x4<T, P> const & m);
177 
180  template <typename T, precision P>
181  detail::fquatSIMD quatSIMD_cast(
182  tmat3x3<T, P> const & m);
183 
186  detail::fmat4x4SIMD mat4SIMD_cast(
187  detail::fquatSIMD const & q);
188 
191  mat4 mat4_cast(
192  detail::fquatSIMD const & q);
193 
194 
198  float length(
199  detail::fquatSIMD const & x);
200 
204  detail::fquatSIMD normalize(
205  detail::fquatSIMD const & x);
206 
210  float dot(
211  detail::fquatSIMD const & q1,
212  detail::fquatSIMD const & q2);
213 
224  detail::fquatSIMD mix(
225  detail::fquatSIMD const & x,
226  detail::fquatSIMD const & y,
227  float const & a);
228 
237  detail::fquatSIMD lerp(
238  detail::fquatSIMD const & x,
239  detail::fquatSIMD const & y,
240  float const & a);
241 
250  detail::fquatSIMD slerp(
251  detail::fquatSIMD const & x,
252  detail::fquatSIMD const & y,
253  float const & a);
254 
255 
266  detail::fquatSIMD fastMix(
267  detail::fquatSIMD const & x,
268  detail::fquatSIMD const & y,
269  float const & a);
270 
278  detail::fquatSIMD fastSlerp(
279  detail::fquatSIMD const & x,
280  detail::fquatSIMD const & y,
281  float const & a);
282 
283 
287  detail::fquatSIMD conjugate(
288  detail::fquatSIMD const & q);
289 
293  detail::fquatSIMD inverse(
294  detail::fquatSIMD const & q);
295 
302  detail::fquatSIMD angleAxisSIMD(
303  float const & angle,
304  vec3 const & axis);
305 
314  detail::fquatSIMD angleAxisSIMD(
315  float const & angle,
316  float const & x,
317  float const & y,
318  float const & z);
319 
320  // TODO: Move this to somewhere more appropriate. Used with fastMix() and fastSlerp().
322  __m128 fastSin(__m128 x);
323 
325 }//namespace glm
326 
327 #include "simd_quat.inl"
328 
329 
330 #if (GLM_COMPILER & GLM_COMPILER_VC)
331 # pragma warning(pop)
332 #endif
333 
334 
335 #endif//(GLM_ARCH != GLM_ARCH_PURE)
GLM_FUNC_DECL T fastSin(T angle)
Faster than the common sin function but less accurate.
GLM_FUNC_DECL tquat< T, P > quat_cast(tmat3x3< T, P > const &x)
Converts a 3 * 3 matrix to a quaternion.
GLM_FUNC_DECL tvec3< T, P > axis(tquat< T, P > const &x)
Returns the q rotation axis.
GLM_FUNC_DECL tquat< T, P > slerp(tquat< T, P > const &x, tquat< T, P > const &y, T const &a)
Spherical linear interpolation of two quaternions.
GLM_FUNC_DECL T angle(tquat< T, P > const &x)
Returns the quaternion rotation angle.
GLM_FUNC_DECL tvec3< T, P > eulerAngles(tquat< T, P > const &x)
Returns euler angles, yitch as x, yaw as y, roll as z.
GLM_FUNC_DECL T dot(vecType< T, P > const &x, vecType< T, P > const &y)
Returns the dot product of x and y, i.e., result = x * y.
mat4x4 mat4
4 columns of 4 components matrix of floating-point numbers.
Definition: type_mat.hpp:442
GLM_FUNC_DECL T length(vecType< T, P > const &x)
Returns the length of x, i.e., sqrt(x * x).
GLM_FUNC_DECL vecType< T, P > normalize(vecType< T, P > const &x)
Returns a vector in the same direction as x but with length of 1.
GLM_FUNC_DECL vecType< T, P > mix(vecType< T, P > const &x, vecType< T, P > const &y, vecType< U, P > const &a)
If genTypeU is a floating scalar or vector: Returns x * (1.0 - a) + y * a, i.e., the linear blend of ...
Definition: _noise.hpp:39
GLM_FUNC_DECL tquat< T, P > conjugate(tquat< T, P > const &q)
Returns the q conjugate.
highp_vec3 vec3
3 components vector of floating-point numbers.
Definition: type_vec.hpp:397
GLM_FUNC_DECL matType< T, P > inverse(matType< T, P > const &m)
Return the inverse of a squared matrix.
GLM_FUNC_DECL tmat4x4< T, P > mat4_cast(tquat< T, P > const &x)
Converts a quaternion to a 4 * 4 matrix.
GLM_FUNC_DECL tquat< T, P > fastMix(tquat< T, P > const &x, tquat< T, P > const &y, T const &a)
Quaternion normalized linear interpolation.
GLM_FUNC_DECL tquat< T, P > lerp(tquat< T, P > const &x, tquat< T, P > const &y, T const &a)
Linear interpolation of two quaternions.