Debian Codegraph @

test/Bullet2/vectormath/sse/vectormath_aos.h

raw symbols SCIP
1 /*
2 Copyright (C) 2006, 2007 Sony Computer Entertainment Inc.
3 All rights reserved.
4
5 Redistribution and use in source and binary forms,
6 with or without modification, are permitted provided that the
7 following conditions are met:
8 * Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10 * Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13 * Neither the name of the Sony Computer Entertainment Inc nor the names
14 of its contributors may be used to endorse or promote products derived
15 from this software without specific prior written permission.
16
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 #ifndef _VECTORMATH_AOS_CPP_SSE_H
31 #define _VECTORMATH_AOS_CPP_SSE_H
32
33 #include <math.h>
34 #include <xmmintrin.h>
35 #include <emmintrin.h>
36 #include <assert.h>
37
38 #define Vector3Ref Vector3 &
39 #define QuatRef Quat &
40 #define Matrix3Ref Matrix3 &
41
42 #if (defined(_WIN32) && (_MSC_VER) && _MSC_VER >= 1400)
43 #define USE_SSE3_LDDQU
44
45 #define VM_ATTRIBUTE_ALIGNED_CLASS16(a) __declspec(align(16)) a
46 #define VM_ATTRIBUTE_ALIGN16 __declspec(align(16))
47 #define VECTORMATH_FORCE_INLINE __forceinline
48 #else
49 #define VM_ATTRIBUTE_ALIGNED_CLASS16(a) a __attribute__((aligned(16)))
50 #define VM_ATTRIBUTE_ALIGN16 __attribute__((aligned(16)))
51 #define VECTORMATH_FORCE_INLINE inline __attribute__((always_inline))
52 #ifdef __SSE3__
53 #define USE_SSE3_LDDQU
54 #endif //__SSE3__
55 #endif //_WIN32
56
57 #ifdef USE_SSE3_LDDQU
58 #include <pmmintrin.h> //_mm_lddqu_si128
59 #endif //USE_SSE3_LDDQU
60
61 // TODO: Tidy
62 typedef __m128 vec_float4;
63 typedef __m128 vec_uint4;
64 typedef __m128 vec_int4;
65 typedef __m128i vec_uchar16;
66 typedef __m128i vec_ushort8;
67
68 #define vec_splat(x, e) _mm_shuffle_ps(x, x, _MM_SHUFFLE(e, e, e, e))
69
70 #define _mm_ror_ps(vec, i) \
71 (((i) % 4) ? (_mm_shuffle_ps(vec, vec, _MM_SHUFFLE((unsigned char)(i + 3) % 4, (unsigned char)(i + 2) % 4, (unsigned char)(i + 1) % 4, (unsigned char)(i + 0) % 4))) : (vec))
72 #define _mm_rol_ps(vec, i) \
73 (((i) % 4) ? (_mm_shuffle_ps(vec, vec, _MM_SHUFFLE((unsigned char)(7 - i) % 4, (unsigned char)(6 - i) % 4, (unsigned char)(5 - i) % 4, (unsigned char)(4 - i) % 4))) : (vec))
74
75 #define vec_sld(vec, vec2, x) _mm_ror_ps(vec, ((x) / 4))
76
77 #define _mm_abs_ps(vec) _mm_andnot_ps(_MASKSIGN_, vec)
78 #define _mm_neg_ps(vec) _mm_xor_ps(_MASKSIGN_, vec)
79
80 #define vec_madd(a, b, c) _mm_add_ps(c, _mm_mul_ps(a, b))
81
82 union SSEFloat {
83 __m128i vi;
84 __m128 m128;
85 __m128 vf;
86 unsigned int ui[4];
87 unsigned short s[8];
88 float f[4];
89 SSEFloat(__m128 v) : m128(v) {}
90 SSEFloat(__m128i v) : vi(v) {}
91 SSEFloat() {} //uninitialized
92 };
93
94 static VECTORMATH_FORCE_INLINE __m128 vec_sel(__m128 a, __m128 b, __m128 mask)
95 {
96 return _mm_or_ps(_mm_and_ps(mask, b), _mm_andnot_ps(mask, a));
97 }
98 static VECTORMATH_FORCE_INLINE __m128 vec_sel(__m128 a, __m128 b, const unsigned int *_mask)
99 {
100 return vec_sel(a, b, _mm_load_ps((float *)_mask));
101 }
102 static VECTORMATH_FORCE_INLINE __m128 vec_sel(__m128 a, __m128 b, unsigned int _mask)
103 {
104 return vec_sel(a, b, _mm_set1_ps(*(float *)&_mask));
105 }
106
107 static VECTORMATH_FORCE_INLINE __m128 toM128(unsigned int x)
108 {
109 return _mm_set1_ps(*(float *)&x);
110 }
111
112 static VECTORMATH_FORCE_INLINE __m128 fabsf4(__m128 x)
113 {
114 return _mm_and_ps(x, toM128(0x7fffffff));
115 }
116 /*
117 union SSE64
118 {
119 __m128 m128;
120 struct
121 {
122 __m64 m01;
123 __m64 m23;
124 } m64;
125 };
126
127 static VECTORMATH_FORCE_INLINE __m128 vec_cts(__m128 x, int a)
128 {
129 assert(a == 0); // Only 2^0 supported
130 (void)a;
131 SSE64 sse64;
132 sse64.m64.m01 = _mm_cvttps_pi32(x);
133 sse64.m64.m23 = _mm_cvttps_pi32(_mm_ror_ps(x,2));
134 _mm_empty();
135 return sse64.m128;
136 }
137
138 static VECTORMATH_FORCE_INLINE __m128 vec_ctf(__m128 x, int a)
139 {
140 assert(a == 0); // Only 2^0 supported
141 (void)a;
142 SSE64 sse64;
143 sse64.m128 = x;
144 __m128 result =_mm_movelh_ps(
145 _mm_cvt_pi2ps(_mm_setzero_ps(), sse64.m64.m01),
146 _mm_cvt_pi2ps(_mm_setzero_ps(), sse64.m64.m23));
147 _mm_empty();
148 return result;
149 }
150 */
151 static VECTORMATH_FORCE_INLINE __m128 vec_cts(__m128 x, int a)
152 {
153 assert(a == 0); // Only 2^0 supported
154 (void)a;
155 __m128i result = _mm_cvtps_epi32(x);
156 return (__m128 &)result;
157 }
158
159 static VECTORMATH_FORCE_INLINE __m128 vec_ctf(__m128 x, int a)
160 {
161 assert(a == 0); // Only 2^0 supported
162 (void)a;
163 return _mm_cvtepi32_ps((__m128i &)x);
164 }
165
166 #define vec_nmsub(a, b, c) _mm_sub_ps(c, _mm_mul_ps(a, b))
167 #define vec_sub(a, b) _mm_sub_ps(a, b)
168 #define vec_add(a, b) _mm_add_ps(a, b)
169 #define vec_mul(a, b) _mm_mul_ps(a, b)
170 #define vec_xor(a, b) _mm_xor_ps(a, b)
171 #define vec_and(a, b) _mm_and_ps(a, b)
172 #define vec_cmpeq(a, b) _mm_cmpeq_ps(a, b)
173 #define vec_cmpgt(a, b) _mm_cmpgt_ps(a, b)
174
175 #define vec_mergeh(a, b) _mm_unpacklo_ps(a, b)
176 #define vec_mergel(a, b) _mm_unpackhi_ps(a, b)
177
178 #define vec_andc(a, b) _mm_andnot_ps(b, a)
179
180 #define sqrtf4(x) _mm_sqrt_ps(x)
181 #define rsqrtf4(x) _mm_rsqrt_ps(x)
182 #define recipf4(x) _mm_rcp_ps(x)
183 #define negatef4(x) _mm_sub_ps(_mm_setzero_ps(), x)
184
185 static VECTORMATH_FORCE_INLINE __m128 newtonrapson_rsqrt4(const __m128 v)
186 {
187 #define _half4 _mm_setr_ps(.5f, .5f, .5f, .5f)
188 #define _three _mm_setr_ps(3.f, 3.f, 3.f, 3.f)
189 const __m128 approx = _mm_rsqrt_ps(v);
190 const __m128 muls = _mm_mul_ps(_mm_mul_ps(v, approx), approx);
191 return _mm_mul_ps(_mm_mul_ps(_half4, approx), _mm_sub_ps(_three, muls));
192 }
193
194 static VECTORMATH_FORCE_INLINE __m128 acosf4(__m128 x)
195 {
196 __m128 xabs = fabsf4(x);
197 __m128 select = _mm_cmplt_ps(x, _mm_setzero_ps());
198 __m128 t1 = sqrtf4(vec_sub(_mm_set1_ps(1.0f), xabs));
199
200 /* Instruction counts can be reduced if the polynomial was
201 * computed entirely from nested (dependent) fma's. However,
202 * to reduce the number of pipeline stalls, the polygon is evaluated
203 * in two halves (hi amd lo).
204 */
205 __m128 xabs2 = _mm_mul_ps(xabs, xabs);
206 __m128 xabs4 = _mm_mul_ps(xabs2, xabs2);
207 __m128 hi = vec_madd(vec_madd(vec_madd(_mm_set1_ps(-0.0012624911f),
208 xabs, _mm_set1_ps(0.0066700901f)),
209 xabs, _mm_set1_ps(-0.0170881256f)),
210 xabs, _mm_set1_ps(0.0308918810f));
211 __m128 lo = vec_madd(vec_madd(vec_madd(_mm_set1_ps(-0.0501743046f),
212 xabs, _mm_set1_ps(0.0889789874f)),
213 xabs, _mm_set1_ps(-0.2145988016f)),
214 xabs, _mm_set1_ps(1.5707963050f));
215
216 __m128 result = vec_madd(hi, xabs4, lo);
217
218 // Adjust the result if x is negactive.
219 return vec_sel(
220 vec_mul(t1, result), // Positive
221 vec_nmsub(t1, result, _mm_set1_ps(3.1415926535898f)), // Negative
222 select);
223 }
224
225 static VECTORMATH_FORCE_INLINE __m128 sinf4(vec_float4 x)
226 {
227 //
228 // Common constants used to evaluate sinf4/cosf4/tanf4
229 //
230 #define _SINCOS_CC0 -0.0013602249f
231 #define _SINCOS_CC1 0.0416566950f
232 #define _SINCOS_CC2 -0.4999990225f
233 #define _SINCOS_SC0 -0.0001950727f
234 #define _SINCOS_SC1 0.0083320758f
235 #define _SINCOS_SC2 -0.1666665247f
236
237 #define _SINCOS_KC1 1.57079625129f
238 #define _SINCOS_KC2 7.54978995489e-8f
239
240 vec_float4 xl, xl2, xl3, res;
241
242 // Range reduction using : xl = angle * TwoOverPi;
243 //
244 xl = vec_mul(x, _mm_set1_ps(0.63661977236f));
245
246 // Find the quadrant the angle falls in
247 // using: q = (int) (ceil(abs(xl))*sign(xl))
248 //
249 vec_int4 q = vec_cts(xl, 0);
250
251 // Compute an offset based on the quadrant that the angle falls in
252 //
253 vec_int4 offset = _mm_and_ps(q, toM128(0x3));
254
255 // Remainder in range [-pi/4..pi/4]
256 //
257 vec_float4 qf = vec_ctf(q, 0);
258 xl = vec_nmsub(qf, _mm_set1_ps(_SINCOS_KC2), vec_nmsub(qf, _mm_set1_ps(_SINCOS_KC1), x));
259
260 // Compute x^2 and x^3
261 //
262 xl2 = vec_mul(xl, xl);
263 xl3 = vec_mul(xl2, xl);
264
265 // Compute both the sin and cos of the angles
266 // using a polynomial expression:
267 // cx = 1.0f + xl2 * ((C0 * xl2 + C1) * xl2 + C2), and
268 // sx = xl + xl3 * ((S0 * xl2 + S1) * xl2 + S2)
269 //
270
271 vec_float4 cx =
272 vec_madd(
273 vec_madd(
274 vec_madd(_mm_set1_ps(_SINCOS_CC0), xl2, _mm_set1_ps(_SINCOS_CC1)), xl2, _mm_set1_ps(_SINCOS_CC2)),
275 xl2, _mm_set1_ps(1.0f));
276 vec_float4 sx =
277 vec_madd(
278 vec_madd(
279 vec_madd(_mm_set1_ps(_SINCOS_SC0), xl2, _mm_set1_ps(_SINCOS_SC1)), xl2, _mm_set1_ps(_SINCOS_SC2)),
280 xl3, xl);
281
282 // Use the cosine when the offset is odd and the sin
283 // when the offset is even
284 //
285 res = vec_sel(cx, sx, vec_cmpeq(vec_and(offset, toM128(0x1)), _mm_setzero_ps()));
286
287 // Flip the sign of the result when (offset mod 4) = 1 or 2
288 //
289 return vec_sel(
290 vec_xor(toM128(0x80000000U), res), // Negative
291 res, // Positive
292 vec_cmpeq(vec_and(offset, toM128(0x2)), _mm_setzero_ps()));
293 }
294
295 static VECTORMATH_FORCE_INLINE void sincosf4(vec_float4 x, vec_float4 *s, vec_float4 *c)
296 {
297 vec_float4 xl, xl2, xl3;
298 vec_int4 offsetSin, offsetCos;
299
300 // Range reduction using : xl = angle * TwoOverPi;
301 //
302 xl = vec_mul(x, _mm_set1_ps(0.63661977236f));
303
304 // Find the quadrant the angle falls in
305 // using: q = (int) (ceil(abs(xl))*sign(xl))
306 //
307 //vec_int4 q = vec_cts(vec_add(xl,vec_sel(_mm_set1_ps(0.5f),xl,(0x80000000))),0);
308 vec_int4 q = vec_cts(xl, 0);
309
310 // Compute the offset based on the quadrant that the angle falls in.
311 // Add 1 to the offset for the cosine.
312 //
313 offsetSin = vec_and(q, toM128((int)0x3));
314 __m128i temp = _mm_add_epi32(_mm_set1_epi32(1), (__m128i &)offsetSin);
315 offsetCos = (__m128 &)temp;
316
317 // Remainder in range [-pi/4..pi/4]
318 //
319 vec_float4 qf = vec_ctf(q, 0);
320 xl = vec_nmsub(qf, _mm_set1_ps(_SINCOS_KC2), vec_nmsub(qf, _mm_set1_ps(_SINCOS_KC1), x));
321
322 // Compute x^2 and x^3
323 //
324 xl2 = vec_mul(xl, xl);
325 xl3 = vec_mul(xl2, xl);
326
327 // Compute both the sin and cos of the angles
328 // using a polynomial expression:
329 // cx = 1.0f + xl2 * ((C0 * xl2 + C1) * xl2 + C2), and
330 // sx = xl + xl3 * ((S0 * xl2 + S1) * xl2 + S2)
331 //
332 vec_float4 cx =
333 vec_madd(
334 vec_madd(
335 vec_madd(_mm_set1_ps(_SINCOS_CC0), xl2, _mm_set1_ps(_SINCOS_CC1)), xl2, _mm_set1_ps(_SINCOS_CC2)),
336 xl2, _mm_set1_ps(1.0f));
337 vec_float4 sx =
338 vec_madd(
339 vec_madd(
340 vec_madd(_mm_set1_ps(_SINCOS_SC0), xl2, _mm_set1_ps(_SINCOS_SC1)), xl2, _mm_set1_ps(_SINCOS_SC2)),
341 xl3, xl);
342
343 // Use the cosine when the offset is odd and the sin
344 // when the offset is even
345 //
346 vec_uint4 sinMask = (vec_uint4)vec_cmpeq(vec_and(offsetSin, toM128(0x1)), _mm_setzero_ps());
347 vec_uint4 cosMask = (vec_uint4)vec_cmpeq(vec_and(offsetCos, toM128(0x1)), _mm_setzero_ps());
348 *s = vec_sel(cx, sx, sinMask);
349 *c = vec_sel(cx, sx, cosMask);
350
351 // Flip the sign of the result when (offset mod 4) = 1 or 2
352 //
353 sinMask = vec_cmpeq(vec_and(offsetSin, toM128(0x2)), _mm_setzero_ps());
354 cosMask = vec_cmpeq(vec_and(offsetCos, toM128(0x2)), _mm_setzero_ps());
355
356 *s = vec_sel((vec_float4)vec_xor(toM128(0x80000000), (vec_uint4)*s), *s, sinMask);
357 *c = vec_sel((vec_float4)vec_xor(toM128(0x80000000), (vec_uint4)*c), *c, cosMask);
358 }
359
360 #include "vecidx_aos.h"
361 #include "floatInVec.h"
362 #include "boolInVec.h"
363
364 #ifdef _VECTORMATH_DEBUG
365 #include <stdio.h>
366 #endif
367 namespace Vectormath
368 {
369 namespace Aos
370 {
371 //-----------------------------------------------------------------------------
372 // Forward Declarations
373 //
374
375 class Vector3;
376 class Vector4;
377 class Point3;
378 class Quat;
379 class Matrix3;
380 class Matrix4;
381 class Transform3;
382
383 // A 3-D vector in array-of-structures format
384 //
385 class Vector3
386 {
387 __m128 mVec128;
388
389 VECTORMATH_FORCE_INLINE void set128(vec_float4 vec);
390
391 VECTORMATH_FORCE_INLINE vec_float4 &get128Ref();
392
393 public:
394 // Default constructor; does no initialization
395 //
396 VECTORMATH_FORCE_INLINE Vector3(){};
397
398 // Default copy constructor
399 //
400 VECTORMATH_FORCE_INLINE Vector3(const Vector3 &vec);
401
402 // Construct a 3-D vector from x, y, and z elements
403 //
404 VECTORMATH_FORCE_INLINE Vector3(float x, float y, float z);
405
406 // Construct a 3-D vector from x, y, and z elements (scalar data contained in vector data type)
407 //
408 VECTORMATH_FORCE_INLINE Vector3(const floatInVec &x, const floatInVec &y, const floatInVec &z);
409
410 // Copy elements from a 3-D point into a 3-D vector
411 //
412 explicit VECTORMATH_FORCE_INLINE Vector3(const Point3 &pnt);
413
414 // Set all elements of a 3-D vector to the same scalar value
415 //
416 explicit VECTORMATH_FORCE_INLINE Vector3(float scalar);
417
418 // Set all elements of a 3-D vector to the same scalar value (scalar data contained in vector data type)
419 //
420 explicit VECTORMATH_FORCE_INLINE Vector3(const floatInVec &scalar);
421
422 // Set vector float data in a 3-D vector
423 //
424 explicit VECTORMATH_FORCE_INLINE Vector3(__m128 vf4);
425
426 // Get vector float data from a 3-D vector
427 //
428 VECTORMATH_FORCE_INLINE __m128 get128() const;
429
430 // Assign one 3-D vector to another
431 //
432 VECTORMATH_FORCE_INLINE Vector3 &operator=(const Vector3 &vec);
433
434 // Set the x element of a 3-D vector
435 //
436 VECTORMATH_FORCE_INLINE Vector3 &setX(float x);
437
438 // Set the y element of a 3-D vector
439 //
440 VECTORMATH_FORCE_INLINE Vector3 &setY(float y);
441
442 // Set the z element of a 3-D vector
443 //
444 VECTORMATH_FORCE_INLINE Vector3 &setZ(float z);
445
446 // Set the x element of a 3-D vector (scalar data contained in vector data type)
447 //
448 VECTORMATH_FORCE_INLINE Vector3 &setX(const floatInVec &x);
449
450 // Set the y element of a 3-D vector (scalar data contained in vector data type)
451 //
452 VECTORMATH_FORCE_INLINE Vector3 &setY(const floatInVec &y);
453
454 // Set the z element of a 3-D vector (scalar data contained in vector data type)
455 //
456 VECTORMATH_FORCE_INLINE Vector3 &setZ(const floatInVec &z);
457
458 // Get the x element of a 3-D vector
459 //
460 VECTORMATH_FORCE_INLINE const floatInVec getX() const;
461
462 // Get the y element of a 3-D vector
463 //
464 VECTORMATH_FORCE_INLINE const floatInVec getY() const;
465
466 // Get the z element of a 3-D vector
467 //
468 VECTORMATH_FORCE_INLINE const floatInVec getZ() const;
469
470 // Set an x, y, or z element of a 3-D vector by index
471 //
472 VECTORMATH_FORCE_INLINE Vector3 &setElem(int idx, float value);
473
474 // Set an x, y, or z element of a 3-D vector by index (scalar data contained in vector data type)
475 //
476 VECTORMATH_FORCE_INLINE Vector3 &setElem(int idx, const floatInVec &value);
477
478 // Get an x, y, or z element of a 3-D vector by index
479 //
480 VECTORMATH_FORCE_INLINE const floatInVec getElem(int idx) const;
481
482 // Subscripting operator to set or get an element
483 //
484 VECTORMATH_FORCE_INLINE VecIdx operator[](int idx);
485
486 // Subscripting operator to get an element
487 //
488 VECTORMATH_FORCE_INLINE const floatInVec operator[](int idx) const;
489
490 // Add two 3-D vectors
491 //
492 VECTORMATH_FORCE_INLINE const Vector3 operator+(const Vector3 &vec) const;
493
494 // Subtract a 3-D vector from another 3-D vector
495 //
496 VECTORMATH_FORCE_INLINE const Vector3 operator-(const Vector3 &vec) const;
497
498 // Add a 3-D vector to a 3-D point
499 //
500 VECTORMATH_FORCE_INLINE const Point3 operator+(const Point3 &pnt) const;
501
502 // Multiply a 3-D vector by a scalar
503 //
504 VECTORMATH_FORCE_INLINE const Vector3 operator*(float scalar) const;
505
506 // Divide a 3-D vector by a scalar
507 //
508 VECTORMATH_FORCE_INLINE const Vector3 operator/(float scalar) const;
509
510 // Multiply a 3-D vector by a scalar (scalar data contained in vector data type)
511 //
512 VECTORMATH_FORCE_INLINE const Vector3 operator*(const floatInVec &scalar) const;
513
514 // Divide a 3-D vector by a scalar (scalar data contained in vector data type)
515 //
516 VECTORMATH_FORCE_INLINE const Vector3 operator/(const floatInVec &scalar) const;
517
518 // Perform compound assignment and addition with a 3-D vector
519 //
520 VECTORMATH_FORCE_INLINE Vector3 &operator+=(const Vector3 &vec);
521
522 // Perform compound assignment and subtraction by a 3-D vector
523 //
524 VECTORMATH_FORCE_INLINE Vector3 &operator-=(const Vector3 &vec);
525
526 // Perform compound assignment and multiplication by a scalar
527 //
528 VECTORMATH_FORCE_INLINE Vector3 &operator*=(float scalar);
529
530 // Perform compound assignment and division by a scalar
531 //
532 VECTORMATH_FORCE_INLINE Vector3 &operator/=(float scalar);
533
534 // Perform compound assignment and multiplication by a scalar (scalar data contained in vector data type)
535 //
536 VECTORMATH_FORCE_INLINE Vector3 &operator*=(const floatInVec &scalar);
537
538 // Perform compound assignment and division by a scalar (scalar data contained in vector data type)
539 //
540 VECTORMATH_FORCE_INLINE Vector3 &operator/=(const floatInVec &scalar);
541
542 // Negate all elements of a 3-D vector
543 //
544 VECTORMATH_FORCE_INLINE const Vector3 operator-() const;
545
546 // Construct x axis
547 //
548 static VECTORMATH_FORCE_INLINE const Vector3 xAxis();
549
550 // Construct y axis
551 //
552 static VECTORMATH_FORCE_INLINE const Vector3 yAxis();
553
554 // Construct z axis
555 //
556 static VECTORMATH_FORCE_INLINE const Vector3 zAxis();
557 };
558
559 // Multiply a 3-D vector by a scalar
560 //
561 VECTORMATH_FORCE_INLINE const Vector3 operator*(float scalar, const Vector3 &vec);
562
563 // Multiply a 3-D vector by a scalar (scalar data contained in vector data type)
564 //
565 VECTORMATH_FORCE_INLINE const Vector3 operator*(const floatInVec &scalar, const Vector3 &vec);
566
567 // Multiply two 3-D vectors per element
568 //
569 VECTORMATH_FORCE_INLINE const Vector3 mulPerElem(const Vector3 &vec0, const Vector3 &vec1);
570
571 // Divide two 3-D vectors per element
572 // NOTE:
573 // Floating-point behavior matches standard library function divf4.
574 //
575 VECTORMATH_FORCE_INLINE const Vector3 divPerElem(const Vector3 &vec0, const Vector3 &vec1);
576
577 // Compute the reciprocal of a 3-D vector per element
578 // NOTE:
579 // Floating-point behavior matches standard library function recipf4.
580 //
581 VECTORMATH_FORCE_INLINE const Vector3 recipPerElem(const Vector3 &vec);
582
583 // Compute the absolute value of a 3-D vector per element
584 //
585 VECTORMATH_FORCE_INLINE const Vector3 absPerElem(const Vector3 &vec);
586
587 // Copy sign from one 3-D vector to another, per element
588 //
589 VECTORMATH_FORCE_INLINE const Vector3 copySignPerElem(const Vector3 &vec0, const Vector3 &vec1);
590
591 // Maximum of two 3-D vectors per element
592 //
593 VECTORMATH_FORCE_INLINE const Vector3 maxPerElem(const Vector3 &vec0, const Vector3 &vec1);
594
595 // Minimum of two 3-D vectors per element
596 //
597 VECTORMATH_FORCE_INLINE const Vector3 minPerElem(const Vector3 &vec0, const Vector3 &vec1);
598
599 // Maximum element of a 3-D vector
600 //
601 VECTORMATH_FORCE_INLINE const floatInVec maxElem(const Vector3 &vec);
602
603 // Minimum element of a 3-D vector
604 //
605 VECTORMATH_FORCE_INLINE const floatInVec minElem(const Vector3 &vec);
606
607 // Compute the sum of all elements of a 3-D vector
608 //
609 VECTORMATH_FORCE_INLINE const floatInVec sum(const Vector3 &vec);
610
611 // Compute the dot product of two 3-D vectors
612 //
613 VECTORMATH_FORCE_INLINE const floatInVec dot(const Vector3 &vec0, const Vector3 &vec1);
614
615 // Compute the square of the length of a 3-D vector
616 //
617 VECTORMATH_FORCE_INLINE const floatInVec lengthSqr(const Vector3 &vec);
618
619 // Compute the length of a 3-D vector
620 //
621 VECTORMATH_FORCE_INLINE const floatInVec length(const Vector3 &vec);
622
623 // Normalize a 3-D vector
624 // NOTE:
625 // The result is unpredictable when all elements of vec are at or near zero.
626 //
627 VECTORMATH_FORCE_INLINE const Vector3 normalize(const Vector3 &vec);
628
629 // Compute cross product of two 3-D vectors
630 //
631 VECTORMATH_FORCE_INLINE const Vector3 cross(const Vector3 &vec0, const Vector3 &vec1);
632
633 // Outer product of two 3-D vectors
634 //
635 VECTORMATH_FORCE_INLINE const Matrix3 outer(const Vector3 &vec0, const Vector3 &vec1);
636
637 // Pre-multiply a row vector by a 3x3 matrix
638 // NOTE:
639 // Slower than column post-multiply.
640 //
641 VECTORMATH_FORCE_INLINE const Vector3 rowMul(const Vector3 &vec, const Matrix3 &mat);
642
643 // Cross-product matrix of a 3-D vector
644 //
645 VECTORMATH_FORCE_INLINE const Matrix3 crossMatrix(const Vector3 &vec);
646
647 // Create cross-product matrix and multiply
648 // NOTE:
649 // Faster than separately creating a cross-product matrix and multiplying.
650 //
651 VECTORMATH_FORCE_INLINE const Matrix3 crossMatrixMul(const Vector3 &vec, const Matrix3 &mat);
652
653 // Linear interpolation between two 3-D vectors
654 // NOTE:
655 // Does not clamp t between 0 and 1.
656 //
657 VECTORMATH_FORCE_INLINE const Vector3 lerp(float t, const Vector3 &vec0, const Vector3 &vec1);
658
659 // Linear interpolation between two 3-D vectors (scalar data contained in vector data type)
660 // NOTE:
661 // Does not clamp t between 0 and 1.
662 //
663 VECTORMATH_FORCE_INLINE const Vector3 lerp(const floatInVec &t, const Vector3 &vec0, const Vector3 &vec1);
664
665 // Spherical linear interpolation between two 3-D vectors
666 // NOTE:
667 // The result is unpredictable if the vectors point in opposite directions.
668 // Does not clamp t between 0 and 1.
669 //
670 VECTORMATH_FORCE_INLINE const Vector3 slerp(float t, const Vector3 &unitVec0, const Vector3 &unitVec1);
671
672 // Spherical linear interpolation between two 3-D vectors (scalar data contained in vector data type)
673 // NOTE:
674 // The result is unpredictable if the vectors point in opposite directions.
675 // Does not clamp t between 0 and 1.
676 //
677 VECTORMATH_FORCE_INLINE const Vector3 slerp(const floatInVec &t, const Vector3 &unitVec0, const Vector3 &unitVec1);
678
679 // Conditionally select between two 3-D vectors
680 // NOTE:
681 // This function uses a conditional select instruction to avoid a branch.
682 // However, the transfer of select1 to a VMX register may use more processing time than a branch.
683 // Use the boolInVec version for better performance.
684 //
685 VECTORMATH_FORCE_INLINE const Vector3 select(const Vector3 &vec0, const Vector3 &vec1, bool select1);
686
687 // Conditionally select between two 3-D vectors (scalar data contained in vector data type)
688 // NOTE:
689 // This function uses a conditional select instruction to avoid a branch.
690 //
691 VECTORMATH_FORCE_INLINE const Vector3 select(const Vector3 &vec0, const Vector3 &vec1, const boolInVec &select1);
692
693 // Store x, y, and z elements of 3-D vector in first three words of a quadword, preserving fourth word
694 //
695 VECTORMATH_FORCE_INLINE void storeXYZ(const Vector3 &vec, __m128 *quad);
696
697 // Load four three-float 3-D vectors, stored in three quadwords
698 //
699 VECTORMATH_FORCE_INLINE void loadXYZArray(Vector3 &vec0, Vector3 &vec1, Vector3 &vec2, Vector3 &vec3, const __m128 *threeQuads);
700
701 // Store four 3-D vectors in three quadwords
702 //
703 VECTORMATH_FORCE_INLINE void storeXYZArray(const Vector3 &vec0, const Vector3 &vec1, const Vector3 &vec2, const Vector3 &vec3, __m128 *threeQuads);
704
705 // Store eight 3-D vectors as half-floats
706 //
707 VECTORMATH_FORCE_INLINE void storeHalfFloats(const Vector3 &vec0, const Vector3 &vec1, const Vector3 &vec2, const Vector3 &vec3, const Vector3 &vec4, const Vector3 &vec5, const Vector3 &vec6, const Vector3 &vec7, vec_ushort8 *threeQuads);
708
709 #ifdef _VECTORMATH_DEBUG
710
711 // Print a 3-D vector
712 // NOTE:
713 // Function is only defined when _VECTORMATH_DEBUG is defined.
714 //
715 VECTORMATH_FORCE_INLINE void print(const Vector3 &vec);
716
717 // Print a 3-D vector and an associated string identifier
718 // NOTE:
719 // Function is only defined when _VECTORMATH_DEBUG is defined.
720 //
721 VECTORMATH_FORCE_INLINE void print(const Vector3 &vec, const char *name);
722
723 #endif
724
725 // A 4-D vector in array-of-structures format
726 //
727 class Vector4
728 {
729 __m128 mVec128;
730
731 public:
732 // Default constructor; does no initialization
733 //
734 VECTORMATH_FORCE_INLINE Vector4(){};
735
736 // Construct a 4-D vector from x, y, z, and w elements
737 //
738 VECTORMATH_FORCE_INLINE Vector4(float x, float y, float z, float w);
739
740 // Construct a 4-D vector from x, y, z, and w elements (scalar data contained in vector data type)
741 //
742 VECTORMATH_FORCE_INLINE Vector4(const floatInVec &x, const floatInVec &y, const floatInVec &z, const floatInVec &w);
743
744 // Construct a 4-D vector from a 3-D vector and a scalar
745 //
746 VECTORMATH_FORCE_INLINE Vector4(const Vector3 &xyz, float w);
747
748 // Construct a 4-D vector from a 3-D vector and a scalar (scalar data contained in vector data type)
749 //
750 VECTORMATH_FORCE_INLINE Vector4(const Vector3 &xyz, const floatInVec &w);
751
752 // Copy x, y, and z from a 3-D vector into a 4-D vector, and set w to 0
753 //
754 explicit VECTORMATH_FORCE_INLINE Vector4(const Vector3 &vec);
755
756 // Copy x, y, and z from a 3-D point into a 4-D vector, and set w to 1
757 //
758 explicit VECTORMATH_FORCE_INLINE Vector4(const Point3 &pnt);
759
760 // Copy elements from a quaternion into a 4-D vector
761 //
762 explicit VECTORMATH_FORCE_INLINE Vector4(const Quat &quat);
763
764 // Set all elements of a 4-D vector to the same scalar value
765 //
766 explicit VECTORMATH_FORCE_INLINE Vector4(float scalar);
767
768 // Set all elements of a 4-D vector to the same scalar value (scalar data contained in vector data type)
769 //
770 explicit VECTORMATH_FORCE_INLINE Vector4(const floatInVec &scalar);
771
772 // Set vector float data in a 4-D vector
773 //
774 explicit VECTORMATH_FORCE_INLINE Vector4(__m128 vf4);
775
776 // Get vector float data from a 4-D vector
777 //
778 VECTORMATH_FORCE_INLINE __m128 get128() const;
779
780 // Assign one 4-D vector to another
781 //
782 VECTORMATH_FORCE_INLINE Vector4 &operator=(const Vector4 &vec);
783
784 // Set the x, y, and z elements of a 4-D vector
785 // NOTE:
786 // This function does not change the w element.
787 //
788 VECTORMATH_FORCE_INLINE Vector4 &setXYZ(const Vector3 &vec);
789
790 // Get the x, y, and z elements of a 4-D vector
791 //
792 VECTORMATH_FORCE_INLINE const Vector3 getXYZ() const;
793
794 // Set the x element of a 4-D vector
795 //
796 VECTORMATH_FORCE_INLINE Vector4 &setX(float x);
797
798 // Set the y element of a 4-D vector
799 //
800 VECTORMATH_FORCE_INLINE Vector4 &setY(float y);
801
802 // Set the z element of a 4-D vector
803 //
804 VECTORMATH_FORCE_INLINE Vector4 &setZ(float z);
805
806 // Set the w element of a 4-D vector
807 //
808 VECTORMATH_FORCE_INLINE Vector4 &setW(float w);
809
810 // Set the x element of a 4-D vector (scalar data contained in vector data type)
811 //
812 VECTORMATH_FORCE_INLINE Vector4 &setX(const floatInVec &x);
813
814 // Set the y element of a 4-D vector (scalar data contained in vector data type)
815 //
816 VECTORMATH_FORCE_INLINE Vector4 &setY(const floatInVec &y);
817
818 // Set the z element of a 4-D vector (scalar data contained in vector data type)
819 //
820 VECTORMATH_FORCE_INLINE Vector4 &setZ(const floatInVec &z);
821
822 // Set the w element of a 4-D vector (scalar data contained in vector data type)
823 //
824 VECTORMATH_FORCE_INLINE Vector4 &setW(const floatInVec &w);
825
826 // Get the x element of a 4-D vector
827 //
828 VECTORMATH_FORCE_INLINE const floatInVec getX() const;
829
830 // Get the y element of a 4-D vector
831 //
832 VECTORMATH_FORCE_INLINE const floatInVec getY() const;
833
834 // Get the z element of a 4-D vector
835 //
836 VECTORMATH_FORCE_INLINE const floatInVec getZ() const;
837
838 // Get the w element of a 4-D vector
839 //
840 VECTORMATH_FORCE_INLINE const floatInVec getW() const;
841
842 // Set an x, y, z, or w element of a 4-D vector by index
843 //
844 VECTORMATH_FORCE_INLINE Vector4 &setElem(int idx, float value);
845
846 // Set an x, y, z, or w element of a 4-D vector by index (scalar data contained in vector data type)
847 //
848 VECTORMATH_FORCE_INLINE Vector4 &setElem(int idx, const floatInVec &value);
849
850 // Get an x, y, z, or w element of a 4-D vector by index
851 //
852 VECTORMATH_FORCE_INLINE const floatInVec getElem(int idx) const;
853
854 // Subscripting operator to set or get an element
855 //
856 VECTORMATH_FORCE_INLINE VecIdx operator[](int idx);
857
858 // Subscripting operator to get an element
859 //
860 VECTORMATH_FORCE_INLINE const floatInVec operator[](int idx) const;
861
862 // Add two 4-D vectors
863 //
864 VECTORMATH_FORCE_INLINE const Vector4 operator+(const Vector4 &vec) const;
865
866 // Subtract a 4-D vector from another 4-D vector
867 //
868 VECTORMATH_FORCE_INLINE const Vector4 operator-(const Vector4 &vec) const;
869
870 // Multiply a 4-D vector by a scalar
871 //
872 VECTORMATH_FORCE_INLINE const Vector4 operator*(float scalar) const;
873
874 // Divide a 4-D vector by a scalar
875 //
876 VECTORMATH_FORCE_INLINE const Vector4 operator/(float scalar) const;
877
878 // Multiply a 4-D vector by a scalar (scalar data contained in vector data type)
879 //
880 VECTORMATH_FORCE_INLINE const Vector4 operator*(const floatInVec &scalar) const;
881
882 // Divide a 4-D vector by a scalar (scalar data contained in vector data type)
883 //
884 VECTORMATH_FORCE_INLINE const Vector4 operator/(const floatInVec &scalar) const;
885
886 // Perform compound assignment and addition with a 4-D vector
887 //
888 VECTORMATH_FORCE_INLINE Vector4 &operator+=(const Vector4 &vec);
889
890 // Perform compound assignment and subtraction by a 4-D vector
891 //
892 VECTORMATH_FORCE_INLINE Vector4 &operator-=(const Vector4 &vec);
893
894 // Perform compound assignment and multiplication by a scalar
895 //
896 VECTORMATH_FORCE_INLINE Vector4 &operator*=(float scalar);
897
898 // Perform compound assignment and division by a scalar
899 //
900 VECTORMATH_FORCE_INLINE Vector4 &operator/=(float scalar);
901
902 // Perform compound assignment and multiplication by a scalar (scalar data contained in vector data type)
903 //
904 VECTORMATH_FORCE_INLINE Vector4 &operator*=(const floatInVec &scalar);
905
906 // Perform compound assignment and division by a scalar (scalar data contained in vector data type)
907 //
908 VECTORMATH_FORCE_INLINE Vector4 &operator/=(const floatInVec &scalar);
909
910 // Negate all elements of a 4-D vector
911 //
912 VECTORMATH_FORCE_INLINE const Vector4 operator-() const;
913
914 // Construct x axis
915 //
916 static VECTORMATH_FORCE_INLINE const Vector4 xAxis();
917
918 // Construct y axis
919 //
920 static VECTORMATH_FORCE_INLINE const Vector4 yAxis();
921
922 // Construct z axis
923 //
924 static VECTORMATH_FORCE_INLINE const Vector4 zAxis();
925
926 // Construct w axis
927 //
928 static VECTORMATH_FORCE_INLINE const Vector4 wAxis();
929 };
930
931 // Multiply a 4-D vector by a scalar
932 //
933 VECTORMATH_FORCE_INLINE const Vector4 operator*(float scalar, const Vector4 &vec);
934
935 // Multiply a 4-D vector by a scalar (scalar data contained in vector data type)
936 //
937 VECTORMATH_FORCE_INLINE const Vector4 operator*(const floatInVec &scalar, const Vector4 &vec);
938
939 // Multiply two 4-D vectors per element
940 //
941 VECTORMATH_FORCE_INLINE const Vector4 mulPerElem(const Vector4 &vec0, const Vector4 &vec1);
942
943 // Divide two 4-D vectors per element
944 // NOTE:
945 // Floating-point behavior matches standard library function divf4.
946 //
947 VECTORMATH_FORCE_INLINE const Vector4 divPerElem(const Vector4 &vec0, const Vector4 &vec1);
948
949 // Compute the reciprocal of a 4-D vector per element
950 // NOTE:
951 // Floating-point behavior matches standard library function recipf4.
952 //
953 VECTORMATH_FORCE_INLINE const Vector4 recipPerElem(const Vector4 &vec);
954
955 // Compute the absolute value of a 4-D vector per element
956 //
957 VECTORMATH_FORCE_INLINE const Vector4 absPerElem(const Vector4 &vec);
958
959 // Copy sign from one 4-D vector to another, per element
960 //
961 VECTORMATH_FORCE_INLINE const Vector4 copySignPerElem(const Vector4 &vec0, const Vector4 &vec1);
962
963 // Maximum of two 4-D vectors per element
964 //
965 VECTORMATH_FORCE_INLINE const Vector4 maxPerElem(const Vector4 &vec0, const Vector4 &vec1);
966
967 // Minimum of two 4-D vectors per element
968 //
969 VECTORMATH_FORCE_INLINE const Vector4 minPerElem(const Vector4 &vec0, const Vector4 &vec1);
970
971 // Maximum element of a 4-D vector
972 //
973 VECTORMATH_FORCE_INLINE const floatInVec maxElem(const Vector4 &vec);
974
975 // Minimum element of a 4-D vector
976 //
977 VECTORMATH_FORCE_INLINE const floatInVec minElem(const Vector4 &vec);
978
979 // Compute the sum of all elements of a 4-D vector
980 //
981 VECTORMATH_FORCE_INLINE const floatInVec sum(const Vector4 &vec);
982
983 // Compute the dot product of two 4-D vectors
984 //
985 VECTORMATH_FORCE_INLINE const floatInVec dot(const Vector4 &vec0, const Vector4 &vec1);
986
987 // Compute the square of the length of a 4-D vector
988 //
989 VECTORMATH_FORCE_INLINE const floatInVec lengthSqr(const Vector4 &vec);
990
991 // Compute the length of a 4-D vector
992 //
993 VECTORMATH_FORCE_INLINE const floatInVec length(const Vector4 &vec);
994
995 // Normalize a 4-D vector
996 // NOTE:
997 // The result is unpredictable when all elements of vec are at or near zero.
998 //
999 VECTORMATH_FORCE_INLINE const Vector4 normalize(const Vector4 &vec);
1000
1001 // Outer product of two 4-D vectors
1002 //
1003 VECTORMATH_FORCE_INLINE const Matrix4 outer(const Vector4 &vec0, const Vector4 &vec1);
1004
1005 // Linear interpolation between two 4-D vectors
1006 // NOTE:
1007 // Does not clamp t between 0 and 1.
1008 //
1009 VECTORMATH_FORCE_INLINE const Vector4 lerp(float t, const Vector4 &vec0, const Vector4 &vec1);
1010
1011 // Linear interpolation between two 4-D vectors (scalar data contained in vector data type)
1012 // NOTE:
1013 // Does not clamp t between 0 and 1.
1014 //
1015 VECTORMATH_FORCE_INLINE const Vector4 lerp(const floatInVec &t, const Vector4 &vec0, const Vector4 &vec1);
1016
1017 // Spherical linear interpolation between two 4-D vectors
1018 // NOTE:
1019 // The result is unpredictable if the vectors point in opposite directions.
1020 // Does not clamp t between 0 and 1.
1021 //
1022 VECTORMATH_FORCE_INLINE const Vector4 slerp(float t, const Vector4 &unitVec0, const Vector4 &unitVec1);
1023
1024 // Spherical linear interpolation between two 4-D vectors (scalar data contained in vector data type)
1025 // NOTE:
1026 // The result is unpredictable if the vectors point in opposite directions.
1027 // Does not clamp t between 0 and 1.
1028 //
1029 VECTORMATH_FORCE_INLINE const Vector4 slerp(const floatInVec &t, const Vector4 &unitVec0, const Vector4 &unitVec1);
1030
1031 // Conditionally select between two 4-D vectors
1032 // NOTE:
1033 // This function uses a conditional select instruction to avoid a branch.
1034 // However, the transfer of select1 to a VMX register may use more processing time than a branch.
1035 // Use the boolInVec version for better performance.
1036 //
1037 VECTORMATH_FORCE_INLINE const Vector4 select(const Vector4 &vec0, const Vector4 &vec1, bool select1);
1038
1039 // Conditionally select between two 4-D vectors (scalar data contained in vector data type)
1040 // NOTE:
1041 // This function uses a conditional select instruction to avoid a branch.
1042 //
1043 VECTORMATH_FORCE_INLINE const Vector4 select(const Vector4 &vec0, const Vector4 &vec1, const boolInVec &select1);
1044
1045 // Store four 4-D vectors as half-floats
1046 //
1047 VECTORMATH_FORCE_INLINE void storeHalfFloats(const Vector4 &vec0, const Vector4 &vec1, const Vector4 &vec2, const Vector4 &vec3, vec_ushort8 *twoQuads);
1048
1049 #ifdef _VECTORMATH_DEBUG
1050
1051 // Print a 4-D vector
1052 // NOTE:
1053 // Function is only defined when _VECTORMATH_DEBUG is defined.
1054 //
1055 VECTORMATH_FORCE_INLINE void print(const Vector4 &vec);
1056
1057 // Print a 4-D vector and an associated string identifier
1058 // NOTE:
1059 // Function is only defined when _VECTORMATH_DEBUG is defined.
1060 //
1061 VECTORMATH_FORCE_INLINE void print(const Vector4 &vec, const char *name);
1062
1063 #endif
1064
1065 // A 3-D point in array-of-structures format
1066 //
1067 class Point3
1068 {
1069 __m128 mVec128;
1070
1071 public:
1072 // Default constructor; does no initialization
1073 //
1074 VECTORMATH_FORCE_INLINE Point3(){};
1075
1076 // Construct a 3-D point from x, y, and z elements
1077 //
1078 VECTORMATH_FORCE_INLINE Point3(float x, float y, float z);
1079
1080 // Construct a 3-D point from x, y, and z elements (scalar data contained in vector data type)
1081 //
1082 VECTORMATH_FORCE_INLINE Point3(const floatInVec &x, const floatInVec &y, const floatInVec &z);
1083
1084 // Copy elements from a 3-D vector into a 3-D point
1085 //
1086 explicit VECTORMATH_FORCE_INLINE Point3(const Vector3 &vec);
1087
1088 // Set all elements of a 3-D point to the same scalar value
1089 //
1090 explicit VECTORMATH_FORCE_INLINE Point3(float scalar);
1091
1092 // Set all elements of a 3-D point to the same scalar value (scalar data contained in vector data type)
1093 //
1094 explicit VECTORMATH_FORCE_INLINE Point3(const floatInVec &scalar);
1095
1096 // Set vector float data in a 3-D point
1097 //
1098 explicit VECTORMATH_FORCE_INLINE Point3(__m128 vf4);
1099
1100 // Get vector float data from a 3-D point
1101 //
1102 VECTORMATH_FORCE_INLINE __m128 get128() const;
1103
1104 // Assign one 3-D point to another
1105 //
1106 VECTORMATH_FORCE_INLINE Point3 &operator=(const Point3 &pnt);
1107
1108 // Set the x element of a 3-D point
1109 //
1110 VECTORMATH_FORCE_INLINE Point3 &setX(float x);
1111
1112 // Set the y element of a 3-D point
1113 //
1114 VECTORMATH_FORCE_INLINE Point3 &setY(float y);
1115
1116 // Set the z element of a 3-D point
1117 //
1118 VECTORMATH_FORCE_INLINE Point3 &setZ(float z);
1119
1120 // Set the x element of a 3-D point (scalar data contained in vector data type)
1121 //
1122 VECTORMATH_FORCE_INLINE Point3 &setX(const floatInVec &x);
1123
1124 // Set the y element of a 3-D point (scalar data contained in vector data type)
1125 //
1126 VECTORMATH_FORCE_INLINE Point3 &setY(const floatInVec &y);
1127
1128 // Set the z element of a 3-D point (scalar data contained in vector data type)
1129 //
1130 VECTORMATH_FORCE_INLINE Point3 &setZ(const floatInVec &z);
1131
1132 // Get the x element of a 3-D point
1133 //
1134 VECTORMATH_FORCE_INLINE const floatInVec getX() const;
1135
1136 // Get the y element of a 3-D point
1137 //
1138 VECTORMATH_FORCE_INLINE const floatInVec getY() const;
1139
1140 // Get the z element of a 3-D point
1141 //
1142 VECTORMATH_FORCE_INLINE const floatInVec getZ() const;
1143
1144 // Set an x, y, or z element of a 3-D point by index
1145 //
1146 VECTORMATH_FORCE_INLINE Point3 &setElem(int idx, float value);
1147
1148 // Set an x, y, or z element of a 3-D point by index (scalar data contained in vector data type)
1149 //
1150 VECTORMATH_FORCE_INLINE Point3 &setElem(int idx, const floatInVec &value);
1151
1152 // Get an x, y, or z element of a 3-D point by index
1153 //
1154 VECTORMATH_FORCE_INLINE const floatInVec getElem(int idx) const;
1155
1156 // Subscripting operator to set or get an element
1157 //
1158 VECTORMATH_FORCE_INLINE VecIdx operator[](int idx);
1159
1160 // Subscripting operator to get an element
1161 //
1162 VECTORMATH_FORCE_INLINE const floatInVec operator[](int idx) const;
1163
1164 // Subtract a 3-D point from another 3-D point
1165 //
1166 VECTORMATH_FORCE_INLINE const Vector3 operator-(const Point3 &pnt) const;
1167
1168 // Add a 3-D point to a 3-D vector
1169 //
1170 VECTORMATH_FORCE_INLINE const Point3 operator+(const Vector3 &vec) const;
1171
1172 // Subtract a 3-D vector from a 3-D point
1173 //
1174 VECTORMATH_FORCE_INLINE const Point3 operator-(const Vector3 &vec) const;
1175
1176 // Perform compound assignment and addition with a 3-D vector
1177 //
1178 VECTORMATH_FORCE_INLINE Point3 &operator+=(const Vector3 &vec);
1179
1180 // Perform compound assignment and subtraction by a 3-D vector
1181 //
1182 VECTORMATH_FORCE_INLINE Point3 &operator-=(const Vector3 &vec);
1183 };
1184
1185 // Multiply two 3-D points per element
1186 //
1187 VECTORMATH_FORCE_INLINE const Point3 mulPerElem(const Point3 &pnt0, const Point3 &pnt1);
1188
1189 // Divide two 3-D points per element
1190 // NOTE:
1191 // Floating-point behavior matches standard library function divf4.
1192 //
1193 VECTORMATH_FORCE_INLINE const Point3 divPerElem(const Point3 &pnt0, const Point3 &pnt1);
1194
1195 // Compute the reciprocal of a 3-D point per element
1196 // NOTE:
1197 // Floating-point behavior matches standard library function recipf4.
1198 //
1199 VECTORMATH_FORCE_INLINE const Point3 recipPerElem(const Point3 &pnt);
1200
1201 // Compute the absolute value of a 3-D point per element
1202 //
1203 VECTORMATH_FORCE_INLINE const Point3 absPerElem(const Point3 &pnt);
1204
1205 // Copy sign from one 3-D point to another, per element
1206 //
1207 VECTORMATH_FORCE_INLINE const Point3 copySignPerElem(const Point3 &pnt0, const Point3 &pnt1);
1208
1209 // Maximum of two 3-D points per element
1210 //
1211 VECTORMATH_FORCE_INLINE const Point3 maxPerElem(const Point3 &pnt0, const Point3 &pnt1);
1212
1213 // Minimum of two 3-D points per element
1214 //
1215 VECTORMATH_FORCE_INLINE const Point3 minPerElem(const Point3 &pnt0, const Point3 &pnt1);
1216
1217 // Maximum element of a 3-D point
1218 //
1219 VECTORMATH_FORCE_INLINE const floatInVec maxElem(const Point3 &pnt);
1220
1221 // Minimum element of a 3-D point
1222 //
1223 VECTORMATH_FORCE_INLINE const floatInVec minElem(const Point3 &pnt);
1224
1225 // Compute the sum of all elements of a 3-D point
1226 //
1227 VECTORMATH_FORCE_INLINE const floatInVec sum(const Point3 &pnt);
1228
1229 // Apply uniform scale to a 3-D point
1230 //
1231 VECTORMATH_FORCE_INLINE const Point3 scale(const Point3 &pnt, float scaleVal);
1232
1233 // Apply uniform scale to a 3-D point (scalar data contained in vector data type)
1234 //
1235 VECTORMATH_FORCE_INLINE const Point3 scale(const Point3 &pnt, const floatInVec &scaleVal);
1236
1237 // Apply non-uniform scale to a 3-D point
1238 //
1239 VECTORMATH_FORCE_INLINE const Point3 scale(const Point3 &pnt, const Vector3 &scaleVec);
1240
1241 // Scalar projection of a 3-D point on a unit-length 3-D vector
1242 //
1243 VECTORMATH_FORCE_INLINE const floatInVec projection(const Point3 &pnt, const Vector3 &unitVec);
1244
1245 // Compute the square of the distance of a 3-D point from the coordinate-system origin
1246 //
1247 VECTORMATH_FORCE_INLINE const floatInVec distSqrFromOrigin(const Point3 &pnt);
1248
1249 // Compute the distance of a 3-D point from the coordinate-system origin
1250 //
1251 VECTORMATH_FORCE_INLINE const floatInVec distFromOrigin(const Point3 &pnt);
1252
1253 // Compute the square of the distance between two 3-D points
1254 //
1255 VECTORMATH_FORCE_INLINE const floatInVec distSqr(const Point3 &pnt0, const Point3 &pnt1);
1256
1257 // Compute the distance between two 3-D points
1258 //
1259 VECTORMATH_FORCE_INLINE const floatInVec dist(const Point3 &pnt0, const Point3 &pnt1);
1260
1261 // Linear interpolation between two 3-D points
1262 // NOTE:
1263 // Does not clamp t between 0 and 1.
1264 //
1265 VECTORMATH_FORCE_INLINE const Point3 lerp(float t, const Point3 &pnt0, const Point3 &pnt1);
1266
1267 // Linear interpolation between two 3-D points (scalar data contained in vector data type)
1268 // NOTE:
1269 // Does not clamp t between 0 and 1.
1270 //
1271 VECTORMATH_FORCE_INLINE const Point3 lerp(const floatInVec &t, const Point3 &pnt0, const Point3 &pnt1);
1272
1273 // Conditionally select between two 3-D points
1274 // NOTE:
1275 // This function uses a conditional select instruction to avoid a branch.
1276 // However, the transfer of select1 to a VMX register may use more processing time than a branch.
1277 // Use the boolInVec version for better performance.
1278 //
1279 VECTORMATH_FORCE_INLINE const Point3 select(const Point3 &pnt0, const Point3 &pnt1, bool select1);
1280
1281 // Conditionally select between two 3-D points (scalar data contained in vector data type)
1282 // NOTE:
1283 // This function uses a conditional select instruction to avoid a branch.
1284 //
1285 VECTORMATH_FORCE_INLINE const Point3 select(const Point3 &pnt0, const Point3 &pnt1, const boolInVec &select1);
1286
1287 // Store x, y, and z elements of 3-D point in first three words of a quadword, preserving fourth word
1288 //
1289 VECTORMATH_FORCE_INLINE void storeXYZ(const Point3 &pnt, __m128 *quad);
1290
1291 // Load four three-float 3-D points, stored in three quadwords
1292 //
1293 VECTORMATH_FORCE_INLINE void loadXYZArray(Point3 &pnt0, Point3 &pnt1, Point3 &pnt2, Point3 &pnt3, const __m128 *threeQuads);
1294
1295 // Store four 3-D points in three quadwords
1296 //
1297 VECTORMATH_FORCE_INLINE void storeXYZArray(const Point3 &pnt0, const Point3 &pnt1, const Point3 &pnt2, const Point3 &pnt3, __m128 *threeQuads);
1298
1299 // Store eight 3-D points as half-floats
1300 //
1301 VECTORMATH_FORCE_INLINE void storeHalfFloats(const Point3 &pnt0, const Point3 &pnt1, const Point3 &pnt2, const Point3 &pnt3, const Point3 &pnt4, const Point3 &pnt5, const Point3 &pnt6, const Point3 &pnt7, vec_ushort8 *threeQuads);
1302
1303 #ifdef _VECTORMATH_DEBUG
1304
1305 // Print a 3-D point
1306 // NOTE:
1307 // Function is only defined when _VECTORMATH_DEBUG is defined.
1308 //
1309 VECTORMATH_FORCE_INLINE void print(const Point3 &pnt);
1310
1311 // Print a 3-D point and an associated string identifier
1312 // NOTE:
1313 // Function is only defined when _VECTORMATH_DEBUG is defined.
1314 //
1315 VECTORMATH_FORCE_INLINE void print(const Point3 &pnt, const char *name);
1316
1317 #endif
1318
1319 // A quaternion in array-of-structures format
1320 //
1321 class Quat
1322 {
1323 __m128 mVec128;
1324
1325 public:
1326 // Default constructor; does no initialization
1327 //
1328 VECTORMATH_FORCE_INLINE Quat(){};
1329
1330 VECTORMATH_FORCE_INLINE Quat(const Quat &quat);
1331
1332 // Construct a quaternion from x, y, z, and w elements
1333 //
1334 VECTORMATH_FORCE_INLINE Quat(float x, float y, float z, float w);
1335
1336 // Construct a quaternion from x, y, z, and w elements (scalar data contained in vector data type)
1337 //
1338 VECTORMATH_FORCE_INLINE Quat(const floatInVec &x, const floatInVec &y, const floatInVec &z, const floatInVec &w);
1339
1340 // Construct a quaternion from a 3-D vector and a scalar
1341 //
1342 VECTORMATH_FORCE_INLINE Quat(const Vector3 &xyz, float w);
1343
1344 // Construct a quaternion from a 3-D vector and a scalar (scalar data contained in vector data type)
1345 //
1346 VECTORMATH_FORCE_INLINE Quat(const Vector3 &xyz, const floatInVec &w);
1347
1348 // Copy elements from a 4-D vector into a quaternion
1349 //
1350 explicit VECTORMATH_FORCE_INLINE Quat(const Vector4 &vec);
1351
1352 // Convert a rotation matrix to a unit-length quaternion
1353 //
1354 explicit VECTORMATH_FORCE_INLINE Quat(const Matrix3 &rotMat);
1355
1356 // Set all elements of a quaternion to the same scalar value
1357 //
1358 explicit VECTORMATH_FORCE_INLINE Quat(float scalar);
1359
1360 // Set all elements of a quaternion to the same scalar value (scalar data contained in vector data type)
1361 //
1362 explicit VECTORMATH_FORCE_INLINE Quat(const floatInVec &scalar);
1363
1364 // Set vector float data in a quaternion
1365 //
1366 explicit VECTORMATH_FORCE_INLINE Quat(__m128 vf4);
1367
1368 // Get vector float data from a quaternion
1369 //
1370 VECTORMATH_FORCE_INLINE __m128 get128() const;
1371
1372 // Set a quaterion from vector float data
1373 //
1374 VECTORMATH_FORCE_INLINE void set128(vec_float4 vec);
1375
1376 // Assign one quaternion to another
1377 //
1378 VECTORMATH_FORCE_INLINE Quat &operator=(const Quat &quat);
1379
1380 // Set the x, y, and z elements of a quaternion
1381 // NOTE:
1382 // This function does not change the w element.
1383 //
1384 VECTORMATH_FORCE_INLINE Quat &setXYZ(const Vector3 &vec);
1385
1386 // Get the x, y, and z elements of a quaternion
1387 //
1388 VECTORMATH_FORCE_INLINE const Vector3 getXYZ() const;
1389
1390 // Set the x element of a quaternion
1391 //
1392 VECTORMATH_FORCE_INLINE Quat &setX(float x);
1393
1394 // Set the y element of a quaternion
1395 //
1396 VECTORMATH_FORCE_INLINE Quat &setY(float y);
1397
1398 // Set the z element of a quaternion
1399 //
1400 VECTORMATH_FORCE_INLINE Quat &setZ(float z);
1401
1402 // Set the w element of a quaternion
1403 //
1404 VECTORMATH_FORCE_INLINE Quat &setW(float w);
1405
1406 // Set the x element of a quaternion (scalar data contained in vector data type)
1407 //
1408 VECTORMATH_FORCE_INLINE Quat &setX(const floatInVec &x);
1409
1410 // Set the y element of a quaternion (scalar data contained in vector data type)
1411 //
1412 VECTORMATH_FORCE_INLINE Quat &setY(const floatInVec &y);
1413
1414 // Set the z element of a quaternion (scalar data contained in vector data type)
1415 //
1416 VECTORMATH_FORCE_INLINE Quat &setZ(const floatInVec &z);
1417
1418 // Set the w element of a quaternion (scalar data contained in vector data type)
1419 //
1420 VECTORMATH_FORCE_INLINE Quat &setW(const floatInVec &w);
1421
1422 // Get the x element of a quaternion
1423 //
1424 VECTORMATH_FORCE_INLINE const floatInVec getX() const;
1425
1426 // Get the y element of a quaternion
1427 //
1428 VECTORMATH_FORCE_INLINE const floatInVec getY() const;
1429
1430 // Get the z element of a quaternion
1431 //
1432 VECTORMATH_FORCE_INLINE const floatInVec getZ() const;
1433
1434 // Get the w element of a quaternion
1435 //
1436 VECTORMATH_FORCE_INLINE const floatInVec getW() const;
1437
1438 // Set an x, y, z, or w element of a quaternion by index
1439 //
1440 VECTORMATH_FORCE_INLINE Quat &setElem(int idx, float value);
1441
1442 // Set an x, y, z, or w element of a quaternion by index (scalar data contained in vector data type)
1443 //
1444 VECTORMATH_FORCE_INLINE Quat &setElem(int idx, const floatInVec &value);
1445
1446 // Get an x, y, z, or w element of a quaternion by index
1447 //
1448 VECTORMATH_FORCE_INLINE const floatInVec getElem(int idx) const;
1449
1450 // Subscripting operator to set or get an element
1451 //
1452 VECTORMATH_FORCE_INLINE VecIdx operator[](int idx);
1453
1454 // Subscripting operator to get an element
1455 //
1456 VECTORMATH_FORCE_INLINE const floatInVec operator[](int idx) const;
1457
1458 // Add two quaternions
1459 //
1460 VECTORMATH_FORCE_INLINE const Quat operator+(const Quat &quat) const;
1461
1462 // Subtract a quaternion from another quaternion
1463 //
1464 VECTORMATH_FORCE_INLINE const Quat operator-(const Quat &quat) const;
1465
1466 // Multiply two quaternions
1467 //
1468 VECTORMATH_FORCE_INLINE const Quat operator*(const Quat &quat) const;
1469
1470 // Multiply a quaternion by a scalar
1471 //
1472 VECTORMATH_FORCE_INLINE const Quat operator*(float scalar) const;
1473
1474 // Divide a quaternion by a scalar
1475 //
1476 VECTORMATH_FORCE_INLINE const Quat operator/(float scalar) const;
1477
1478 // Multiply a quaternion by a scalar (scalar data contained in vector data type)
1479 //
1480 VECTORMATH_FORCE_INLINE const Quat operator*(const floatInVec &scalar) const;
1481
1482 // Divide a quaternion by a scalar (scalar data contained in vector data type)
1483 //
1484 VECTORMATH_FORCE_INLINE const Quat operator/(const floatInVec &scalar) const;
1485
1486 // Perform compound assignment and addition with a quaternion
1487 //
1488 VECTORMATH_FORCE_INLINE Quat &operator+=(const Quat &quat);
1489
1490 // Perform compound assignment and subtraction by a quaternion
1491 //
1492 VECTORMATH_FORCE_INLINE Quat &operator-=(const Quat &quat);
1493
1494 // Perform compound assignment and multiplication by a quaternion
1495 //
1496 VECTORMATH_FORCE_INLINE Quat &operator*=(const Quat &quat);
1497
1498 // Perform compound assignment and multiplication by a scalar
1499 //
1500 VECTORMATH_FORCE_INLINE Quat &operator*=(float scalar);
1501
1502 // Perform compound assignment and division by a scalar
1503 //
1504 VECTORMATH_FORCE_INLINE Quat &operator/=(float scalar);
1505
1506 // Perform compound assignment and multiplication by a scalar (scalar data contained in vector data type)
1507 //
1508 VECTORMATH_FORCE_INLINE Quat &operator*=(const floatInVec &scalar);
1509
1510 // Perform compound assignment and division by a scalar (scalar data contained in vector data type)
1511 //
1512 VECTORMATH_FORCE_INLINE Quat &operator/=(const floatInVec &scalar);
1513
1514 // Negate all elements of a quaternion
1515 //
1516 VECTORMATH_FORCE_INLINE const Quat operator-() const;
1517
1518 // Construct an identity quaternion
1519 //
1520 static VECTORMATH_FORCE_INLINE const Quat identity();
1521
1522 // Construct a quaternion to rotate between two unit-length 3-D vectors
1523 // NOTE:
1524 // The result is unpredictable if unitVec0 and unitVec1 point in opposite directions.
1525 //
1526 static VECTORMATH_FORCE_INLINE const Quat rotation(const Vector3 &unitVec0, const Vector3 &unitVec1);
1527
1528 // Construct a quaternion to rotate around a unit-length 3-D vector
1529 //
1530 static VECTORMATH_FORCE_INLINE const Quat rotation(float radians, const Vector3 &unitVec);
1531
1532 // Construct a quaternion to rotate around a unit-length 3-D vector (scalar data contained in vector data type)
1533 //
1534 static VECTORMATH_FORCE_INLINE const Quat rotation(const floatInVec &radians, const Vector3 &unitVec);
1535
1536 // Construct a quaternion to rotate around the x axis
1537 //
1538 static VECTORMATH_FORCE_INLINE const Quat rotationX(float radians);
1539
1540 // Construct a quaternion to rotate around the y axis
1541 //
1542 static VECTORMATH_FORCE_INLINE const Quat rotationY(float radians);
1543
1544 // Construct a quaternion to rotate around the z axis
1545 //
1546 static VECTORMATH_FORCE_INLINE const Quat rotationZ(float radians);
1547
1548 // Construct a quaternion to rotate around the x axis (scalar data contained in vector data type)
1549 //
1550 static VECTORMATH_FORCE_INLINE const Quat rotationX(const floatInVec &radians);
1551
1552 // Construct a quaternion to rotate around the y axis (scalar data contained in vector data type)
1553 //
1554 static VECTORMATH_FORCE_INLINE const Quat rotationY(const floatInVec &radians);
1555
1556 // Construct a quaternion to rotate around the z axis (scalar data contained in vector data type)
1557 //
1558 static VECTORMATH_FORCE_INLINE const Quat rotationZ(const floatInVec &radians);
1559 };
1560
1561 // Multiply a quaternion by a scalar
1562 //
1563 VECTORMATH_FORCE_INLINE const Quat operator*(float scalar, const Quat &quat);
1564
1565 // Multiply a quaternion by a scalar (scalar data contained in vector data type)
1566 //
1567 VECTORMATH_FORCE_INLINE const Quat operator*(const floatInVec &scalar, const Quat &quat);
1568
1569 // Compute the conjugate of a quaternion
1570 //
1571 VECTORMATH_FORCE_INLINE const Quat conj(const Quat &quat);
1572
1573 // Use a unit-length quaternion to rotate a 3-D vector
1574 //
1575 VECTORMATH_FORCE_INLINE const Vector3 rotate(const Quat &unitQuat, const Vector3 &vec);
1576
1577 // Compute the dot product of two quaternions
1578 //
1579 VECTORMATH_FORCE_INLINE const floatInVec dot(const Quat &quat0, const Quat &quat1);
1580
1581 // Compute the norm of a quaternion
1582 //
1583 VECTORMATH_FORCE_INLINE const floatInVec norm(const Quat &quat);
1584
1585 // Compute the length of a quaternion
1586 //
1587 VECTORMATH_FORCE_INLINE const floatInVec length(const Quat &quat);
1588
1589 // Normalize a quaternion
1590 // NOTE:
1591 // The result is unpredictable when all elements of quat are at or near zero.
1592 //
1593 VECTORMATH_FORCE_INLINE const Quat normalize(const Quat &quat);
1594
1595 // Linear interpolation between two quaternions
1596 // NOTE:
1597 // Does not clamp t between 0 and 1.
1598 //
1599 VECTORMATH_FORCE_INLINE const Quat lerp(float t, const Quat &quat0, const Quat &quat1);
1600
1601 // Linear interpolation between two quaternions (scalar data contained in vector data type)
1602 // NOTE:
1603 // Does not clamp t between 0 and 1.
1604 //
1605 VECTORMATH_FORCE_INLINE const Quat lerp(const floatInVec &t, const Quat &quat0, const Quat &quat1);
1606
1607 // Spherical linear interpolation between two quaternions
1608 // NOTE:
1609 // Interpolates along the shortest path between orientations.
1610 // Does not clamp t between 0 and 1.
1611 //
1612 VECTORMATH_FORCE_INLINE const Quat slerp(float t, const Quat &unitQuat0, const Quat &unitQuat1);
1613
1614 // Spherical linear interpolation between two quaternions (scalar data contained in vector data type)
1615 // NOTE:
1616 // Interpolates along the shortest path between orientations.
1617 // Does not clamp t between 0 and 1.
1618 //
1619 VECTORMATH_FORCE_INLINE const Quat slerp(const floatInVec &t, const Quat &unitQuat0, const Quat &unitQuat1);
1620
1621 // Spherical quadrangle interpolation
1622 //
1623 VECTORMATH_FORCE_INLINE const Quat squad(float t, const Quat &unitQuat0, const Quat &unitQuat1, const Quat &unitQuat2, const Quat &unitQuat3);
1624
1625 // Spherical quadrangle interpolation (scalar data contained in vector data type)
1626 //
1627 VECTORMATH_FORCE_INLINE const Quat squad(const floatInVec &t, const Quat &unitQuat0, const Quat &unitQuat1, const Quat &unitQuat2, const Quat &unitQuat3);
1628
1629 // Conditionally select between two quaternions
1630 // NOTE:
1631 // This function uses a conditional select instruction to avoid a branch.
1632 // However, the transfer of select1 to a VMX register may use more processing time than a branch.
1633 // Use the boolInVec version for better performance.
1634 //
1635 VECTORMATH_FORCE_INLINE const Quat select(const Quat &quat0, const Quat &quat1, bool select1);
1636
1637 // Conditionally select between two quaternions (scalar data contained in vector data type)
1638 // NOTE:
1639 // This function uses a conditional select instruction to avoid a branch.
1640 //
1641 VECTORMATH_FORCE_INLINE const Quat select(const Quat &quat0, const Quat &quat1, const boolInVec &select1);
1642
1643 #ifdef _VECTORMATH_DEBUG
1644
1645 // Print a quaternion
1646 // NOTE:
1647 // Function is only defined when _VECTORMATH_DEBUG is defined.
1648 //
1649 VECTORMATH_FORCE_INLINE void print(const Quat &quat);
1650
1651 // Print a quaternion and an associated string identifier
1652 // NOTE:
1653 // Function is only defined when _VECTORMATH_DEBUG is defined.
1654 //
1655 VECTORMATH_FORCE_INLINE void print(const Quat &quat, const char *name);
1656
1657 #endif
1658
1659 // A 3x3 matrix in array-of-structures format
1660 //
1661 class Matrix3
1662 {
1663 Vector3 mCol0;
1664 Vector3 mCol1;
1665 Vector3 mCol2;
1666
1667 public:
1668 // Default constructor; does no initialization
1669 //
1670 VECTORMATH_FORCE_INLINE Matrix3(){};
1671
1672 // Copy a 3x3 matrix
1673 //
1674 VECTORMATH_FORCE_INLINE Matrix3(const Matrix3 &mat);
1675
1676 // Construct a 3x3 matrix containing the specified columns
1677 //
1678 VECTORMATH_FORCE_INLINE Matrix3(const Vector3 &col0, const Vector3 &col1, const Vector3 &col2);
1679
1680 // Construct a 3x3 rotation matrix from a unit-length quaternion
1681 //
1682 explicit VECTORMATH_FORCE_INLINE Matrix3(const Quat &unitQuat);
1683
1684 // Set all elements of a 3x3 matrix to the same scalar value
1685 //
1686 explicit VECTORMATH_FORCE_INLINE Matrix3(float scalar);
1687
1688 // Set all elements of a 3x3 matrix to the same scalar value (scalar data contained in vector data type)
1689 //
1690 explicit VECTORMATH_FORCE_INLINE Matrix3(const floatInVec &scalar);
1691
1692 // Assign one 3x3 matrix to another
1693 //
1694 VECTORMATH_FORCE_INLINE Matrix3 &operator=(const Matrix3 &mat);
1695
1696 // Set column 0 of a 3x3 matrix
1697 //
1698 VECTORMATH_FORCE_INLINE Matrix3 &setCol0(const Vector3 &col0);
1699
1700 // Set column 1 of a 3x3 matrix
1701 //
1702 VECTORMATH_FORCE_INLINE Matrix3 &setCol1(const Vector3 &col1);
1703
1704 // Set column 2 of a 3x3 matrix
1705 //
1706 VECTORMATH_FORCE_INLINE Matrix3 &setCol2(const Vector3 &col2);
1707
1708 // Get column 0 of a 3x3 matrix
1709 //
1710 VECTORMATH_FORCE_INLINE const Vector3 getCol0() const;
1711
1712 // Get column 1 of a 3x3 matrix
1713 //
1714 VECTORMATH_FORCE_INLINE const Vector3 getCol1() const;
1715
1716 // Get column 2 of a 3x3 matrix
1717 //
1718 VECTORMATH_FORCE_INLINE const Vector3 getCol2() const;
1719
1720 // Set the column of a 3x3 matrix referred to by the specified index
1721 //
1722 VECTORMATH_FORCE_INLINE Matrix3 &setCol(int col, const Vector3 &vec);
1723
1724 // Set the row of a 3x3 matrix referred to by the specified index
1725 //
1726 VECTORMATH_FORCE_INLINE Matrix3 &setRow(int row, const Vector3 &vec);
1727
1728 // Get the column of a 3x3 matrix referred to by the specified index
1729 //
1730 VECTORMATH_FORCE_INLINE const Vector3 getCol(int col) const;
1731
1732 // Get the row of a 3x3 matrix referred to by the specified index
1733 //
1734 VECTORMATH_FORCE_INLINE const Vector3 getRow(int row) const;
1735
1736 // Subscripting operator to set or get a column
1737 //
1738 VECTORMATH_FORCE_INLINE Vector3 &operator[](int col);
1739
1740 // Subscripting operator to get a column
1741 //
1742 VECTORMATH_FORCE_INLINE const Vector3 operator[](int col) const;
1743
1744 // Set the element of a 3x3 matrix referred to by column and row indices
1745 //
1746 VECTORMATH_FORCE_INLINE Matrix3 &setElem(int col, int row, float val);
1747
1748 // Set the element of a 3x3 matrix referred to by column and row indices (scalar data contained in vector data type)
1749 //
1750 VECTORMATH_FORCE_INLINE Matrix3 &setElem(int col, int row, const floatInVec &val);
1751
1752 // Get the element of a 3x3 matrix referred to by column and row indices
1753 //
1754 VECTORMATH_FORCE_INLINE const floatInVec getElem(int col, int row) const;
1755
1756 // Add two 3x3 matrices
1757 //
1758 VECTORMATH_FORCE_INLINE const Matrix3 operator+(const Matrix3 &mat) const;
1759
1760 // Subtract a 3x3 matrix from another 3x3 matrix
1761 //
1762 VECTORMATH_FORCE_INLINE const Matrix3 operator-(const Matrix3 &mat) const;
1763
1764 // Negate all elements of a 3x3 matrix
1765 //
1766 VECTORMATH_FORCE_INLINE const Matrix3 operator-() const;
1767
1768 // Multiply a 3x3 matrix by a scalar
1769 //
1770 VECTORMATH_FORCE_INLINE const Matrix3 operator*(float scalar) const;
1771
1772 // Multiply a 3x3 matrix by a scalar (scalar data contained in vector data type)
1773 //
1774 VECTORMATH_FORCE_INLINE const Matrix3 operator*(const floatInVec &scalar) const;
1775
1776 // Multiply a 3x3 matrix by a 3-D vector
1777 //
1778 VECTORMATH_FORCE_INLINE const Vector3 operator*(const Vector3 &vec) const;
1779
1780 // Multiply two 3x3 matrices
1781 //
1782 VECTORMATH_FORCE_INLINE const Matrix3 operator*(const Matrix3 &mat) const;
1783
1784 // Perform compound assignment and addition with a 3x3 matrix
1785 //
1786 VECTORMATH_FORCE_INLINE Matrix3 &operator+=(const Matrix3 &mat);
1787
1788 // Perform compound assignment and subtraction by a 3x3 matrix
1789 //
1790 VECTORMATH_FORCE_INLINE Matrix3 &operator-=(const Matrix3 &mat);
1791
1792 // Perform compound assignment and multiplication by a scalar
1793 //
1794 VECTORMATH_FORCE_INLINE Matrix3 &operator*=(float scalar);
1795
1796 // Perform compound assignment and multiplication by a scalar (scalar data contained in vector data type)
1797 //
1798 VECTORMATH_FORCE_INLINE Matrix3 &operator*=(const floatInVec &scalar);
1799
1800 // Perform compound assignment and multiplication by a 3x3 matrix
1801 //
1802 VECTORMATH_FORCE_INLINE Matrix3 &operator*=(const Matrix3 &mat);
1803
1804 // Construct an identity 3x3 matrix
1805 //
1806 static VECTORMATH_FORCE_INLINE const Matrix3 identity();
1807
1808 // Construct a 3x3 matrix to rotate around the x axis
1809 //
1810 static VECTORMATH_FORCE_INLINE const Matrix3 rotationX(float radians);
1811
1812 // Construct a 3x3 matrix to rotate around the y axis
1813 //
1814 static VECTORMATH_FORCE_INLINE const Matrix3 rotationY(float radians);
1815
1816 // Construct a 3x3 matrix to rotate around the z axis
1817 //
1818 static VECTORMATH_FORCE_INLINE const Matrix3 rotationZ(float radians);
1819
1820 // Construct a 3x3 matrix to rotate around the x axis (scalar data contained in vector data type)
1821 //
1822 static VECTORMATH_FORCE_INLINE const Matrix3 rotationX(const floatInVec &radians);
1823
1824 // Construct a 3x3 matrix to rotate around the y axis (scalar data contained in vector data type)
1825 //
1826 static VECTORMATH_FORCE_INLINE const Matrix3 rotationY(const floatInVec &radians);
1827
1828 // Construct a 3x3 matrix to rotate around the z axis (scalar data contained in vector data type)
1829 //
1830 static VECTORMATH_FORCE_INLINE const Matrix3 rotationZ(const floatInVec &radians);
1831
1832 // Construct a 3x3 matrix to rotate around the x, y, and z axes
1833 //
1834 static VECTORMATH_FORCE_INLINE const Matrix3 rotationZYX(const Vector3 &radiansXYZ);
1835
1836 // Construct a 3x3 matrix to rotate around a unit-length 3-D vector
1837 //
1838 static VECTORMATH_FORCE_INLINE const Matrix3 rotation(float radians, const Vector3 &unitVec);
1839
1840 // Construct a 3x3 matrix to rotate around a unit-length 3-D vector (scalar data contained in vector data type)
1841 //
1842 static VECTORMATH_FORCE_INLINE const Matrix3 rotation(const floatInVec &radians, const Vector3 &unitVec);
1843
1844 // Construct a rotation matrix from a unit-length quaternion
1845 //
1846 static VECTORMATH_FORCE_INLINE const Matrix3 rotation(const Quat &unitQuat);
1847
1848 // Construct a 3x3 matrix to perform scaling
1849 //
1850 static VECTORMATH_FORCE_INLINE const Matrix3 scale(const Vector3 &scaleVec);
1851 };
1852 // Multiply a 3x3 matrix by a scalar
1853 //
1854 VECTORMATH_FORCE_INLINE const Matrix3 operator*(float scalar, const Matrix3 &mat);
1855
1856 // Multiply a 3x3 matrix by a scalar (scalar data contained in vector data type)
1857 //
1858 VECTORMATH_FORCE_INLINE const Matrix3 operator*(const floatInVec &scalar, const Matrix3 &mat);
1859
1860 // Append (post-multiply) a scale transformation to a 3x3 matrix
1861 // NOTE:
1862 // Faster than creating and multiplying a scale transformation matrix.
1863 //
1864 VECTORMATH_FORCE_INLINE const Matrix3 appendScale(const Matrix3 &mat, const Vector3 &scaleVec);
1865
1866 // Prepend (pre-multiply) a scale transformation to a 3x3 matrix
1867 // NOTE:
1868 // Faster than creating and multiplying a scale transformation matrix.
1869 //
1870 VECTORMATH_FORCE_INLINE const Matrix3 prependScale(const Vector3 &scaleVec, const Matrix3 &mat);
1871
1872 // Multiply two 3x3 matrices per element
1873 //
1874 VECTORMATH_FORCE_INLINE const Matrix3 mulPerElem(const Matrix3 &mat0, const Matrix3 &mat1);
1875
1876 // Compute the absolute value of a 3x3 matrix per element
1877 //
1878 VECTORMATH_FORCE_INLINE const Matrix3 absPerElem(const Matrix3 &mat);
1879
1880 // Transpose of a 3x3 matrix
1881 //
1882 VECTORMATH_FORCE_INLINE const Matrix3 transpose(const Matrix3 &mat);
1883
1884 // Compute the inverse of a 3x3 matrix
1885 // NOTE:
1886 // Result is unpredictable when the determinant of mat is equal to or near 0.
1887 //
1888 VECTORMATH_FORCE_INLINE const Matrix3 inverse(const Matrix3 &mat);
1889
1890 // Determinant of a 3x3 matrix
1891 //
1892 VECTORMATH_FORCE_INLINE const floatInVec determinant(const Matrix3 &mat);
1893
1894 // Conditionally select between two 3x3 matrices
1895 // NOTE:
1896 // This function uses a conditional select instruction to avoid a branch.
1897 // However, the transfer of select1 to a VMX register may use more processing time than a branch.
1898 // Use the boolInVec version for better performance.
1899 //
1900 VECTORMATH_FORCE_INLINE const Matrix3 select(const Matrix3 &mat0, const Matrix3 &mat1, bool select1);
1901
1902 // Conditionally select between two 3x3 matrices (scalar data contained in vector data type)
1903 // NOTE:
1904 // This function uses a conditional select instruction to avoid a branch.
1905 //
1906 VECTORMATH_FORCE_INLINE const Matrix3 select(const Matrix3 &mat0, const Matrix3 &mat1, const boolInVec &select1);
1907
1908 #ifdef _VECTORMATH_DEBUG
1909
1910 // Print a 3x3 matrix
1911 // NOTE:
1912 // Function is only defined when _VECTORMATH_DEBUG is defined.
1913 //
1914 VECTORMATH_FORCE_INLINE void print(const Matrix3 &mat);
1915
1916 // Print a 3x3 matrix and an associated string identifier
1917 // NOTE:
1918 // Function is only defined when _VECTORMATH_DEBUG is defined.
1919 //
1920 VECTORMATH_FORCE_INLINE void print(const Matrix3 &mat, const char *name);
1921
1922 #endif
1923
1924 // A 4x4 matrix in array-of-structures format
1925 //
1926 class Matrix4
1927 {
1928 Vector4 mCol0;
1929 Vector4 mCol1;
1930 Vector4 mCol2;
1931 Vector4 mCol3;
1932
1933 public:
1934 // Default constructor; does no initialization
1935 //
1936 VECTORMATH_FORCE_INLINE Matrix4(){};
1937
1938 // Copy a 4x4 matrix
1939 //
1940 VECTORMATH_FORCE_INLINE Matrix4(const Matrix4 &mat);
1941
1942 // Construct a 4x4 matrix containing the specified columns
1943 //
1944 VECTORMATH_FORCE_INLINE Matrix4(const Vector4 &col0, const Vector4 &col1, const Vector4 &col2, const Vector4 &col3);
1945
1946 // Construct a 4x4 matrix from a 3x4 transformation matrix
1947 //
1948 explicit VECTORMATH_FORCE_INLINE Matrix4(const Transform3 &mat);
1949
1950 // Construct a 4x4 matrix from a 3x3 matrix and a 3-D vector
1951 //
1952 VECTORMATH_FORCE_INLINE Matrix4(const Matrix3 &mat, const Vector3 &translateVec);
1953
1954 // Construct a 4x4 matrix from a unit-length quaternion and a 3-D vector
1955 //
1956 VECTORMATH_FORCE_INLINE Matrix4(const Quat &unitQuat, const Vector3 &translateVec);
1957
1958 // Set all elements of a 4x4 matrix to the same scalar value
1959 //
1960 explicit VECTORMATH_FORCE_INLINE Matrix4(float scalar);
1961
1962 // Set all elements of a 4x4 matrix to the same scalar value (scalar data contained in vector data type)
1963 //
1964 explicit VECTORMATH_FORCE_INLINE Matrix4(const floatInVec &scalar);
1965
1966 // Assign one 4x4 matrix to another
1967 //
1968 VECTORMATH_FORCE_INLINE Matrix4 &operator=(const Matrix4 &mat);
1969
1970 // Set the upper-left 3x3 submatrix
1971 // NOTE:
1972 // This function does not change the bottom row elements.
1973 //
1974 VECTORMATH_FORCE_INLINE Matrix4 &setUpper3x3(const Matrix3 &mat3);
1975
1976 // Get the upper-left 3x3 submatrix of a 4x4 matrix
1977 //
1978 VECTORMATH_FORCE_INLINE const Matrix3 getUpper3x3() const;
1979
1980 // Set translation component
1981 // NOTE:
1982 // This function does not change the bottom row elements.
1983 //
1984 VECTORMATH_FORCE_INLINE Matrix4 &setTranslation(const Vector3 &translateVec);
1985
1986 // Get the translation component of a 4x4 matrix
1987 //
1988 VECTORMATH_FORCE_INLINE const Vector3 getTranslation() const;
1989
1990 // Set column 0 of a 4x4 matrix
1991 //
1992 VECTORMATH_FORCE_INLINE Matrix4 &setCol0(const Vector4 &col0);
1993
1994 // Set column 1 of a 4x4 matrix
1995 //
1996 VECTORMATH_FORCE_INLINE Matrix4 &setCol1(const Vector4 &col1);
1997
1998 // Set column 2 of a 4x4 matrix
1999 //
2000 VECTORMATH_FORCE_INLINE Matrix4 &setCol2(const Vector4 &col2);
2001
2002 // Set column 3 of a 4x4 matrix
2003 //
2004 VECTORMATH_FORCE_INLINE Matrix4 &setCol3(const Vector4 &col3);
2005
2006 // Get column 0 of a 4x4 matrix
2007 //
2008 VECTORMATH_FORCE_INLINE const Vector4 getCol0() const;
2009
2010 // Get column 1 of a 4x4 matrix
2011 //
2012 VECTORMATH_FORCE_INLINE const Vector4 getCol1() const;
2013
2014 // Get column 2 of a 4x4 matrix
2015 //
2016 VECTORMATH_FORCE_INLINE const Vector4 getCol2() const;
2017
2018 // Get column 3 of a 4x4 matrix
2019 //
2020 VECTORMATH_FORCE_INLINE const Vector4 getCol3() const;
2021
2022 // Set the column of a 4x4 matrix referred to by the specified index
2023 //
2024 VECTORMATH_FORCE_INLINE Matrix4 &setCol(int col, const Vector4 &vec);
2025
2026 // Set the row of a 4x4 matrix referred to by the specified index
2027 //
2028 VECTORMATH_FORCE_INLINE Matrix4 &setRow(int row, const Vector4 &vec);
2029
2030 // Get the column of a 4x4 matrix referred to by the specified index
2031 //
2032 VECTORMATH_FORCE_INLINE const Vector4 getCol(int col) const;
2033
2034 // Get the row of a 4x4 matrix referred to by the specified index
2035 //
2036 VECTORMATH_FORCE_INLINE const Vector4 getRow(int row) const;
2037
2038 // Subscripting operator to set or get a column
2039 //
2040 VECTORMATH_FORCE_INLINE Vector4 &operator[](int col);
2041
2042 // Subscripting operator to get a column
2043 //
2044 VECTORMATH_FORCE_INLINE const Vector4 operator[](int col) const;
2045
2046 // Set the element of a 4x4 matrix referred to by column and row indices
2047 //
2048 VECTORMATH_FORCE_INLINE Matrix4 &setElem(int col, int row, float val);
2049
2050 // Set the element of a 4x4 matrix referred to by column and row indices (scalar data contained in vector data type)
2051 //
2052 VECTORMATH_FORCE_INLINE Matrix4 &setElem(int col, int row, const floatInVec &val);
2053
2054 // Get the element of a 4x4 matrix referred to by column and row indices
2055 //
2056 VECTORMATH_FORCE_INLINE const floatInVec getElem(int col, int row) const;
2057
2058 // Add two 4x4 matrices
2059 //
2060 VECTORMATH_FORCE_INLINE const Matrix4 operator+(const Matrix4 &mat) const;
2061
2062 // Subtract a 4x4 matrix from another 4x4 matrix
2063 //
2064 VECTORMATH_FORCE_INLINE const Matrix4 operator-(const Matrix4 &mat) const;
2065
2066 // Negate all elements of a 4x4 matrix
2067 //
2068 VECTORMATH_FORCE_INLINE const Matrix4 operator-() const;
2069
2070 // Multiply a 4x4 matrix by a scalar
2071 //
2072 VECTORMATH_FORCE_INLINE const Matrix4 operator*(float scalar) const;
2073
2074 // Multiply a 4x4 matrix by a scalar (scalar data contained in vector data type)
2075 //
2076 VECTORMATH_FORCE_INLINE const Matrix4 operator*(const floatInVec &scalar) const;
2077
2078 // Multiply a 4x4 matrix by a 4-D vector
2079 //
2080 VECTORMATH_FORCE_INLINE const Vector4 operator*(const Vector4 &vec) const;
2081
2082 // Multiply a 4x4 matrix by a 3-D vector
2083 //
2084 VECTORMATH_FORCE_INLINE const Vector4 operator*(const Vector3 &vec) const;
2085
2086 // Multiply a 4x4 matrix by a 3-D point
2087 //
2088 VECTORMATH_FORCE_INLINE const Vector4 operator*(const Point3 &pnt) const;
2089
2090 // Multiply two 4x4 matrices
2091 //
2092 VECTORMATH_FORCE_INLINE const Matrix4 operator*(const Matrix4 &mat) const;
2093
2094 // Multiply a 4x4 matrix by a 3x4 transformation matrix
2095 //
2096 VECTORMATH_FORCE_INLINE const Matrix4 operator*(const Transform3 &tfrm) const;
2097
2098 // Perform compound assignment and addition with a 4x4 matrix
2099 //
2100 VECTORMATH_FORCE_INLINE Matrix4 &operator+=(const Matrix4 &mat);
2101
2102 // Perform compound assignment and subtraction by a 4x4 matrix
2103 //
2104 VECTORMATH_FORCE_INLINE Matrix4 &operator-=(const Matrix4 &mat);
2105
2106 // Perform compound assignment and multiplication by a scalar
2107 //
2108 VECTORMATH_FORCE_INLINE Matrix4 &operator*=(float scalar);
2109
2110 // Perform compound assignment and multiplication by a scalar (scalar data contained in vector data type)
2111 //
2112 VECTORMATH_FORCE_INLINE Matrix4 &operator*=(const floatInVec &scalar);
2113
2114 // Perform compound assignment and multiplication by a 4x4 matrix
2115 //
2116 VECTORMATH_FORCE_INLINE Matrix4 &operator*=(const Matrix4 &mat);
2117
2118 // Perform compound assignment and multiplication by a 3x4 transformation matrix
2119 //
2120 VECTORMATH_FORCE_INLINE Matrix4 &operator*=(const Transform3 &tfrm);
2121
2122 // Construct an identity 4x4 matrix
2123 //
2124 static VECTORMATH_FORCE_INLINE const Matrix4 identity();
2125
2126 // Construct a 4x4 matrix to rotate around the x axis
2127 //
2128 static VECTORMATH_FORCE_INLINE const Matrix4 rotationX(float radians);
2129
2130 // Construct a 4x4 matrix to rotate around the y axis
2131 //
2132 static VECTORMATH_FORCE_INLINE const Matrix4 rotationY(float radians);
2133
2134 // Construct a 4x4 matrix to rotate around the z axis
2135 //
2136 static VECTORMATH_FORCE_INLINE const Matrix4 rotationZ(float radians);
2137
2138 // Construct a 4x4 matrix to rotate around the x axis (scalar data contained in vector data type)
2139 //
2140 static VECTORMATH_FORCE_INLINE const Matrix4 rotationX(const floatInVec &radians);
2141
2142 // Construct a 4x4 matrix to rotate around the y axis (scalar data contained in vector data type)
2143 //
2144 static VECTORMATH_FORCE_INLINE const Matrix4 rotationY(const floatInVec &radians);
2145
2146 // Construct a 4x4 matrix to rotate around the z axis (scalar data contained in vector data type)
2147 //
2148 static VECTORMATH_FORCE_INLINE const Matrix4 rotationZ(const floatInVec &radians);
2149
2150 // Construct a 4x4 matrix to rotate around the x, y, and z axes
2151 //
2152 static VECTORMATH_FORCE_INLINE const Matrix4 rotationZYX(const Vector3 &radiansXYZ);
2153
2154 // Construct a 4x4 matrix to rotate around a unit-length 3-D vector
2155 //
2156 static VECTORMATH_FORCE_INLINE const Matrix4 rotation(float radians, const Vector3 &unitVec);
2157
2158 // Construct a 4x4 matrix to rotate around a unit-length 3-D vector (scalar data contained in vector data type)
2159 //
2160 static VECTORMATH_FORCE_INLINE const Matrix4 rotation(const floatInVec &radians, const Vector3 &unitVec);
2161
2162 // Construct a rotation matrix from a unit-length quaternion
2163 //
2164 static VECTORMATH_FORCE_INLINE const Matrix4 rotation(const Quat &unitQuat);
2165
2166 // Construct a 4x4 matrix to perform scaling
2167 //
2168 static VECTORMATH_FORCE_INLINE const Matrix4 scale(const Vector3 &scaleVec);
2169
2170 // Construct a 4x4 matrix to perform translation
2171 //
2172 static VECTORMATH_FORCE_INLINE const Matrix4 translation(const Vector3 &translateVec);
2173
2174 // Construct viewing matrix based on eye, position looked at, and up direction
2175 //
2176 static VECTORMATH_FORCE_INLINE const Matrix4 lookAt(const Point3 &eyePos, const Point3 &lookAtPos, const Vector3 &upVec);
2177
2178 // Construct a perspective projection matrix
2179 //
2180 static VECTORMATH_FORCE_INLINE const Matrix4 perspective(float fovyRadians, float aspect, float zNear, float zFar);
2181
2182 // Construct a perspective projection matrix based on frustum
2183 //
2184 static VECTORMATH_FORCE_INLINE const Matrix4 frustum(float left, float right, float bottom, float top, float zNear, float zFar);
2185
2186 // Construct an orthographic projection matrix
2187 //
2188 static VECTORMATH_FORCE_INLINE const Matrix4 orthographic(float left, float right, float bottom, float top, float zNear, float zFar);
2189 };
2190 // Multiply a 4x4 matrix by a scalar
2191 //
2192 VECTORMATH_FORCE_INLINE const Matrix4 operator*(float scalar, const Matrix4 &mat);
2193
2194 // Multiply a 4x4 matrix by a scalar (scalar data contained in vector data type)
2195 //
2196 VECTORMATH_FORCE_INLINE const Matrix4 operator*(const floatInVec &scalar, const Matrix4 &mat);
2197
2198 // Append (post-multiply) a scale transformation to a 4x4 matrix
2199 // NOTE:
2200 // Faster than creating and multiplying a scale transformation matrix.
2201 //
2202 VECTORMATH_FORCE_INLINE const Matrix4 appendScale(const Matrix4 &mat, const Vector3 &scaleVec);
2203
2204 // Prepend (pre-multiply) a scale transformation to a 4x4 matrix
2205 // NOTE:
2206 // Faster than creating and multiplying a scale transformation matrix.
2207 //
2208 VECTORMATH_FORCE_INLINE const Matrix4 prependScale(const Vector3 &scaleVec, const Matrix4 &mat);
2209
2210 // Multiply two 4x4 matrices per element
2211 //
2212 VECTORMATH_FORCE_INLINE const Matrix4 mulPerElem(const Matrix4 &mat0, const Matrix4 &mat1);
2213
2214 // Compute the absolute value of a 4x4 matrix per element
2215 //
2216 VECTORMATH_FORCE_INLINE const Matrix4 absPerElem(const Matrix4 &mat);
2217
2218 // Transpose of a 4x4 matrix
2219 //
2220 VECTORMATH_FORCE_INLINE const Matrix4 transpose(const Matrix4 &mat);
2221
2222 // Compute the inverse of a 4x4 matrix
2223 // NOTE:
2224 // Result is unpredictable when the determinant of mat is equal to or near 0.
2225 //
2226 VECTORMATH_FORCE_INLINE const Matrix4 inverse(const Matrix4 &mat);
2227
2228 // Compute the inverse of a 4x4 matrix, which is expected to be an affine matrix
2229 // NOTE:
2230 // This can be used to achieve better performance than a general inverse when the specified 4x4 matrix meets the given restrictions. The result is unpredictable when the determinant of mat is equal to or near 0.
2231 //
2232 VECTORMATH_FORCE_INLINE const Matrix4 affineInverse(const Matrix4 &mat);
2233
2234 // Compute the inverse of a 4x4 matrix, which is expected to be an affine matrix with an orthogonal upper-left 3x3 submatrix
2235 // NOTE:
2236 // This can be used to achieve better performance than a general inverse when the specified 4x4 matrix meets the given restrictions.
2237 //
2238 VECTORMATH_FORCE_INLINE const Matrix4 orthoInverse(const Matrix4 &mat);
2239
2240 // Determinant of a 4x4 matrix
2241 //
2242 VECTORMATH_FORCE_INLINE const floatInVec determinant(const Matrix4 &mat);
2243
2244 // Conditionally select between two 4x4 matrices
2245 // NOTE:
2246 // This function uses a conditional select instruction to avoid a branch.
2247 // However, the transfer of select1 to a VMX register may use more processing time than a branch.
2248 // Use the boolInVec version for better performance.
2249 //
2250 VECTORMATH_FORCE_INLINE const Matrix4 select(const Matrix4 &mat0, const Matrix4 &mat1, bool select1);
2251
2252 // Conditionally select between two 4x4 matrices (scalar data contained in vector data type)
2253 // NOTE:
2254 // This function uses a conditional select instruction to avoid a branch.
2255 //
2256 VECTORMATH_FORCE_INLINE const Matrix4 select(const Matrix4 &mat0, const Matrix4 &mat1, const boolInVec &select1);
2257
2258 #ifdef _VECTORMATH_DEBUG
2259
2260 // Print a 4x4 matrix
2261 // NOTE:
2262 // Function is only defined when _VECTORMATH_DEBUG is defined.
2263 //
2264 VECTORMATH_FORCE_INLINE void print(const Matrix4 &mat);
2265
2266 // Print a 4x4 matrix and an associated string identifier
2267 // NOTE:
2268 // Function is only defined when _VECTORMATH_DEBUG is defined.
2269 //
2270 VECTORMATH_FORCE_INLINE void print(const Matrix4 &mat, const char *name);
2271
2272 #endif
2273
2274 // A 3x4 transformation matrix in array-of-structures format
2275 //
2276 class Transform3
2277 {
2278 Vector3 mCol0;
2279 Vector3 mCol1;
2280 Vector3 mCol2;
2281 Vector3 mCol3;
2282
2283 public:
2284 // Default constructor; does no initialization
2285 //
2286 VECTORMATH_FORCE_INLINE Transform3(){};
2287
2288 // Copy a 3x4 transformation matrix
2289 //
2290 VECTORMATH_FORCE_INLINE Transform3(const Transform3 &tfrm);
2291
2292 // Construct a 3x4 transformation matrix containing the specified columns
2293 //
2294 VECTORMATH_FORCE_INLINE Transform3(const Vector3 &col0, const Vector3 &col1, const Vector3 &col2, const Vector3 &col3);
2295
2296 // Construct a 3x4 transformation matrix from a 3x3 matrix and a 3-D vector
2297 //
2298 VECTORMATH_FORCE_INLINE Transform3(const Matrix3 &tfrm, const Vector3 &translateVec);
2299
2300 // Construct a 3x4 transformation matrix from a unit-length quaternion and a 3-D vector
2301 //
2302 VECTORMATH_FORCE_INLINE Transform3(const Quat &unitQuat, const Vector3 &translateVec);
2303
2304 // Set all elements of a 3x4 transformation matrix to the same scalar value
2305 //
2306 explicit VECTORMATH_FORCE_INLINE Transform3(float scalar);
2307
2308 // Set all elements of a 3x4 transformation matrix to the same scalar value (scalar data contained in vector data type)
2309 //
2310 explicit VECTORMATH_FORCE_INLINE Transform3(const floatInVec &scalar);
2311
2312 // Assign one 3x4 transformation matrix to another
2313 //
2314 VECTORMATH_FORCE_INLINE Transform3 &operator=(const Transform3 &tfrm);
2315
2316 // Set the upper-left 3x3 submatrix
2317 //
2318 VECTORMATH_FORCE_INLINE Transform3 &setUpper3x3(const Matrix3 &mat3);
2319
2320 // Get the upper-left 3x3 submatrix of a 3x4 transformation matrix
2321 //
2322 VECTORMATH_FORCE_INLINE const Matrix3 getUpper3x3() const;
2323
2324 // Set translation component
2325 //
2326 VECTORMATH_FORCE_INLINE Transform3 &setTranslation(const Vector3 &translateVec);
2327
2328 // Get the translation component of a 3x4 transformation matrix
2329 //
2330 VECTORMATH_FORCE_INLINE const Vector3 getTranslation() const;
2331
2332 // Set column 0 of a 3x4 transformation matrix
2333 //
2334 VECTORMATH_FORCE_INLINE Transform3 &setCol0(const Vector3 &col0);
2335
2336 // Set column 1 of a 3x4 transformation matrix
2337 //
2338 VECTORMATH_FORCE_INLINE Transform3 &setCol1(const Vector3 &col1);
2339
2340 // Set column 2 of a 3x4 transformation matrix
2341 //
2342 VECTORMATH_FORCE_INLINE Transform3 &setCol2(const Vector3 &col2);
2343
2344 // Set column 3 of a 3x4 transformation matrix
2345 //
2346 VECTORMATH_FORCE_INLINE Transform3 &setCol3(const Vector3 &col3);
2347
2348 // Get column 0 of a 3x4 transformation matrix
2349 //
2350 VECTORMATH_FORCE_INLINE const Vector3 getCol0() const;
2351
2352 // Get column 1 of a 3x4 transformation matrix
2353 //
2354 VECTORMATH_FORCE_INLINE const Vector3 getCol1() const;
2355
2356 // Get column 2 of a 3x4 transformation matrix
2357 //
2358 VECTORMATH_FORCE_INLINE const Vector3 getCol2() const;
2359
2360 // Get column 3 of a 3x4 transformation matrix
2361 //
2362 VECTORMATH_FORCE_INLINE const Vector3 getCol3() const;
2363
2364 // Set the column of a 3x4 transformation matrix referred to by the specified index
2365 //
2366 VECTORMATH_FORCE_INLINE Transform3 &setCol(int col, const Vector3 &vec);
2367
2368 // Set the row of a 3x4 transformation matrix referred to by the specified index
2369 //
2370 VECTORMATH_FORCE_INLINE Transform3 &setRow(int row, const Vector4 &vec);
2371
2372 // Get the column of a 3x4 transformation matrix referred to by the specified index
2373 //
2374 VECTORMATH_FORCE_INLINE const Vector3 getCol(int col) const;
2375
2376 // Get the row of a 3x4 transformation matrix referred to by the specified index
2377 //
2378 VECTORMATH_FORCE_INLINE const Vector4 getRow(int row) const;
2379
2380 // Subscripting operator to set or get a column
2381 //
2382 VECTORMATH_FORCE_INLINE Vector3 &operator[](int col);
2383
2384 // Subscripting operator to get a column
2385 //
2386 VECTORMATH_FORCE_INLINE const Vector3 operator[](int col) const;
2387
2388 // Set the element of a 3x4 transformation matrix referred to by column and row indices
2389 //
2390 VECTORMATH_FORCE_INLINE Transform3 &setElem(int col, int row, float val);
2391
2392 // Set the element of a 3x4 transformation matrix referred to by column and row indices (scalar data contained in vector data type)
2393 //
2394 VECTORMATH_FORCE_INLINE Transform3 &setElem(int col, int row, const floatInVec &val);
2395
2396 // Get the element of a 3x4 transformation matrix referred to by column and row indices
2397 //
2398 VECTORMATH_FORCE_INLINE const floatInVec getElem(int col, int row) const;
2399
2400 // Multiply a 3x4 transformation matrix by a 3-D vector
2401 //
2402 VECTORMATH_FORCE_INLINE const Vector3 operator*(const Vector3 &vec) const;
2403
2404 // Multiply a 3x4 transformation matrix by a 3-D point
2405 //
2406 VECTORMATH_FORCE_INLINE const Point3 operator*(const Point3 &pnt) const;
2407
2408 // Multiply two 3x4 transformation matrices
2409 //
2410 VECTORMATH_FORCE_INLINE const Transform3 operator*(const Transform3 &tfrm) const;
2411
2412 // Perform compound assignment and multiplication by a 3x4 transformation matrix
2413 //
2414 VECTORMATH_FORCE_INLINE Transform3 &operator*=(const Transform3 &tfrm);
2415
2416 // Construct an identity 3x4 transformation matrix
2417 //
2418 static VECTORMATH_FORCE_INLINE const Transform3 identity();
2419
2420 // Construct a 3x4 transformation matrix to rotate around the x axis
2421 //
2422 static VECTORMATH_FORCE_INLINE const Transform3 rotationX(float radians);
2423
2424 // Construct a 3x4 transformation matrix to rotate around the y axis
2425 //
2426 static VECTORMATH_FORCE_INLINE const Transform3 rotationY(float radians);
2427
2428 // Construct a 3x4 transformation matrix to rotate around the z axis
2429 //
2430 static VECTORMATH_FORCE_INLINE const Transform3 rotationZ(float radians);
2431
2432 // Construct a 3x4 transformation matrix to rotate around the x axis (scalar data contained in vector data type)
2433 //
2434 static VECTORMATH_FORCE_INLINE const Transform3 rotationX(const floatInVec &radians);
2435
2436 // Construct a 3x4 transformation matrix to rotate around the y axis (scalar data contained in vector data type)
2437 //
2438 static VECTORMATH_FORCE_INLINE const Transform3 rotationY(const floatInVec &radians);
2439
2440 // Construct a 3x4 transformation matrix to rotate around the z axis (scalar data contained in vector data type)
2441 //
2442 static VECTORMATH_FORCE_INLINE const Transform3 rotationZ(const floatInVec &radians);
2443
2444 // Construct a 3x4 transformation matrix to rotate around the x, y, and z axes
2445 //
2446 static VECTORMATH_FORCE_INLINE const Transform3 rotationZYX(const Vector3 &radiansXYZ);
2447
2448 // Construct a 3x4 transformation matrix to rotate around a unit-length 3-D vector
2449 //
2450 static VECTORMATH_FORCE_INLINE const Transform3 rotation(float radians, const Vector3 &unitVec);
2451
2452 // Construct a 3x4 transformation matrix to rotate around a unit-length 3-D vector (scalar data contained in vector data type)
2453 //
2454 static VECTORMATH_FORCE_INLINE const Transform3 rotation(const floatInVec &radians, const Vector3 &unitVec);
2455
2456 // Construct a rotation matrix from a unit-length quaternion
2457 //
2458 static VECTORMATH_FORCE_INLINE const Transform3 rotation(const Quat &unitQuat);
2459
2460 // Construct a 3x4 transformation matrix to perform scaling
2461 //
2462 static VECTORMATH_FORCE_INLINE const Transform3 scale(const Vector3 &scaleVec);
2463
2464 // Construct a 3x4 transformation matrix to perform translation
2465 //
2466 static VECTORMATH_FORCE_INLINE const Transform3 translation(const Vector3 &translateVec);
2467 };
2468 // Append (post-multiply) a scale transformation to a 3x4 transformation matrix
2469 // NOTE:
2470 // Faster than creating and multiplying a scale transformation matrix.
2471 //
2472 VECTORMATH_FORCE_INLINE const Transform3 appendScale(const Transform3 &tfrm, const Vector3 &scaleVec);
2473
2474 // Prepend (pre-multiply) a scale transformation to a 3x4 transformation matrix
2475 // NOTE:
2476 // Faster than creating and multiplying a scale transformation matrix.
2477 //
2478 VECTORMATH_FORCE_INLINE const Transform3 prependScale(const Vector3 &scaleVec, const Transform3 &tfrm);
2479
2480 // Multiply two 3x4 transformation matrices per element
2481 //
2482 VECTORMATH_FORCE_INLINE const Transform3 mulPerElem(const Transform3 &tfrm0, const Transform3 &tfrm1);
2483
2484 // Compute the absolute value of a 3x4 transformation matrix per element
2485 //
2486 VECTORMATH_FORCE_INLINE const Transform3 absPerElem(const Transform3 &tfrm);
2487
2488 // Inverse of a 3x4 transformation matrix
2489 // NOTE:
2490 // Result is unpredictable when the determinant of the left 3x3 submatrix is equal to or near 0.
2491 //
2492 VECTORMATH_FORCE_INLINE const Transform3 inverse(const Transform3 &tfrm);
2493
2494 // Compute the inverse of a 3x4 transformation matrix, expected to have an orthogonal upper-left 3x3 submatrix
2495 // NOTE:
2496 // This can be used to achieve better performance than a general inverse when the specified 3x4 transformation matrix meets the given restrictions.
2497 //
2498 VECTORMATH_FORCE_INLINE const Transform3 orthoInverse(const Transform3 &tfrm);
2499
2500 // Conditionally select between two 3x4 transformation matrices
2501 // NOTE:
2502 // This function uses a conditional select instruction to avoid a branch.
2503 // However, the transfer of select1 to a VMX register may use more processing time than a branch.
2504 // Use the boolInVec version for better performance.
2505 //
2506 VECTORMATH_FORCE_INLINE const Transform3 select(const Transform3 &tfrm0, const Transform3 &tfrm1, bool select1);
2507
2508 // Conditionally select between two 3x4 transformation matrices (scalar data contained in vector data type)
2509 // NOTE:
2510 // This function uses a conditional select instruction to avoid a branch.
2511 //
2512 VECTORMATH_FORCE_INLINE const Transform3 select(const Transform3 &tfrm0, const Transform3 &tfrm1, const boolInVec &select1);
2513
2514 #ifdef _VECTORMATH_DEBUG
2515
2516 // Print a 3x4 transformation matrix
2517 // NOTE:
2518 // Function is only defined when _VECTORMATH_DEBUG is defined.
2519 //
2520 VECTORMATH_FORCE_INLINE void print(const Transform3 &tfrm);
2521
2522 // Print a 3x4 transformation matrix and an associated string identifier
2523 // NOTE:
2524 // Function is only defined when _VECTORMATH_DEBUG is defined.
2525 //
2526 VECTORMATH_FORCE_INLINE void print(const Transform3 &tfrm, const char *name);
2527
2528 #endif
2529
2530 } // namespace Aos
2531 } // namespace Vectormath
2532
2533 #include "vec_aos.h"
2534 #include "quat_aos.h"
2535 #include "mat_aos.h"
2536
2537 #endif