| 0.9.9 API documenation

- Main Page
- Modules
- Files

- File List

type_vec4.hpp
Go to the documentation of this file.
1
4 #pragma once
5
6 #include "type_vec.hpp"
7 #if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
8 # if GLM_HAS_UNRESTRICTED_UNIONS
9 # include "_swizzle.hpp"
10 # else
11 # include "_swizzle_func.hpp"
12 # endif
13 #endif //GLM_SWIZZLE
14 #include <cstddef>
15
16 namespace glm
17 {
18 template<typename T, qualifier Q>
19 struct vec<4, T, Q>
20 {
21 // -- Implementation detail --
22
23 typedef T value_type;
24 typedef vec<4, T, Q> type;
25 typedef vec<4, bool, Q> bool_type;
26
27 // -- Data --
28
29 # if GLM_HAS_ONLY_XYZW
30 T x, y, z, w;
31
32 # elif GLM_HAS_ALIGNED_TYPE
33 # if GLM_COMPILER & GLM_COMPILER_GCC
34 # pragma GCC diagnostic push
35 # pragma GCC diagnostic ignored "-Wpedantic"
36 # endif
37 # if GLM_COMPILER & GLM_COMPILER_CLANG
38 # pragma clang diagnostic push
39 # pragma clang diagnostic ignored "-Wgnu-anonymous-struct"
40 # pragma clang diagnostic ignored "-Wnested-anon-types"
41 # endif
42
43 union
44 {
45 struct { T x, y, z, w;};
46 struct { T r, g, b, a; };
47 struct { T s, t, p, q; };
48
49 typename detail::storage<T, sizeof(T) * 4, detail::is_aligned<Q>::value>::type data;
50
51 # if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
52 GLM_SWIZZLE4_2_MEMBERS(T, Q, x, y, z, w)
53 GLM_SWIZZLE4_2_MEMBERS(T, Q, r, g, b, a)
54 GLM_SWIZZLE4_2_MEMBERS(T, Q, s, t, p, q)
55 GLM_SWIZZLE4_3_MEMBERS(T, Q, x, y, z, w)
56 GLM_SWIZZLE4_3_MEMBERS(T, Q, r, g, b, a)
57 GLM_SWIZZLE4_3_MEMBERS(T, Q, s, t, p, q)
58 GLM_SWIZZLE4_4_MEMBERS(T, Q, x, y, z, w)
59 GLM_SWIZZLE4_4_MEMBERS(T, Q, r, g, b, a)
60 GLM_SWIZZLE4_4_MEMBERS(T, Q, s, t, p, q)
61 # endif//GLM_SWIZZLE
62 };
63
64 # if GLM_COMPILER & GLM_COMPILER_CLANG
65 # pragma clang diagnostic pop
66 # endif
67 # if GLM_COMPILER & GLM_COMPILER_GCC
68 # pragma GCC diagnostic pop
69 # endif
70 # else
71 union { T x, r, s; };
72 union { T y, g, t; };
73 union { T z, b, p; };
74 union { T w, a, q; };
75
76 # if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
77 GLM_SWIZZLE_GEN_VEC_FROM_VEC4(T, P)
78 # endif//GLM_SWIZZLE
79 # endif
80
81 // -- Component accesses --
82
84 typedef length_t length_type;
85 GLM_FUNC_DECL static GLM_CONSTEXPR length_type length(){return 4;}
86
87 GLM_FUNC_DECL T & operator[](length_type i);
88 GLM_FUNC_DECL T const& operator[](length_type i) const;
89
90 // -- Implicit basic constructors --
91
92 GLM_FUNC_DECL GLM_CONSTEXPR_SIMD vec() GLM_DEFAULT;
93 GLM_FUNC_DECL GLM_CONSTEXPR_SIMD vec(vec<4, T, Q> const& v) GLM_DEFAULT;
94 template<qualifier P>
95 GLM_FUNC_DECL GLM_CONSTEXPR_SIMD vec(vec<4, T, P> const& v);
96
97 // -- Explicit basic constructors --
98
99 GLM_FUNC_DECL GLM_CONSTEXPR_SIMD explicit vec(T scalar);
100 GLM_FUNC_DECL GLM_CONSTEXPR_SIMD vec(T x, T y, T z, T w);
101
102 // -- Conversion scalar constructors --
103
105 template<typename X, typename Y, typename Z, typename W>
106 GLM_FUNC_DECL GLM_CONSTEXPR_SIMD vec(X _x, Y _y, Z _z, W _w);
107 template<typename X, typename Y, typename Z, typename W>
108 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(vec<1, X, Q> const& _x, vec<1, Y, Q> const& _Y, vec<1, Z, Q> const& _z, vec<1, W, Q> const& _w);
109
110 // -- Conversion vector constructors --
111
113 template<typename A, typename B, typename C, qualifier P>
114 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(vec<2, A, P> const& _xy, B _z, C _w);
116 template<typename A, typename B, typename C, qualifier P>
117 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(vec<2, A, P> const& _xy, vec<1, B, P> const& _z, vec<1, C, P> const& _w);
119 template<typename A, typename B, typename C, qualifier P>
120 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(A _x, vec<2, B, P> const& _yz, C _w);
122 template<typename A, typename B, typename C, qualifier P>
123 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(vec<1, A, P> const& _x, vec<2, B, P> const& _yz, vec<1, C, P> const& _w);
125 template<typename A, typename B, typename C, qualifier P>
126 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(A _x, B _y, vec<2, C, P> const& _zw);
128 template<typename A, typename B, typename C, qualifier P>
129 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(vec<1, A, P> const& _x, vec<1, B, P> const& _y, vec<2, C, P> const& _zw);
131 template<typename A, typename B, qualifier P>
132 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(vec<3, A, P> const& _xyz, B _w);
134 template<typename A, typename B, qualifier P>
135 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(vec<3, A, P> const& _xyz, vec<1, B, P> const& _w);
137 template<typename A, typename B, qualifier P>
138 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(A _x, vec<3, B, P> const& _yzw);
140 template<typename A, typename B, qualifier P>
141 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(vec<1, A, P> const& _x, vec<3, B, P> const& _yzw);
143 template<typename A, typename B, qualifier P>
144 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(vec<2, A, P> const& _xy, vec<2, B, P> const& _zw);
145
147 template<typename U, qualifier P>
148 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR GLM_EXPLICIT vec(vec<4, U, P> const& v);
149
150 // -- Swizzle constructors --
151 # if GLM_HAS_UNRESTRICTED_UNIONS && (GLM_SWIZZLE == GLM_SWIZZLE_ENABLED)
152 template<int E0, int E1, int E2, int E3>
153 GLM_FUNC_DECL vec(detail::_swizzle<4, T, Q, E0, E1, E2, E3> const& that)
154 {
155 *this = that();
156 }
157
158 template<int E0, int E1, int F0, int F1>
159 GLM_FUNC_DECL vec(detail::_swizzle<2, T, Q, E0, E1, -1, -2> const& v, detail::_swizzle<2, T, Q, F0, F1, -1, -2> const& u)
160 {
161 *this = vec<4, T, Q>(v(), u());
162 }
163
164 template<int E0, int E1>
165 GLM_FUNC_DECL vec(T const& x, T const& y, detail::_swizzle<2, T, Q, E0, E1, -1, -2> const& v)
166 {
167 *this = vec<4, T, Q>(x, y, v());
168 }
169
170 template<int E0, int E1>
171 GLM_FUNC_DECL vec(T const& x, detail::_swizzle<2, T, Q, E0, E1, -1, -2> const& v, T const& w)
172 {
173 *this = vec<4, T, Q>(x, v(), w);
174 }
175
176 template<int E0, int E1>
177 GLM_FUNC_DECL vec(detail::_swizzle<2, T, Q, E0, E1, -1, -2> const& v, T const& z, T const& w)
178 {
179 *this = vec<4, T, Q>(v(), z, w);
180 }
181
182 template<int E0, int E1, int E2>
183 GLM_FUNC_DECL vec(detail::_swizzle<3, T, Q, E0, E1, E2, -1> const& v, T const& w)
184 {
185 *this = vec<4, T, Q>(v(), w);
186 }
187
188 template<int E0, int E1, int E2>
189 GLM_FUNC_DECL vec(T const& x, detail::_swizzle<3, T, Q, E0, E1, E2, -1> const& v)
190 {
191 *this = vec<4, T, Q>(x, v());
192 }
193 # endif// GLM_HAS_UNRESTRICTED_UNIONS && (GLM_SWIZZLE == GLM_SWIZZLE_ENABLED)
194
195 // -- Unary arithmetic operators --
196
197 GLM_FUNC_DECL vec<4, T, Q>& operator=(vec<4, T, Q> const& v) GLM_DEFAULT;
198
199 template<typename U>
200 GLM_FUNC_DECL vec<4, T, Q>& operator=(vec<4, U, Q> const& v);
201 template<typename U>
202 GLM_FUNC_DECL vec<4, T, Q>& operator+=(U scalar);
203 template<typename U>
204 GLM_FUNC_DECL vec<4, T, Q>& operator+=(vec<1, U, Q> const& v);
205 template<typename U>
206 GLM_FUNC_DECL vec<4, T, Q>& operator+=(vec<4, U, Q> const& v);
207 template<typename U>
208 GLM_FUNC_DECL vec<4, T, Q>& operator-=(U scalar);
209 template<typename U>
210 GLM_FUNC_DECL vec<4, T, Q>& operator-=(vec<1, U, Q> const& v);
211 template<typename U>
212 GLM_FUNC_DECL vec<4, T, Q>& operator-=(vec<4, U, Q> const& v);
213 template<typename U>
214 GLM_FUNC_DECL vec<4, T, Q>& operator*=(U scalar);
215 template<typename U>
216 GLM_FUNC_DECL vec<4, T, Q>& operator*=(vec<1, U, Q> const& v);
217 template<typename U>
218 GLM_FUNC_DECL vec<4, T, Q>& operator*=(vec<4, U, Q> const& v);
219 template<typename U>
220 GLM_FUNC_DECL vec<4, T, Q>& operator/=(U scalar);
221 template<typename U>
222 GLM_FUNC_DECL vec<4, T, Q>& operator/=(vec<1, U, Q> const& v);
223 template<typename U>
224 GLM_FUNC_DECL vec<4, T, Q>& operator/=(vec<4, U, Q> const& v);
225
226 // -- Increment and decrement operators --
227
228 GLM_FUNC_DECL vec<4, T, Q> & operator++();
229 GLM_FUNC_DECL vec<4, T, Q> & operator--();
230 GLM_FUNC_DECL vec<4, T, Q> operator++(int);
231 GLM_FUNC_DECL vec<4, T, Q> operator--(int);
232
233 // -- Unary bit operators --
234
235 template<typename U>
236 GLM_FUNC_DECL vec<4, T, Q> & operator%=(U scalar);
237 template<typename U>
238 GLM_FUNC_DECL vec<4, T, Q> & operator%=(vec<1, U, Q> const& v);
239 template<typename U>
240 GLM_FUNC_DECL vec<4, T, Q> & operator%=(vec<4, U, Q> const& v);
241 template<typename U>
242 GLM_FUNC_DECL vec<4, T, Q> & operator&=(U scalar);
243 template<typename U>
244 GLM_FUNC_DECL vec<4, T, Q> & operator&=(vec<1, U, Q> const& v);
245 template<typename U>
246 GLM_FUNC_DECL vec<4, T, Q> & operator&=(vec<4, U, Q> const& v);
247 template<typename U>
248 GLM_FUNC_DECL vec<4, T, Q> & operator|=(U scalar);
249 template<typename U>
250 GLM_FUNC_DECL vec<4, T, Q> & operator|=(vec<1, U, Q> const& v);
251 template<typename U>
252 GLM_FUNC_DECL vec<4, T, Q> & operator|=(vec<4, U, Q> const& v);
253 template<typename U>
254 GLM_FUNC_DECL vec<4, T, Q> & operator^=(U scalar);
255 template<typename U>
256 GLM_FUNC_DECL vec<4, T, Q> & operator^=(vec<1, U, Q> const& v);
257 template<typename U>
258 GLM_FUNC_DECL vec<4, T, Q> & operator^=(vec<4, U, Q> const& v);
259 template<typename U>
260 GLM_FUNC_DECL vec<4, T, Q> & operator<<=(U scalar);
261 template<typename U>
262 GLM_FUNC_DECL vec<4, T, Q> & operator<<=(vec<1, U, Q> const& v);
263 template<typename U>
264 GLM_FUNC_DECL vec<4, T, Q> & operator<<=(vec<4, U, Q> const& v);
265 template<typename U>
266 GLM_FUNC_DECL vec<4, T, Q> & operator>>=(U scalar);
267 template<typename U>
268 GLM_FUNC_DECL vec<4, T, Q> & operator>>=(vec<1, U, Q> const& v);
269 template<typename U>
270 GLM_FUNC_DECL vec<4, T, Q> & operator>>=(vec<4, U, Q> const& v);
271 };
272
273 // -- Unary operators --
274
275 template<typename T, qualifier Q>
276 GLM_FUNC_DECL vec<4, T, Q> operator+(vec<4, T, Q> const& v);
277
278 template<typename T, qualifier Q>
279 GLM_FUNC_DECL vec<4, T, Q> operator-(vec<4, T, Q> const& v);
280
281 // -- Binary operators --
282
283 template<typename T, qualifier Q>
284 GLM_FUNC_DECL vec<4, T, Q> operator+(vec<4, T, Q> const& v, T scalar);
285
286 template<typename T, qualifier Q>
287 GLM_FUNC_DECL vec<4, T, Q> operator+(vec<4, T, Q> const& v1, vec<1, T, Q> const& v2);
288
289 template<typename T, qualifier Q>
290 GLM_FUNC_DECL vec<4, T, Q> operator+(T scalar, vec<4, T, Q> const& v);
291
292 template<typename T, qualifier Q>
293 GLM_FUNC_DECL vec<4, T, Q> operator+(vec<1, T, Q> const& v1, vec<4, T, Q> const& v2);
294
295 template<typename T, qualifier Q>
296 GLM_FUNC_DECL vec<4, T, Q> operator+(vec<4, T, Q> const& v1, vec<4, T, Q> const& v2);
297
298 template<typename T, qualifier Q>
299 GLM_FUNC_DECL vec<4, T, Q> operator-(vec<4, T, Q> const& v, T scalar);
300
301 template<typename T, qualifier Q>
302 GLM_FUNC_DECL vec<4, T, Q> operator-(vec<4, T, Q> const& v1, vec<1, T, Q> const& v2);
303
304 template<typename T, qualifier Q>
305 GLM_FUNC_DECL vec<4, T, Q> operator-(T scalar, vec<4, T, Q> const& v);
306
307 template<typename T, qualifier Q>
308 GLM_FUNC_DECL vec<4, T, Q> operator-(vec<1, T, Q> const& v1, vec<4, T, Q> const& v2);
309
310 template<typename T, qualifier Q>
311 GLM_FUNC_DECL vec<4, T, Q> operator-(vec<4, T, Q> const& v1, vec<4, T, Q> const& v2);
312
313 template<typename T, qualifier Q>
314 GLM_FUNC_DECL vec<4, T, Q> operator*(vec<4, T, Q> const& v, T scalar);
315
316 template<typename T, qualifier Q>
317 GLM_FUNC_DECL vec<4, T, Q> operator*(vec<4, T, Q> const& v1, vec<1, T, Q> const& v2);
318
319 template<typename T, qualifier Q>
320 GLM_FUNC_DECL vec<4, T, Q> operator*(T scalar, vec<4, T, Q> const& v);
321
322 template<typename T, qualifier Q>
323 GLM_FUNC_DECL vec<4, T, Q> operator*(vec<1, T, Q> const& v1, vec<4, T, Q> const& v2);
324
325 template<typename T, qualifier Q>
326 GLM_FUNC_DECL vec<4, T, Q> operator*(vec<4, T, Q> const& v1, vec<4, T, Q> const& v2);
327
328 template<typename T, qualifier Q>
329 GLM_FUNC_DECL vec<4, T, Q> operator/(vec<4, T, Q> const& v, T scalar);
330
331 template<typename T, qualifier Q>
332 GLM_FUNC_DECL vec<4, T, Q> operator/(vec<4, T, Q> const& v1, vec<1, T, Q> const& v2);
333
334 template<typename T, qualifier Q>
335 GLM_FUNC_DECL vec<4, T, Q> operator/(T scalar, vec<4, T, Q> const& v);
336
337 template<typename T, qualifier Q>
338 GLM_FUNC_DECL vec<4, T, Q> operator/(vec<1, T, Q> const& v1, vec<4, T, Q> const& v2);
339
340 template<typename T, qualifier Q>
341 GLM_FUNC_DECL vec<4, T, Q> operator/(vec<4, T, Q> const& v1, vec<4, T, Q> const& v2);
342
343 template<typename T, qualifier Q>
344 GLM_FUNC_DECL vec<4, T, Q> operator%(vec<4, T, Q> const& v, T scalar);
345
346 template<typename T, qualifier Q>
347 GLM_FUNC_DECL vec<4, T, Q> operator%(vec<4, T, Q> const& v, vec<1, T, Q> const& scalar);
348
349 template<typename T, qualifier Q>
350 GLM_FUNC_DECL vec<4, T, Q> operator%(T scalar, vec<4, T, Q> const& v);
351
352 template<typename T, qualifier Q>
353 GLM_FUNC_DECL vec<4, T, Q> operator%(vec<1, T, Q> const& scalar, vec<4, T, Q> const& v);
354
355 template<typename T, qualifier Q>
356 GLM_FUNC_DECL vec<4, T, Q> operator%(vec<4, T, Q> const& v1, vec<4, T, Q> const& v2);
357
358 template<typename T, qualifier Q>
359 GLM_FUNC_DECL vec<4, T, Q> operator&(vec<4, T, Q> const& v, T scalar);
360
361 template<typename T, qualifier Q>
362 GLM_FUNC_DECL vec<4, T, Q> operator&(vec<4, T, Q> const& v, vec<1, T, Q> const& scalar);
363
364 template<typename T, qualifier Q>
365 GLM_FUNC_DECL vec<4, T, Q> operator&(T scalar, vec<4, T, Q> const& v);
366
367 template<typename T, qualifier Q>
368 GLM_FUNC_DECL vec<4, T, Q> operator&(vec<1, T, Q> const& scalar, vec<4, T, Q> const& v);
369
370 template<typename T, qualifier Q>
371 GLM_FUNC_DECL vec<4, T, Q> operator&(vec<4, T, Q> const& v1, vec<4, T, Q> const& v2);
372
373 template<typename T, qualifier Q>
374 GLM_FUNC_DECL vec<4, T, Q> operator|(vec<4, T, Q> const& v, T scalar);
375
376 template<typename T, qualifier Q>
377 GLM_FUNC_DECL vec<4, T, Q> operator|(vec<4, T, Q> const& v, vec<1, T, Q> const& scalar);
378
379 template<typename T, qualifier Q>
380 GLM_FUNC_DECL vec<4, T, Q> operator|(T scalar, vec<4, T, Q> const& v);
381
382 template<typename T, qualifier Q>
383 GLM_FUNC_DECL vec<4, T, Q> operator|(vec<1, T, Q> const& scalar, vec<4, T, Q> const& v);
384
385 template<typename T, qualifier Q>
386 GLM_FUNC_DECL vec<4, T, Q> operator|(vec<4, T, Q> const& v1, vec<4, T, Q> const& v2);
387
388 template<typename T, qualifier Q>
389 GLM_FUNC_DECL vec<4, T, Q> operator^(vec<4, T, Q> const& v, T scalar);
390
391 template<typename T, qualifier Q>
392 GLM_FUNC_DECL vec<4, T, Q> operator^(vec<4, T, Q> const& v, vec<1, T, Q> const& scalar);
393
394 template<typename T, qualifier Q>
395 GLM_FUNC_DECL vec<4, T, Q> operator^(T scalar, vec<4, T, Q> const& v);
396
397 template<typename T, qualifier Q>
398 GLM_FUNC_DECL vec<4, T, Q> operator^(vec<1, T, Q> const& scalar, vec<4, T, Q> const& v);
399
400 template<typename T, qualifier Q>
401 GLM_FUNC_DECL vec<4, T, Q> operator^(vec<4, T, Q> const& v1, vec<4, T, Q> const& v2);
402
403 template<typename T, qualifier Q>
404 GLM_FUNC_DECL vec<4, T, Q> operator<<(vec<4, T, Q> const& v, T scalar);
405
406 template<typename T, qualifier Q>
407 GLM_FUNC_DECL vec<4, T, Q> operator<<(vec<4, T, Q> const& v, vec<1, T, Q> const& scalar);
408
409 template<typename T, qualifier Q>
410 GLM_FUNC_DECL vec<4, T, Q> operator<<(T scalar, vec<4, T, Q> const& v);
411
412 template<typename T, qualifier Q>
413 GLM_FUNC_DECL vec<4, T, Q> operator<<(vec<1, T, Q> const& scalar, vec<4, T, Q> const& v);
414
415 template<typename T, qualifier Q>
416 GLM_FUNC_DECL vec<4, T, Q> operator<<(vec<4, T, Q> const& v1, vec<4, T, Q> const& v2);
417
418 template<typename T, qualifier Q>
419 GLM_FUNC_DECL vec<4, T, Q> operator>>(vec<4, T, Q> const& v, T scalar);
420
421 template<typename T, qualifier Q>
422 GLM_FUNC_DECL vec<4, T, Q> operator>>(vec<4, T, Q> const& v, vec<1, T, Q> const& scalar);
423
424 template<typename T, qualifier Q>
425 GLM_FUNC_DECL vec<4, T, Q> operator>>(T scalar, vec<4, T, Q> const& v);
426
427 template<typename T, qualifier Q>
428 GLM_FUNC_DECL vec<4, T, Q> operator>>(vec<1, T, Q> const& scalar, vec<4, T, Q> const& v);
429
430 template<typename T, qualifier Q>
431 GLM_FUNC_DECL vec<4, T, Q> operator>>(vec<4, T, Q> const& v1, vec<4, T, Q> const& v2);
432
433 template<typename T, qualifier Q>
434 GLM_FUNC_DECL vec<4, T, Q> operator~(vec<4, T, Q> const& v);
435
436 // -- Boolean operators --
437
438 template<typename T, qualifier Q>
439 GLM_FUNC_DECL bool operator==(vec<4, T, Q> const& v1, vec<4, T, Q> const& v2);
440
441 template<typename T, qualifier Q>
442 GLM_FUNC_DECL bool operator!=(vec<4, T, Q> const& v1, vec<4, T, Q> const& v2);
443
444 template<qualifier Q>
445 GLM_FUNC_DECL vec<4, bool, Q> operator&&(vec<4, bool, Q> const& v1, vec<4, bool, Q> const& v2);
446
447 template<qualifier Q>
448 GLM_FUNC_DECL vec<4, bool, Q> operator||(vec<4, bool, Q> const& v1, vec<4, bool, Q> const& v2);
449 }//namespace glm
450
451 #ifndef GLM_EXTERNAL_TEMPLATE
452 #include "type_vec4.inl"
453 #endif//GLM_EXTERNAL_TEMPLATE
glm
Definition: common.hpp:20
glm::length
GLM_FUNC_DECL T length(vec< L, T, Q > const &x)
Returns the length of x, i.e., sqrt(x * x).
_swizzle_func.hpp
Core features
type_vec.hpp
Core features
_swizzle.hpp
Core features