GLM  0.9.5
simd_quat.hpp
Go to the documentation of this file.
1 
38 #ifndef GLM_GTX_simd_quat
39 #define GLM_GTX_simd_quat
40 
41 // Dependency:
42 #include "../glm.hpp"
43 #include "../gtc/quaternion.hpp"
44 #include "../gtx/fast_trigonometry.hpp"
45 
46 #if(GLM_ARCH != GLM_ARCH_PURE)
47 
48 #if(GLM_ARCH & GLM_ARCH_SSE2)
49 # include "../core/intrinsic_common.hpp"
50 # include "../core/intrinsic_geometric.hpp"
51 # include "../gtx/simd_mat4.hpp"
52 #else
53 # error "GLM: GLM_GTX_simd_quat requires compiler support of SSE2 through intrinsics"
54 #endif
55 
56 #if(defined(GLM_MESSAGES) && !defined(GLM_EXT_INCLUDED))
57 # pragma message("GLM: GLM_GTX_simd_quat extension included")
58 #endif
59 
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 
68 namespace glm{
69 namespace detail
70 {
73  GLM_ALIGNED_STRUCT(16) fquatSIMD
74  {
75  enum ctor{null};
76  typedef __m128 value_type;
77  typedef std::size_t size_type;
78  static size_type value_size();
79 
80  typedef fquatSIMD type;
81  typedef tquat<bool, defaultp> bool_type;
82 
83 #ifdef GLM_SIMD_ENABLE_XYZW_UNION
84  union
85  {
86  __m128 Data;
87  struct {float x, y, z, w;};
88  };
89 #else
90  __m128 Data;
91 #endif
92 
94  // Implicit basic constructors
95 
96  fquatSIMD();
97  fquatSIMD(__m128 const & Data);
98  fquatSIMD(fquatSIMD const & q);
99 
101  // Explicit basic constructors
102 
103  explicit fquatSIMD(
104  ctor);
105  explicit fquatSIMD(
106  float const & w,
107  float const & x,
108  float const & y,
109  float const & z);
110  explicit fquatSIMD(
111  quat const & v);
112  explicit fquatSIMD(
113  vec3 const & eulerAngles);
114 
115 
117  // Unary arithmetic operators
118 
119  fquatSIMD& operator =(fquatSIMD const & q);
120  fquatSIMD& operator*=(float const & s);
121  fquatSIMD& operator/=(float const & s);
122  };
123 
124 
126  // Arithmetic operators
127 
128  detail::fquatSIMD operator- (
129  detail::fquatSIMD const & q);
130 
131  detail::fquatSIMD operator+ (
132  detail::fquatSIMD const & q,
133  detail::fquatSIMD const & p);
134 
135  detail::fquatSIMD operator* (
136  detail::fquatSIMD const & q,
137  detail::fquatSIMD const & p);
138 
139  detail::fvec4SIMD operator* (
140  detail::fquatSIMD const & q,
141  detail::fvec4SIMD const & v);
142 
143  detail::fvec4SIMD operator* (
144  detail::fvec4SIMD const & v,
145  detail::fquatSIMD const & q);
146 
147  detail::fquatSIMD operator* (
148  detail::fquatSIMD const & q,
149  float s);
150 
151  detail::fquatSIMD operator* (
152  float s,
153  detail::fquatSIMD const & q);
154 
155  detail::fquatSIMD operator/ (
156  detail::fquatSIMD const & q,
157  float s);
158 
159 }//namespace detail
160 
161  typedef glm::detail::fquatSIMD simdQuat;
162 
165 
168  quat quat_cast(
169  detail::fquatSIMD const & x);
170 
173  detail::fquatSIMD quatSIMD_cast(
174  detail::fmat4x4SIMD const & m);
175 
178  template <typename T, precision P>
179  detail::fquatSIMD quatSIMD_cast(
180  detail::tmat4x4<T, P> const & m);
181 
184  template <typename T, precision P>
185  detail::fquatSIMD quatSIMD_cast(
186  detail::tmat3x3<T, P> const & m);
187 
190  detail::fmat4x4SIMD mat4SIMD_cast(
191  detail::fquatSIMD const & q);
192 
195  mat4 mat4_cast(
196  detail::fquatSIMD const & q);
197 
198 
202  float length(
203  detail::fquatSIMD const & x);
204 
208  detail::fquatSIMD normalize(
209  detail::fquatSIMD const & x);
210 
214  float dot(
215  detail::fquatSIMD const & q1,
216  detail::fquatSIMD const & q2);
217 
228  detail::fquatSIMD mix(
229  detail::fquatSIMD const & x,
230  detail::fquatSIMD const & y,
231  float const & a);
232 
241  detail::fquatSIMD lerp(
242  detail::fquatSIMD const & x,
243  detail::fquatSIMD const & y,
244  float const & a);
245 
254  detail::fquatSIMD slerp(
255  detail::fquatSIMD const & x,
256  detail::fquatSIMD const & y,
257  float const & a);
258 
259 
270  detail::fquatSIMD fastMix(
271  detail::fquatSIMD const & x,
272  detail::fquatSIMD const & y,
273  float const & a);
274 
282  detail::fquatSIMD fastSlerp(
283  detail::fquatSIMD const & x,
284  detail::fquatSIMD const & y,
285  float const & a);
286 
287 
291  detail::fquatSIMD conjugate(
292  detail::fquatSIMD const & q);
293 
297  detail::fquatSIMD inverse(
298  detail::fquatSIMD const & q);
299 
306  detail::fquatSIMD angleAxisSIMD(
307  float const & angle,
308  vec3 const & axis);
309 
318  detail::fquatSIMD angleAxisSIMD(
319  float const & angle,
320  float const & x,
321  float const & y,
322  float const & z);
323 
324 
325  // TODO: Move this to somewhere more appropriate. Used with fastMix() and fastSlerp().
327  __m128 fastSin(__m128 x);
328 
329 
331 }//namespace glm
332 
333 #include "simd_quat.inl"
334 
335 
336 #if (GLM_COMPILER & GLM_COMPILER_VC)
337 # pragma warning(pop)
338 #endif
339 
340 
341 #endif//(GLM_ARCH != GLM_ARCH_PURE)
342 
343 #endif//GLM_GTX_simd_quat
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.
highp_vec3 vec3
3 components vector of floating-point numbers.
Definition: type_vec.hpp:414
GLM_FUNC_DECL detail::tquat< T, P > lerp(detail::tquat< T, P > const &x, detail::tquat< T, P > const &y, T const &a)
Linear interpolation of two quaternions.
GLM_FUNC_DECL detail::tquat< T, P > quat_cast(detail::tmat3x3< T, P > const &x)
Converts a 3 * 3 matrix to a quaternion.
GLM_FUNC_DECL genTypeT mix(genTypeT const &x, genTypeT const &y, genTypeU const &a)
If genTypeU is a floating scalar or vector: Returns x * (1.0 - a) + y * a, i.e., the linear blend of ...
GLM_FUNC_DECL T angle(detail::tquat< T, P > const &x)
Returns the quaternion rotation angle.
GLM_FUNC_DECL detail::tvec3< T, P > eulerAngles(detail::tquat< T, P > const &x)
Returns euler angles, yitch as x, yaw as y, roll as z.
mat4x4 mat4
4 columns of 4 components matrix of floating-point numbers.
Definition: type_mat.hpp:454
T fastSin(const T &angle)
Faster than the common sin function but less accurate.
GLM_FUNC_DECL genType normalize(genType const &x)
Returns a vector in the same direction as x but with length of 1.
GLM_FUNC_DECL detail::tmat4x4< T, P > mat4_cast(detail::tquat< T, P > const &x)
Converts a quaternion to a 4 * 4 matrix.
GLM_FUNC_DECL genType::value_type length(genType const &x)
Returns the length of x, i.e., sqrt(x * x).
highp_quat quat
Quaternion of default single-precision floating-point numbers.
Definition: fwd.hpp:69
GLM_FUNC_DECL matType< T, P > inverse(matType< T, P > const &m)
Return the inverse of a squared matrix.
detail::tquat< T, P > fastMix(detail::tquat< T, P > const &x, detail::tquat< T, P > const &y, T const &a)
Quaternion normalized linear interpolation.
GLM_FUNC_DECL detail::tvec3< T, P > axis(detail::tquat< T, P > const &x)
Returns the q rotation axis.
GLM_FUNC_DECL detail::tquat< T, P > slerp(detail::tquat< T, P > const &x, detail::tquat< T, P > const &y, T const &a)
Spherical linear interpolation of two quaternions.
GLM_FUNC_DECL detail::tquat< T, P > conjugate(detail::tquat< T, P > const &q)
Returns the q conjugate.