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 P>
19 struct vec<4, T, P>
20 {
21 // -- Implementation detail --
22
23 typedef T value_type;
24 typedef vec<4, T, P> type;
25 typedef vec<4, bool, P> 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<P>::value>::type data;
50
51 # if GLM_SWIZZLE == GLM_SWIZZLE_ENABLED
52 GLM_SWIZZLE4_2_MEMBERS(T, P, x, y, z, w)
53 GLM_SWIZZLE4_2_MEMBERS(T, P, r, g, b, a)
54 GLM_SWIZZLE4_2_MEMBERS(T, P, s, t, p, q)
55 GLM_SWIZZLE4_3_MEMBERS(T, P, x, y, z, w)
56 GLM_SWIZZLE4_3_MEMBERS(T, P, r, g, b, a)
57 GLM_SWIZZLE4_3_MEMBERS(T, P, s, t, p, q)
58 GLM_SWIZZLE4_4_MEMBERS(T, P, x, y, z, w)
59 GLM_SWIZZLE4_4_MEMBERS(T, P, r, g, b, a)
60 GLM_SWIZZLE4_4_MEMBERS(T, P, 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, P> const& v) GLM_DEFAULT;
94 template<qualifier Q>
95 GLM_FUNC_DECL GLM_CONSTEXPR_SIMD vec(vec<4, T, Q> 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, P> const& _x, vec<1, Y, P> const& _Y, vec<1, Z, P> const& _z, vec<1, W, P> const& _w);
109
110 // -- Conversion vector constructors --
111
113 template<typename A, typename B, typename C, qualifier Q>
114 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(vec<2, A, Q> const& _xy, B _z, C _w);
116 template<typename A, typename B, typename C, qualifier Q>
117 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(vec<2, A, Q> const& _xy, vec<1, B, Q> const& _z, vec<1, C, Q> const& _w);
119 template<typename A, typename B, typename C, qualifier Q>
120 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(A _x, vec<2, B, Q> const& _yz, C _w);
122 template<typename A, typename B, typename C, qualifier Q>
123 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(vec<1, A, Q> const& _x, vec<2, B, Q> const& _yz, vec<1, C, Q> const& _w);
125 template<typename A, typename B, typename C, qualifier Q>
126 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(A _x, B _y, vec<2, C, Q> const& _zw);
128 template<typename A, typename B, typename C, qualifier Q>
129 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(vec<1, A, Q> const& _x, vec<1, B, Q> const& _y, vec<2, C, Q> const& _zw);
131 template<typename A, typename B, qualifier Q>
132 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(vec<3, A, Q> const& _xyz, B _w);
134 template<typename A, typename B, qualifier Q>
135 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(vec<3, A, Q> const& _xyz, vec<1, B, Q> const& _w);
137 template<typename A, typename B, qualifier Q>
138 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(A _x, vec<3, B, Q> const& _yzw);
140 template<typename A, typename B, qualifier Q>
141 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(vec<1, A, Q> const& _x, vec<3, B, Q> const& _yzw);
143 template<typename A, typename B, qualifier Q>
144 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR vec(vec<2, A, Q> const& _xy, vec<2, B, Q> const& _zw);
145
147 template<typename U, qualifier Q>
148 GLM_FUNC_DECL GLM_CONSTEXPR_CTOR GLM_EXPLICIT vec(vec<4, U, Q> 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, P, 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, P, E0, E1, -1, -2> const & v, detail::_swizzle<2, T, P, F0, F1, -1, -2> const & u)
160 {
161 *this = vec<4, T, P>(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, P, E0, E1, -1, -2> const & v)
166 {
167 *this = vec<4, T, P>(x, y, v());
168 }
169
170 template<int E0, int E1>
171 GLM_FUNC_DECL vec(T const & x, detail::_swizzle<2, T, P, E0, E1, -1, -2> const & v, T const & w)
172 {
173 *this = vec<4, T, P>(x, v(), w);
174 }
175
176 template<int E0, int E1>
177 GLM_FUNC_DECL vec(detail::_swizzle<2, T, P, E0, E1, -1, -2> const & v, T const & z, T const & w)
178 {
179 *this = vec<4, T, P>(v(), z, w);
180 }
181
182 template<int E0, int E1, int E2>
183 GLM_FUNC_DECL vec(detail::_swizzle<3, T, P, E0, E1, E2, -1> const & v, T const & w)
184 {
185 *this = vec<4, T, P>(v(), w);
186 }
187
188 template<int E0, int E1, int E2>
189 GLM_FUNC_DECL vec(T const & x, detail::_swizzle<3, T, P, E0, E1, E2, -1> const & v)
190 {
191 *this = vec<4, T, P>(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, P>& operator=(vec<4, T, P> const & v) GLM_DEFAULT;
198
199 template<typename U>
200 GLM_FUNC_DECL vec<4, T, P>& operator=(vec<4, U, P> const & v);
201 template<typename U>
202 GLM_FUNC_DECL vec<4, T, P>& operator+=(U scalar);
203 template<typename U>
204 GLM_FUNC_DECL vec<4, T, P>& operator+=(vec<1, U, P> const & v);
205 template<typename U>
206 GLM_FUNC_DECL vec<4, T, P>& operator+=(vec<4, U, P> const & v);
207 template<typename U>
208 GLM_FUNC_DECL vec<4, T, P>& operator-=(U scalar);
209 template<typename U>
210 GLM_FUNC_DECL vec<4, T, P>& operator-=(vec<1, U, P> const & v);
211 template<typename U>
212 GLM_FUNC_DECL vec<4, T, P>& operator-=(vec<4, U, P> const & v);
213 template<typename U>
214 GLM_FUNC_DECL vec<4, T, P>& operator*=(U scalar);
215 template<typename U>
216 GLM_FUNC_DECL vec<4, T, P>& operator*=(vec<1, U, P> const& v);
217 template<typename U>
218 GLM_FUNC_DECL vec<4, T, P>& operator*=(vec<4, U, P> const& v);
219 template<typename U>
220 GLM_FUNC_DECL vec<4, T, P>& operator/=(U scalar);
221 template<typename U>
222 GLM_FUNC_DECL vec<4, T, P>& operator/=(vec<1, U, P> const & v);
223 template<typename U>
224 GLM_FUNC_DECL vec<4, T, P>& operator/=(vec<4, U, P> const & v);
225
226 // -- Increment and decrement operators --
227
228 GLM_FUNC_DECL vec<4, T, P> & operator++();
229 GLM_FUNC_DECL vec<4, T, P> & operator--();
230 GLM_FUNC_DECL vec<4, T, P> operator++(int);
231 GLM_FUNC_DECL vec<4, T, P> operator--(int);
232
233 // -- Unary bit operators --
234
235 template<typename U>
236 GLM_FUNC_DECL vec<4, T, P> & operator%=(U scalar);
237 template<typename U>
238 GLM_FUNC_DECL vec<4, T, P> & operator%=(vec<1, U, P> const & v);
239 template<typename U>
240 GLM_FUNC_DECL vec<4, T, P> & operator%=(vec<4, U, P> const & v);
241 template<typename U>
242 GLM_FUNC_DECL vec<4, T, P> & operator&=(U scalar);
243 template<typename U>
244 GLM_FUNC_DECL vec<4, T, P> & operator&=(vec<1, U, P> const & v);
245 template<typename U>
246 GLM_FUNC_DECL vec<4, T, P> & operator&=(vec<4, U, P> const & v);
247 template<typename U>
248 GLM_FUNC_DECL vec<4, T, P> & operator|=(U scalar);
249 template<typename U>
250 GLM_FUNC_DECL vec<4, T, P> & operator|=(vec<1, U, P> const & v);
251 template<typename U>
252 GLM_FUNC_DECL vec<4, T, P> & operator|=(vec<4, U, P> const & v);
253 template<typename U>
254 GLM_FUNC_DECL vec<4, T, P> & operator^=(U scalar);
255 template<typename U>
256 GLM_FUNC_DECL vec<4, T, P> & operator^=(vec<1, U, P> const & v);
257 template<typename U>
258 GLM_FUNC_DECL vec<4, T, P> & operator^=(vec<4, U, P> const & v);
259 template<typename U>
260 GLM_FUNC_DECL vec<4, T, P> & operator<<=(U scalar);
261 template<typename U>
262 GLM_FUNC_DECL vec<4, T, P> & operator<<=(vec<1, U, P> const & v);
263 template<typename U>
264 GLM_FUNC_DECL vec<4, T, P> & operator<<=(vec<4, U, P> const & v);
265 template<typename U>
266 GLM_FUNC_DECL vec<4, T, P> & operator>>=(U scalar);
267 template<typename U>
268 GLM_FUNC_DECL vec<4, T, P> & operator>>=(vec<1, U, P> const & v);
269 template<typename U>
270 GLM_FUNC_DECL vec<4, T, P> & operator>>=(vec<4, U, P> const & v);
271 };
272
273 // -- Unary operators --
274
275 template<typename T, qualifier P>
276 GLM_FUNC_DECL vec<4, T, P> operator+(vec<4, T, P> const & v);
277
278 template<typename T, qualifier P>
279 GLM_FUNC_DECL vec<4, T, P> operator-(vec<4, T, P> const & v);
280
281 // -- Binary operators --
282
283 template<typename T, qualifier P>
284 GLM_FUNC_DECL vec<4, T, P> operator+(vec<4, T, P> const & v, T scalar);
285
286 template<typename T, qualifier P>
287 GLM_FUNC_DECL vec<4, T, P> operator+(vec<4, T, P> const & v1, vec<1, T, P> const & v2);
288
289 template<typename T, qualifier P>
290 GLM_FUNC_DECL vec<4, T, P> operator+(T scalar, vec<4, T, P> const & v);
291
292 template<typename T, qualifier P>
293 GLM_FUNC_DECL vec<4, T, P> operator+(vec<1, T, P> const & v1, vec<4, T, P> const & v2);
294
295 template<typename T, qualifier P>
296 GLM_FUNC_DECL vec<4, T, P> operator+(vec<4, T, P> const & v1, vec<4, T, P> const & v2);
297
298 template<typename T, qualifier P>
299 GLM_FUNC_DECL vec<4, T, P> operator-(vec<4, T, P> const & v, T scalar);
300
301 template<typename T, qualifier P>
302 GLM_FUNC_DECL vec<4, T, P> operator-(vec<4, T, P> const & v1, vec<1, T, P> const & v2);
303
304 template<typename T, qualifier P>
305 GLM_FUNC_DECL vec<4, T, P> operator-(T scalar, vec<4, T, P> const & v);
306
307 template<typename T, qualifier P>
308 GLM_FUNC_DECL vec<4, T, P> operator-(vec<1, T, P> const & v1, vec<4, T, P> const & v2);
309
310 template<typename T, qualifier P>
311 GLM_FUNC_DECL vec<4, T, P> operator-(vec<4, T, P> const & v1, vec<4, T, P> const & v2);
312
313 template<typename T, qualifier P>
314 GLM_FUNC_DECL vec<4, T, P> operator*(vec<4, T, P> const & v, T scalar);
315
316 template<typename T, qualifier P>
317 GLM_FUNC_DECL vec<4, T, P> operator*(vec<4, T, P> const & v1, vec<1, T, P> const & v2);
318
319 template<typename T, qualifier P>
320 GLM_FUNC_DECL vec<4, T, P> operator*(T scalar, vec<4, T, P> const & v);
321
322 template<typename T, qualifier P>
323 GLM_FUNC_DECL vec<4, T, P> operator*(vec<1, T, P> const & v1, vec<4, T, P> const & v2);
324
325 template<typename T, qualifier P>
326 GLM_FUNC_DECL vec<4, T, P> operator*(vec<4, T, P> const & v1, vec<4, T, P> const & v2);
327
328 template<typename T, qualifier P>
329 GLM_FUNC_DECL vec<4, T, P> operator/(vec<4, T, P> const & v, T scalar);
330
331 template<typename T, qualifier P>
332 GLM_FUNC_DECL vec<4, T, P> operator/(vec<4, T, P> const & v1, vec<1, T, P> const & v2);
333
334 template<typename T, qualifier P>
335 GLM_FUNC_DECL vec<4, T, P> operator/(T scalar, vec<4, T, P> const & v);
336
337 template<typename T, qualifier P>
338 GLM_FUNC_DECL vec<4, T, P> operator/(vec<1, T, P> const & v1, vec<4, T, P> const & v2);
339
340 template<typename T, qualifier P>
341 GLM_FUNC_DECL vec<4, T, P> operator/(vec<4, T, P> const & v1, vec<4, T, P> const & v2);
342
343 template<typename T, qualifier P>
344 GLM_FUNC_DECL vec<4, T, P> operator%(vec<4, T, P> const & v, T scalar);
345
346 template<typename T, qualifier P>
347 GLM_FUNC_DECL vec<4, T, P> operator%(vec<4, T, P> const & v, vec<1, T, P> const & scalar);
348
349 template<typename T, qualifier P>
350 GLM_FUNC_DECL vec<4, T, P> operator%(T scalar, vec<4, T, P> const & v);
351
352 template<typename T, qualifier P>
353 GLM_FUNC_DECL vec<4, T, P> operator%(vec<1, T, P> const & scalar, vec<4, T, P> const & v);
354
355 template<typename T, qualifier P>
356 GLM_FUNC_DECL vec<4, T, P> operator%(vec<4, T, P> const & v1, vec<4, T, P> const & v2);
357
358 template<typename T, qualifier P>
359 GLM_FUNC_DECL vec<4, T, P> operator&(vec<4, T, P> const & v, T scalar);
360
361 template<typename T, qualifier P>
362 GLM_FUNC_DECL vec<4, T, P> operator&(vec<4, T, P> const & v, vec<1, T, P> const & scalar);
363
364 template<typename T, qualifier P>
365 GLM_FUNC_DECL vec<4, T, P> operator&(T scalar, vec<4, T, P> const & v);
366
367 template<typename T, qualifier P>
368 GLM_FUNC_DECL vec<4, T, P> operator&(vec<1, T, P> const & scalar, vec<4, T, P> const & v);
369
370 template<typename T, qualifier P>
371 GLM_FUNC_DECL vec<4, T, P> operator&(vec<4, T, P> const & v1, vec<4, T, P> const & v2);
372
373 template<typename T, qualifier P>
374 GLM_FUNC_DECL vec<4, T, P> operator|(vec<4, T, P> const & v, T scalar);
375
376 template<typename T, qualifier P>
377 GLM_FUNC_DECL vec<4, T, P> operator|(vec<4, T, P> const & v, vec<1, T, P> const & scalar);
378
379 template<typename T, qualifier P>
380 GLM_FUNC_DECL vec<4, T, P> operator|(T scalar, vec<4, T, P> const & v);
381
382 template<typename T, qualifier P>
383 GLM_FUNC_DECL vec<4, T, P> operator|(vec<1, T, P> const & scalar, vec<4, T, P> const & v);
384
385 template<typename T, qualifier P>
386 GLM_FUNC_DECL vec<4, T, P> operator|(vec<4, T, P> const & v1, vec<4, T, P> const & v2);
387
388 template<typename T, qualifier P>
389 GLM_FUNC_DECL vec<4, T, P> operator^(vec<4, T, P> const & v, T scalar);
390
391 template<typename T, qualifier P>
392 GLM_FUNC_DECL vec<4, T, P> operator^(vec<4, T, P> const & v, vec<1, T, P> const & scalar);
393
394 template<typename T, qualifier P>
395 GLM_FUNC_DECL vec<4, T, P> operator^(T scalar, vec<4, T, P> const & v);
396
397 template<typename T, qualifier P>
398 GLM_FUNC_DECL vec<4, T, P> operator^(vec<1, T, P> const & scalar, vec<4, T, P> const & v);
399
400 template<typename T, qualifier P>
401 GLM_FUNC_DECL vec<4, T, P> operator^(vec<4, T, P> const & v1, vec<4, T, P> const & v2);
402
403 template<typename T, qualifier P>
404 GLM_FUNC_DECL vec<4, T, P> operator<<(vec<4, T, P> const & v, T scalar);
405
406 template<typename T, qualifier P>
407 GLM_FUNC_DECL vec<4, T, P> operator<<(vec<4, T, P> const & v, vec<1, T, P> const & scalar);
408
409 template<typename T, qualifier P>
410 GLM_FUNC_DECL vec<4, T, P> operator<<(T scalar, vec<4, T, P> const & v);
411
412 template<typename T, qualifier P>
413 GLM_FUNC_DECL vec<4, T, P> operator<<(vec<1, T, P> const & scalar, vec<4, T, P> const & v);
414
415 template<typename T, qualifier P>
416 GLM_FUNC_DECL vec<4, T, P> operator<<(vec<4, T, P> const & v1, vec<4, T, P> const & v2);
417
418 template<typename T, qualifier P>
419 GLM_FUNC_DECL vec<4, T, P> operator>>(vec<4, T, P> const & v, T scalar);
420
421 template<typename T, qualifier P>
422 GLM_FUNC_DECL vec<4, T, P> operator>>(vec<4, T, P> const & v, vec<1, T, P> const & scalar);
423
424 template<typename T, qualifier P>
425 GLM_FUNC_DECL vec<4, T, P> operator>>(T scalar, vec<4, T, P> const & v);
426
427 template<typename T, qualifier P>
428 GLM_FUNC_DECL vec<4, T, P> operator>>(vec<1, T, P> const & scalar, vec<4, T, P> const & v);
429
430 template<typename T, qualifier P>
431 GLM_FUNC_DECL vec<4, T, P> operator>>(vec<4, T, P> const & v1, vec<4, T, P> const & v2);
432
433 template<typename T, qualifier P>
434 GLM_FUNC_DECL vec<4, T, P> operator~(vec<4, T, P> const & v);
435
436 // -- Boolean operators --
437
438 template<typename T, qualifier P>
439 GLM_FUNC_DECL bool operator==(vec<4, T, P> const & v1, vec<4, T, P> const & v2);
440
441 template<typename T, qualifier P>
442 GLM_FUNC_DECL bool operator!=(vec<4, T, P> const & v1, vec<4, T, P> const & v2);
443
444 template<qualifier P>
445 GLM_FUNC_DECL vec<4, bool, P> operator&&(vec<4, bool, P> const & v1, vec<4, bool, P> const & v2);
446
447 template<qualifier P>
448 GLM_FUNC_DECL vec<4, bool, P> operator||(vec<4, bool, P> const & v1, vec<4, bool, P> const & v2);
449 }//namespace glm
450
451 #ifndef GLM_EXTERNAL_TEMPLATE
452 #include "type_vec4.inl"
453 #endif//GLM_EXTERNAL_TEMPLATE
glm
Definition: _noise.hpp:11
_swizzle_func.hpp
GLM Core
glm::length
GLM_FUNC_DECL T length(vec< L, T, P > const &x)
Returns the length of x, i.e., sqrt(x * x).
type_vec.hpp
GLM Core
_swizzle.hpp
GLM Core