Debian Codegraph @

test/Bullet2/vectormath/scalar/vectormath_aos.h

raw symbols SCIP
1 /*
2 Copyright (C) 2009 Sony Computer Entertainment Inc.
3 All rights reserved.
4
5 This software is provided 'as-is', without any express or implied warranty.
6 In no event will the authors be held liable for any damages arising from the use of this software.
7 Permission is granted to anyone to use this software for any purpose,
8 including commercial applications, and to alter it and redistribute it freely,
9 subject to the following restrictions:
10
11 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
12 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
13 3. This notice may not be removed or altered from any source distribution.
14
15 */
16
17 #ifndef _VECTORMATH_AOS_CPP_H
18 #define _VECTORMATH_AOS_CPP_H
19
20 #include <math.h>
21
22 #ifdef _VECTORMATH_DEBUG
23 #include <stdio.h>
24 #endif
25
26 namespace Vectormath
27 {
28 namespace Aos
29 {
30 //-----------------------------------------------------------------------------
31 // Forward Declarations
32 //
33
34 class Vector3;
35 class Vector4;
36 class Point3;
37 class Quat;
38 class Matrix3;
39 class Matrix4;
40 class Transform3;
41
42 // A 3-D vector in array-of-structures format
43 //
44 class Vector3
45 {
46 float mX;
47 float mY;
48 float mZ;
49 #ifndef __GNUC__
50 float d;
51 #endif
52
53 public:
54 // Default constructor; does no initialization
55 //
56 inline Vector3(){};
57
58 // Copy a 3-D vector
59 //
60 inline Vector3(const Vector3 &vec);
61
62 // Construct a 3-D vector from x, y, and z elements
63 //
64 inline Vector3(float x, float y, float z);
65
66 // Copy elements from a 3-D point into a 3-D vector
67 //
68 explicit inline Vector3(const Point3 &pnt);
69
70 // Set all elements of a 3-D vector to the same scalar value
71 //
72 explicit inline Vector3(float scalar);
73
74 // Assign one 3-D vector to another
75 //
76 inline Vector3 &operator=(const Vector3 &vec);
77
78 // Set the x element of a 3-D vector
79 //
80 inline Vector3 &setX(float x);
81
82 // Set the y element of a 3-D vector
83 //
84 inline Vector3 &setY(float y);
85
86 // Set the z element of a 3-D vector
87 //
88 inline Vector3 &setZ(float z);
89
90 // Get the x element of a 3-D vector
91 //
92 inline float getX() const;
93
94 // Get the y element of a 3-D vector
95 //
96 inline float getY() const;
97
98 // Get the z element of a 3-D vector
99 //
100 inline float getZ() const;
101
102 // Set an x, y, or z element of a 3-D vector by index
103 //
104 inline Vector3 &setElem(int idx, float value);
105
106 // Get an x, y, or z element of a 3-D vector by index
107 //
108 inline float getElem(int idx) const;
109
110 // Subscripting operator to set or get an element
111 //
112 inline float &operator[](int idx);
113
114 // Subscripting operator to get an element
115 //
116 inline float operator[](int idx) const;
117
118 // Add two 3-D vectors
119 //
120 inline const Vector3 operator+(const Vector3 &vec) const;
121
122 // Subtract a 3-D vector from another 3-D vector
123 //
124 inline const Vector3 operator-(const Vector3 &vec) const;
125
126 // Add a 3-D vector to a 3-D point
127 //
128 inline const Point3 operator+(const Point3 &pnt) const;
129
130 // Multiply a 3-D vector by a scalar
131 //
132 inline const Vector3 operator*(float scalar) const;
133
134 // Divide a 3-D vector by a scalar
135 //
136 inline const Vector3 operator/(float scalar) const;
137
138 // Perform compound assignment and addition with a 3-D vector
139 //
140 inline Vector3 &operator+=(const Vector3 &vec);
141
142 // Perform compound assignment and subtraction by a 3-D vector
143 //
144 inline Vector3 &operator-=(const Vector3 &vec);
145
146 // Perform compound assignment and multiplication by a scalar
147 //
148 inline Vector3 &operator*=(float scalar);
149
150 // Perform compound assignment and division by a scalar
151 //
152 inline Vector3 &operator/=(float scalar);
153
154 // Negate all elements of a 3-D vector
155 //
156 inline const Vector3 operator-() const;
157
158 // Construct x axis
159 //
160 static inline const Vector3 xAxis();
161
162 // Construct y axis
163 //
164 static inline const Vector3 yAxis();
165
166 // Construct z axis
167 //
168 static inline const Vector3 zAxis();
169
170 }
171 #ifdef __GNUC__
172 __attribute__((aligned(16)))
173 #endif
174 ;
175
176 // Multiply a 3-D vector by a scalar
177 //
178 inline const Vector3 operator*(float scalar, const Vector3 &vec);
179
180 // Multiply two 3-D vectors per element
181 //
182 inline const Vector3 mulPerElem(const Vector3 &vec0, const Vector3 &vec1);
183
184 // Divide two 3-D vectors per element
185 // NOTE:
186 // Floating-point behavior matches standard library function divf4.
187 //
188 inline const Vector3 divPerElem(const Vector3 &vec0, const Vector3 &vec1);
189
190 // Compute the reciprocal of a 3-D vector per element
191 // NOTE:
192 // Floating-point behavior matches standard library function recipf4.
193 //
194 inline const Vector3 recipPerElem(const Vector3 &vec);
195
196 // Compute the square root of a 3-D vector per element
197 // NOTE:
198 // Floating-point behavior matches standard library function sqrtf4.
199 //
200 inline const Vector3 sqrtPerElem(const Vector3 &vec);
201
202 // Compute the reciprocal square root of a 3-D vector per element
203 // NOTE:
204 // Floating-point behavior matches standard library function rsqrtf4.
205 //
206 inline const Vector3 rsqrtPerElem(const Vector3 &vec);
207
208 // Compute the absolute value of a 3-D vector per element
209 //
210 inline const Vector3 absPerElem(const Vector3 &vec);
211
212 // Copy sign from one 3-D vector to another, per element
213 //
214 inline const Vector3 copySignPerElem(const Vector3 &vec0, const Vector3 &vec1);
215
216 // Maximum of two 3-D vectors per element
217 //
218 inline const Vector3 maxPerElem(const Vector3 &vec0, const Vector3 &vec1);
219
220 // Minimum of two 3-D vectors per element
221 //
222 inline const Vector3 minPerElem(const Vector3 &vec0, const Vector3 &vec1);
223
224 // Maximum element of a 3-D vector
225 //
226 inline float maxElem(const Vector3 &vec);
227
228 // Minimum element of a 3-D vector
229 //
230 inline float minElem(const Vector3 &vec);
231
232 // Compute the sum of all elements of a 3-D vector
233 //
234 inline float sum(const Vector3 &vec);
235
236 // Compute the dot product of two 3-D vectors
237 //
238 inline float dot(const Vector3 &vec0, const Vector3 &vec1);
239
240 // Compute the square of the length of a 3-D vector
241 //
242 inline float lengthSqr(const Vector3 &vec);
243
244 // Compute the length of a 3-D vector
245 //
246 inline float length(const Vector3 &vec);
247
248 // Normalize a 3-D vector
249 // NOTE:
250 // The result is unpredictable when all elements of vec are at or near zero.
251 //
252 inline const Vector3 normalize(const Vector3 &vec);
253
254 // Compute cross product of two 3-D vectors
255 //
256 inline const Vector3 cross(const Vector3 &vec0, const Vector3 &vec1);
257
258 // Outer product of two 3-D vectors
259 //
260 inline const Matrix3 outer(const Vector3 &vec0, const Vector3 &vec1);
261
262 // Pre-multiply a row vector by a 3x3 matrix
263 //
264 inline const Vector3 rowMul(const Vector3 &vec, const Matrix3 &mat);
265
266 // Cross-product matrix of a 3-D vector
267 //
268 inline const Matrix3 crossMatrix(const Vector3 &vec);
269
270 // Create cross-product matrix and multiply
271 // NOTE:
272 // Faster than separately creating a cross-product matrix and multiplying.
273 //
274 inline const Matrix3 crossMatrixMul(const Vector3 &vec, const Matrix3 &mat);
275
276 // Linear interpolation between two 3-D vectors
277 // NOTE:
278 // Does not clamp t between 0 and 1.
279 //
280 inline const Vector3 lerp(float t, const Vector3 &vec0, const Vector3 &vec1);
281
282 // Spherical linear interpolation between two 3-D vectors
283 // NOTE:
284 // The result is unpredictable if the vectors point in opposite directions.
285 // Does not clamp t between 0 and 1.
286 //
287 inline const Vector3 slerp(float t, const Vector3 &unitVec0, const Vector3 &unitVec1);
288
289 // Conditionally select between two 3-D vectors
290 //
291 inline const Vector3 select(const Vector3 &vec0, const Vector3 &vec1, bool select1);
292
293 // Load x, y, and z elements from the first three words of a float array.
294 //
295 //
296 inline void loadXYZ(Vector3 &vec, const float *fptr);
297
298 // Store x, y, and z elements of a 3-D vector in the first three words of a float array.
299 // Memory area of previous 16 bytes and next 32 bytes from fptr might be accessed
300 //
301 inline void storeXYZ(const Vector3 &vec, float *fptr);
302
303 // Load three-half-floats as a 3-D vector
304 // NOTE:
305 // This transformation does not support either denormalized numbers or NaNs.
306 //
307 inline void loadHalfFloats(Vector3 &vec, const unsigned short *hfptr);
308
309 // Store a 3-D vector as half-floats. Memory area of previous 16 bytes and next 32 bytes from <code><i>hfptr</i></code> might be accessed.
310 // NOTE:
311 // This transformation does not support either denormalized numbers or NaNs. Memory area of previous 16 bytes and next 32 bytes from hfptr might be accessed.
312 //
313 inline void storeHalfFloats(const Vector3 &vec, unsigned short *hfptr);
314
315 #ifdef _VECTORMATH_DEBUG
316
317 // Print a 3-D vector
318 // NOTE:
319 // Function is only defined when _VECTORMATH_DEBUG is defined.
320 //
321 inline void print(const Vector3 &vec);
322
323 // Print a 3-D vector and an associated string identifier
324 // NOTE:
325 // Function is only defined when _VECTORMATH_DEBUG is defined.
326 //
327 inline void print(const Vector3 &vec, const char *name);
328
329 #endif
330
331 // A 4-D vector in array-of-structures format
332 //
333 class Vector4
334 {
335 float mX;
336 float mY;
337 float mZ;
338 float mW;
339
340 public:
341 // Default constructor; does no initialization
342 //
343 inline Vector4(){};
344
345 // Copy a 4-D vector
346 //
347 inline Vector4(const Vector4 &vec);
348
349 // Construct a 4-D vector from x, y, z, and w elements
350 //
351 inline Vector4(float x, float y, float z, float w);
352
353 // Construct a 4-D vector from a 3-D vector and a scalar
354 //
355 inline Vector4(const Vector3 &xyz, float w);
356
357 // Copy x, y, and z from a 3-D vector into a 4-D vector, and set w to 0
358 //
359 explicit inline Vector4(const Vector3 &vec);
360
361 // Copy x, y, and z from a 3-D point into a 4-D vector, and set w to 1
362 //
363 explicit inline Vector4(const Point3 &pnt);
364
365 // Copy elements from a quaternion into a 4-D vector
366 //
367 explicit inline Vector4(const Quat &quat);
368
369 // Set all elements of a 4-D vector to the same scalar value
370 //
371 explicit inline Vector4(float scalar);
372
373 // Assign one 4-D vector to another
374 //
375 inline Vector4 &operator=(const Vector4 &vec);
376
377 // Set the x, y, and z elements of a 4-D vector
378 // NOTE:
379 // This function does not change the w element.
380 //
381 inline Vector4 &setXYZ(const Vector3 &vec);
382
383 // Get the x, y, and z elements of a 4-D vector
384 //
385 inline const Vector3 getXYZ() const;
386
387 // Set the x element of a 4-D vector
388 //
389 inline Vector4 &setX(float x);
390
391 // Set the y element of a 4-D vector
392 //
393 inline Vector4 &setY(float y);
394
395 // Set the z element of a 4-D vector
396 //
397 inline Vector4 &setZ(float z);
398
399 // Set the w element of a 4-D vector
400 //
401 inline Vector4 &setW(float w);
402
403 // Get the x element of a 4-D vector
404 //
405 inline float getX() const;
406
407 // Get the y element of a 4-D vector
408 //
409 inline float getY() const;
410
411 // Get the z element of a 4-D vector
412 //
413 inline float getZ() const;
414
415 // Get the w element of a 4-D vector
416 //
417 inline float getW() const;
418
419 // Set an x, y, z, or w element of a 4-D vector by index
420 //
421 inline Vector4 &setElem(int idx, float value);
422
423 // Get an x, y, z, or w element of a 4-D vector by index
424 //
425 inline float getElem(int idx) const;
426
427 // Subscripting operator to set or get an element
428 //
429 inline float &operator[](int idx);
430
431 // Subscripting operator to get an element
432 //
433 inline float operator[](int idx) const;
434
435 // Add two 4-D vectors
436 //
437 inline const Vector4 operator+(const Vector4 &vec) const;
438
439 // Subtract a 4-D vector from another 4-D vector
440 //
441 inline const Vector4 operator-(const Vector4 &vec) const;
442
443 // Multiply a 4-D vector by a scalar
444 //
445 inline const Vector4 operator*(float scalar) const;
446
447 // Divide a 4-D vector by a scalar
448 //
449 inline const Vector4 operator/(float scalar) const;
450
451 // Perform compound assignment and addition with a 4-D vector
452 //
453 inline Vector4 &operator+=(const Vector4 &vec);
454
455 // Perform compound assignment and subtraction by a 4-D vector
456 //
457 inline Vector4 &operator-=(const Vector4 &vec);
458
459 // Perform compound assignment and multiplication by a scalar
460 //
461 inline Vector4 &operator*=(float scalar);
462
463 // Perform compound assignment and division by a scalar
464 //
465 inline Vector4 &operator/=(float scalar);
466
467 // Negate all elements of a 4-D vector
468 //
469 inline const Vector4 operator-() const;
470
471 // Construct x axis
472 //
473 static inline const Vector4 xAxis();
474
475 // Construct y axis
476 //
477 static inline const Vector4 yAxis();
478
479 // Construct z axis
480 //
481 static inline const Vector4 zAxis();
482
483 // Construct w axis
484 //
485 static inline const Vector4 wAxis();
486
487 }
488 #ifdef __GNUC__
489 __attribute__((aligned(16)))
490 #endif
491 ;
492
493 // Multiply a 4-D vector by a scalar
494 //
495 inline const Vector4 operator*(float scalar, const Vector4 &vec);
496
497 // Multiply two 4-D vectors per element
498 //
499 inline const Vector4 mulPerElem(const Vector4 &vec0, const Vector4 &vec1);
500
501 // Divide two 4-D vectors per element
502 // NOTE:
503 // Floating-point behavior matches standard library function divf4.
504 //
505 inline const Vector4 divPerElem(const Vector4 &vec0, const Vector4 &vec1);
506
507 // Compute the reciprocal of a 4-D vector per element
508 // NOTE:
509 // Floating-point behavior matches standard library function recipf4.
510 //
511 inline const Vector4 recipPerElem(const Vector4 &vec);
512
513 // Compute the square root of a 4-D vector per element
514 // NOTE:
515 // Floating-point behavior matches standard library function sqrtf4.
516 //
517 inline const Vector4 sqrtPerElem(const Vector4 &vec);
518
519 // Compute the reciprocal square root of a 4-D vector per element
520 // NOTE:
521 // Floating-point behavior matches standard library function rsqrtf4.
522 //
523 inline const Vector4 rsqrtPerElem(const Vector4 &vec);
524
525 // Compute the absolute value of a 4-D vector per element
526 //
527 inline const Vector4 absPerElem(const Vector4 &vec);
528
529 // Copy sign from one 4-D vector to another, per element
530 //
531 inline const Vector4 copySignPerElem(const Vector4 &vec0, const Vector4 &vec1);
532
533 // Maximum of two 4-D vectors per element
534 //
535 inline const Vector4 maxPerElem(const Vector4 &vec0, const Vector4 &vec1);
536
537 // Minimum of two 4-D vectors per element
538 //
539 inline const Vector4 minPerElem(const Vector4 &vec0, const Vector4 &vec1);
540
541 // Maximum element of a 4-D vector
542 //
543 inline float maxElem(const Vector4 &vec);
544
545 // Minimum element of a 4-D vector
546 //
547 inline float minElem(const Vector4 &vec);
548
549 // Compute the sum of all elements of a 4-D vector
550 //
551 inline float sum(const Vector4 &vec);
552
553 // Compute the dot product of two 4-D vectors
554 //
555 inline float dot(const Vector4 &vec0, const Vector4 &vec1);
556
557 // Compute the square of the length of a 4-D vector
558 //
559 inline float lengthSqr(const Vector4 &vec);
560
561 // Compute the length of a 4-D vector
562 //
563 inline float length(const Vector4 &vec);
564
565 // Normalize a 4-D vector
566 // NOTE:
567 // The result is unpredictable when all elements of vec are at or near zero.
568 //
569 inline const Vector4 normalize(const Vector4 &vec);
570
571 // Outer product of two 4-D vectors
572 //
573 inline const Matrix4 outer(const Vector4 &vec0, const Vector4 &vec1);
574
575 // Linear interpolation between two 4-D vectors
576 // NOTE:
577 // Does not clamp t between 0 and 1.
578 //
579 inline const Vector4 lerp(float t, const Vector4 &vec0, const Vector4 &vec1);
580
581 // Spherical linear interpolation between two 4-D vectors
582 // NOTE:
583 // The result is unpredictable if the vectors point in opposite directions.
584 // Does not clamp t between 0 and 1.
585 //
586 inline const Vector4 slerp(float t, const Vector4 &unitVec0, const Vector4 &unitVec1);
587
588 // Conditionally select between two 4-D vectors
589 //
590 inline const Vector4 select(const Vector4 &vec0, const Vector4 &vec1, bool select1);
591
592 // Load x, y, z, and w elements from the first four words of a float array.
593 //
594 //
595 inline void loadXYZW(Vector4 &vec, const float *fptr);
596
597 // Store x, y, z, and w elements of a 4-D vector in the first four words of a float array.
598 // Memory area of previous 16 bytes and next 32 bytes from fptr might be accessed
599 //
600 inline void storeXYZW(const Vector4 &vec, float *fptr);
601
602 // Load four-half-floats as a 4-D vector
603 // NOTE:
604 // This transformation does not support either denormalized numbers or NaNs.
605 //
606 inline void loadHalfFloats(Vector4 &vec, const unsigned short *hfptr);
607
608 // Store a 4-D vector as half-floats. Memory area of previous 16 bytes and next 32 bytes from <code><i>hfptr</i></code> might be accessed.
609 // NOTE:
610 // This transformation does not support either denormalized numbers or NaNs. Memory area of previous 16 bytes and next 32 bytes from hfptr might be accessed.
611 //
612 inline void storeHalfFloats(const Vector4 &vec, unsigned short *hfptr);
613
614 #ifdef _VECTORMATH_DEBUG
615
616 // Print a 4-D vector
617 // NOTE:
618 // Function is only defined when _VECTORMATH_DEBUG is defined.
619 //
620 inline void print(const Vector4 &vec);
621
622 // Print a 4-D vector and an associated string identifier
623 // NOTE:
624 // Function is only defined when _VECTORMATH_DEBUG is defined.
625 //
626 inline void print(const Vector4 &vec, const char *name);
627
628 #endif
629
630 // A 3-D point in array-of-structures format
631 //
632 class Point3
633 {
634 float mX;
635 float mY;
636 float mZ;
637 #ifndef __GNUC__
638 float d;
639 #endif
640
641 public:
642 // Default constructor; does no initialization
643 //
644 inline Point3(){};
645
646 // Copy a 3-D point
647 //
648 inline Point3(const Point3 &pnt);
649
650 // Construct a 3-D point from x, y, and z elements
651 //
652 inline Point3(float x, float y, float z);
653
654 // Copy elements from a 3-D vector into a 3-D point
655 //
656 explicit inline Point3(const Vector3 &vec);
657
658 // Set all elements of a 3-D point to the same scalar value
659 //
660 explicit inline Point3(float scalar);
661
662 // Assign one 3-D point to another
663 //
664 inline Point3 &operator=(const Point3 &pnt);
665
666 // Set the x element of a 3-D point
667 //
668 inline Point3 &setX(float x);
669
670 // Set the y element of a 3-D point
671 //
672 inline Point3 &setY(float y);
673
674 // Set the z element of a 3-D point
675 //
676 inline Point3 &setZ(float z);
677
678 // Get the x element of a 3-D point
679 //
680 inline float getX() const;
681
682 // Get the y element of a 3-D point
683 //
684 inline float getY() const;
685
686 // Get the z element of a 3-D point
687 //
688 inline float getZ() const;
689
690 // Set an x, y, or z element of a 3-D point by index
691 //
692 inline Point3 &setElem(int idx, float value);
693
694 // Get an x, y, or z element of a 3-D point by index
695 //
696 inline float getElem(int idx) const;
697
698 // Subscripting operator to set or get an element
699 //
700 inline float &operator[](int idx);
701
702 // Subscripting operator to get an element
703 //
704 inline float operator[](int idx) const;
705
706 // Subtract a 3-D point from another 3-D point
707 //
708 inline const Vector3 operator-(const Point3 &pnt) const;
709
710 // Add a 3-D point to a 3-D vector
711 //
712 inline const Point3 operator+(const Vector3 &vec) const;
713
714 // Subtract a 3-D vector from a 3-D point
715 //
716 inline const Point3 operator-(const Vector3 &vec) const;
717
718 // Perform compound assignment and addition with a 3-D vector
719 //
720 inline Point3 &operator+=(const Vector3 &vec);
721
722 // Perform compound assignment and subtraction by a 3-D vector
723 //
724 inline Point3 &operator-=(const Vector3 &vec);
725
726 }
727 #ifdef __GNUC__
728 __attribute__((aligned(16)))
729 #endif
730 ;
731
732 // Multiply two 3-D points per element
733 //
734 inline const Point3 mulPerElem(const Point3 &pnt0, const Point3 &pnt1);
735
736 // Divide two 3-D points per element
737 // NOTE:
738 // Floating-point behavior matches standard library function divf4.
739 //
740 inline const Point3 divPerElem(const Point3 &pnt0, const Point3 &pnt1);
741
742 // Compute the reciprocal of a 3-D point per element
743 // NOTE:
744 // Floating-point behavior matches standard library function recipf4.
745 //
746 inline const Point3 recipPerElem(const Point3 &pnt);
747
748 // Compute the square root of a 3-D point per element
749 // NOTE:
750 // Floating-point behavior matches standard library function sqrtf4.
751 //
752 inline const Point3 sqrtPerElem(const Point3 &pnt);
753
754 // Compute the reciprocal square root of a 3-D point per element
755 // NOTE:
756 // Floating-point behavior matches standard library function rsqrtf4.
757 //
758 inline const Point3 rsqrtPerElem(const Point3 &pnt);
759
760 // Compute the absolute value of a 3-D point per element
761 //
762 inline const Point3 absPerElem(const Point3 &pnt);
763
764 // Copy sign from one 3-D point to another, per element
765 //
766 inline const Point3 copySignPerElem(const Point3 &pnt0, const Point3 &pnt1);
767
768 // Maximum of two 3-D points per element
769 //
770 inline const Point3 maxPerElem(const Point3 &pnt0, const Point3 &pnt1);
771
772 // Minimum of two 3-D points per element
773 //
774 inline const Point3 minPerElem(const Point3 &pnt0, const Point3 &pnt1);
775
776 // Maximum element of a 3-D point
777 //
778 inline float maxElem(const Point3 &pnt);
779
780 // Minimum element of a 3-D point
781 //
782 inline float minElem(const Point3 &pnt);
783
784 // Compute the sum of all elements of a 3-D point
785 //
786 inline float sum(const Point3 &pnt);
787
788 // Apply uniform scale to a 3-D point
789 //
790 inline const Point3 scale(const Point3 &pnt, float scaleVal);
791
792 // Apply non-uniform scale to a 3-D point
793 //
794 inline const Point3 scale(const Point3 &pnt, const Vector3 &scaleVec);
795
796 // Scalar projection of a 3-D point on a unit-length 3-D vector
797 //
798 inline float projection(const Point3 &pnt, const Vector3 &unitVec);
799
800 // Compute the square of the distance of a 3-D point from the coordinate-system origin
801 //
802 inline float distSqrFromOrigin(const Point3 &pnt);
803
804 // Compute the distance of a 3-D point from the coordinate-system origin
805 //
806 inline float distFromOrigin(const Point3 &pnt);
807
808 // Compute the square of the distance between two 3-D points
809 //
810 inline float distSqr(const Point3 &pnt0, const Point3 &pnt1);
811
812 // Compute the distance between two 3-D points
813 //
814 inline float dist(const Point3 &pnt0, const Point3 &pnt1);
815
816 // Linear interpolation between two 3-D points
817 // NOTE:
818 // Does not clamp t between 0 and 1.
819 //
820 inline const Point3 lerp(float t, const Point3 &pnt0, const Point3 &pnt1);
821
822 // Conditionally select between two 3-D points
823 //
824 inline const Point3 select(const Point3 &pnt0, const Point3 &pnt1, bool select1);
825
826 // Load x, y, and z elements from the first three words of a float array.
827 //
828 //
829 inline void loadXYZ(Point3 &pnt, const float *fptr);
830
831 // Store x, y, and z elements of a 3-D point in the first three words of a float array.
832 // Memory area of previous 16 bytes and next 32 bytes from fptr might be accessed
833 //
834 inline void storeXYZ(const Point3 &pnt, float *fptr);
835
836 // Load three-half-floats as a 3-D point
837 // NOTE:
838 // This transformation does not support either denormalized numbers or NaNs.
839 //
840 inline void loadHalfFloats(Point3 &pnt, const unsigned short *hfptr);
841
842 // Store a 3-D point as half-floats. Memory area of previous 16 bytes and next 32 bytes from <code><i>hfptr</i></code> might be accessed.
843 // NOTE:
844 // This transformation does not support either denormalized numbers or NaNs. Memory area of previous 16 bytes and next 32 bytes from hfptr might be accessed.
845 //
846 inline void storeHalfFloats(const Point3 &pnt, unsigned short *hfptr);
847
848 #ifdef _VECTORMATH_DEBUG
849
850 // Print a 3-D point
851 // NOTE:
852 // Function is only defined when _VECTORMATH_DEBUG is defined.
853 //
854 inline void print(const Point3 &pnt);
855
856 // Print a 3-D point and an associated string identifier
857 // NOTE:
858 // Function is only defined when _VECTORMATH_DEBUG is defined.
859 //
860 inline void print(const Point3 &pnt, const char *name);
861
862 #endif
863
864 // A quaternion in array-of-structures format
865 //
866 class Quat
867 {
868 float mX;
869 float mY;
870 float mZ;
871 float mW;
872
873 public:
874 // Default constructor; does no initialization
875 //
876 inline Quat(){};
877
878 // Copy a quaternion
879 //
880 inline Quat(const Quat &quat);
881
882 // Construct a quaternion from x, y, z, and w elements
883 //
884 inline Quat(float x, float y, float z, float w);
885
886 // Construct a quaternion from a 3-D vector and a scalar
887 //
888 inline Quat(const Vector3 &xyz, float w);
889
890 // Copy elements from a 4-D vector into a quaternion
891 //
892 explicit inline Quat(const Vector4 &vec);
893
894 // Convert a rotation matrix to a unit-length quaternion
895 //
896 explicit inline Quat(const Matrix3 &rotMat);
897
898 // Set all elements of a quaternion to the same scalar value
899 //
900 explicit inline Quat(float scalar);
901
902 // Assign one quaternion to another
903 //
904 inline Quat &operator=(const Quat &quat);
905
906 // Set the x, y, and z elements of a quaternion
907 // NOTE:
908 // This function does not change the w element.
909 //
910 inline Quat &setXYZ(const Vector3 &vec);
911
912 // Get the x, y, and z elements of a quaternion
913 //
914 inline const Vector3 getXYZ() const;
915
916 // Set the x element of a quaternion
917 //
918 inline Quat &setX(float x);
919
920 // Set the y element of a quaternion
921 //
922 inline Quat &setY(float y);
923
924 // Set the z element of a quaternion
925 //
926 inline Quat &setZ(float z);
927
928 // Set the w element of a quaternion
929 //
930 inline Quat &setW(float w);
931
932 // Get the x element of a quaternion
933 //
934 inline float getX() const;
935
936 // Get the y element of a quaternion
937 //
938 inline float getY() const;
939
940 // Get the z element of a quaternion
941 //
942 inline float getZ() const;
943
944 // Get the w element of a quaternion
945 //
946 inline float getW() const;
947
948 // Set an x, y, z, or w element of a quaternion by index
949 //
950 inline Quat &setElem(int idx, float value);
951
952 // Get an x, y, z, or w element of a quaternion by index
953 //
954 inline float getElem(int idx) const;
955
956 // Subscripting operator to set or get an element
957 //
958 inline float &operator[](int idx);
959
960 // Subscripting operator to get an element
961 //
962 inline float operator[](int idx) const;
963
964 // Add two quaternions
965 //
966 inline const Quat operator+(const Quat &quat) const;
967
968 // Subtract a quaternion from another quaternion
969 //
970 inline const Quat operator-(const Quat &quat) const;
971
972 // Multiply two quaternions
973 //
974 inline const Quat operator*(const Quat &quat) const;
975
976 // Multiply a quaternion by a scalar
977 //
978 inline const Quat operator*(float scalar) const;
979
980 // Divide a quaternion by a scalar
981 //
982 inline const Quat operator/(float scalar) const;
983
984 // Perform compound assignment and addition with a quaternion
985 //
986 inline Quat &operator+=(const Quat &quat);
987
988 // Perform compound assignment and subtraction by a quaternion
989 //
990 inline Quat &operator-=(const Quat &quat);
991
992 // Perform compound assignment and multiplication by a quaternion
993 //
994 inline Quat &operator*=(const Quat &quat);
995
996 // Perform compound assignment and multiplication by a scalar
997 //
998 inline Quat &operator*=(float scalar);
999
1000 // Perform compound assignment and division by a scalar
1001 //
1002 inline Quat &operator/=(float scalar);
1003
1004 // Negate all elements of a quaternion
1005 //
1006 inline const Quat operator-() const;
1007
1008 // Construct an identity quaternion
1009 //
1010 static inline const Quat identity();
1011
1012 // Construct a quaternion to rotate between two unit-length 3-D vectors
1013 // NOTE:
1014 // The result is unpredictable if unitVec0 and unitVec1 point in opposite directions.
1015 //
1016 static inline const Quat rotation(const Vector3 &unitVec0, const Vector3 &unitVec1);
1017
1018 // Construct a quaternion to rotate around a unit-length 3-D vector
1019 //
1020 static inline const Quat rotation(float radians, const Vector3 &unitVec);
1021
1022 // Construct a quaternion to rotate around the x axis
1023 //
1024 static inline const Quat rotationX(float radians);
1025
1026 // Construct a quaternion to rotate around the y axis
1027 //
1028 static inline const Quat rotationY(float radians);
1029
1030 // Construct a quaternion to rotate around the z axis
1031 //
1032 static inline const Quat rotationZ(float radians);
1033
1034 }
1035 #ifdef __GNUC__
1036 __attribute__((aligned(16)))
1037 #endif
1038 ;
1039
1040 // Multiply a quaternion by a scalar
1041 //
1042 inline const Quat operator*(float scalar, const Quat &quat);
1043
1044 // Compute the conjugate of a quaternion
1045 //
1046 inline const Quat conj(const Quat &quat);
1047
1048 // Use a unit-length quaternion to rotate a 3-D vector
1049 //
1050 inline const Vector3 rotate(const Quat &unitQuat, const Vector3 &vec);
1051
1052 // Compute the dot product of two quaternions
1053 //
1054 inline float dot(const Quat &quat0, const Quat &quat1);
1055
1056 // Compute the norm of a quaternion
1057 //
1058 inline float norm(const Quat &quat);
1059
1060 // Compute the length of a quaternion
1061 //
1062 inline float length(const Quat &quat);
1063
1064 // Normalize a quaternion
1065 // NOTE:
1066 // The result is unpredictable when all elements of quat are at or near zero.
1067 //
1068 inline const Quat normalize(const Quat &quat);
1069
1070 // Linear interpolation between two quaternions
1071 // NOTE:
1072 // Does not clamp t between 0 and 1.
1073 //
1074 inline const Quat lerp(float t, const Quat &quat0, const Quat &quat1);
1075
1076 // Spherical linear interpolation between two quaternions
1077 // NOTE:
1078 // Interpolates along the shortest path between orientations.
1079 // Does not clamp t between 0 and 1.
1080 //
1081 inline const Quat slerp(float t, const Quat &unitQuat0, const Quat &unitQuat1);
1082
1083 // Spherical quadrangle interpolation
1084 //
1085 inline const Quat squad(float t, const Quat &unitQuat0, const Quat &unitQuat1, const Quat &unitQuat2, const Quat &unitQuat3);
1086
1087 // Conditionally select between two quaternions
1088 //
1089 inline const Quat select(const Quat &quat0, const Quat &quat1, bool select1);
1090
1091 // Load x, y, z, and w elements from the first four words of a float array.
1092 //
1093 //
1094 inline void loadXYZW(Quat &quat, const float *fptr);
1095
1096 // Store x, y, z, and w elements of a quaternion in the first four words of a float array.
1097 // Memory area of previous 16 bytes and next 32 bytes from fptr might be accessed
1098 //
1099 inline void storeXYZW(const Quat &quat, float *fptr);
1100
1101 #ifdef _VECTORMATH_DEBUG
1102
1103 // Print a quaternion
1104 // NOTE:
1105 // Function is only defined when _VECTORMATH_DEBUG is defined.
1106 //
1107 inline void print(const Quat &quat);
1108
1109 // Print a quaternion and an associated string identifier
1110 // NOTE:
1111 // Function is only defined when _VECTORMATH_DEBUG is defined.
1112 //
1113 inline void print(const Quat &quat, const char *name);
1114
1115 #endif
1116
1117 // A 3x3 matrix in array-of-structures format
1118 //
1119 class Matrix3
1120 {
1121 Vector3 mCol0;
1122 Vector3 mCol1;
1123 Vector3 mCol2;
1124
1125 public:
1126 // Default constructor; does no initialization
1127 //
1128 inline Matrix3(){};
1129
1130 // Copy a 3x3 matrix
1131 //
1132 inline Matrix3(const Matrix3 &mat);
1133
1134 // Construct a 3x3 matrix containing the specified columns
1135 //
1136 inline Matrix3(const Vector3 &col0, const Vector3 &col1, const Vector3 &col2);
1137
1138 // Construct a 3x3 rotation matrix from a unit-length quaternion
1139 //
1140 explicit inline Matrix3(const Quat &unitQuat);
1141
1142 // Set all elements of a 3x3 matrix to the same scalar value
1143 //
1144 explicit inline Matrix3(float scalar);
1145
1146 // Assign one 3x3 matrix to another
1147 //
1148 inline Matrix3 &operator=(const Matrix3 &mat);
1149
1150 // Set column 0 of a 3x3 matrix
1151 //
1152 inline Matrix3 &setCol0(const Vector3 &col0);
1153
1154 // Set column 1 of a 3x3 matrix
1155 //
1156 inline Matrix3 &setCol1(const Vector3 &col1);
1157
1158 // Set column 2 of a 3x3 matrix
1159 //
1160 inline Matrix3 &setCol2(const Vector3 &col2);
1161
1162 // Get column 0 of a 3x3 matrix
1163 //
1164 inline const Vector3 getCol0() const;
1165
1166 // Get column 1 of a 3x3 matrix
1167 //
1168 inline const Vector3 getCol1() const;
1169
1170 // Get column 2 of a 3x3 matrix
1171 //
1172 inline const Vector3 getCol2() const;
1173
1174 // Set the column of a 3x3 matrix referred to by the specified index
1175 //
1176 inline Matrix3 &setCol(int col, const Vector3 &vec);
1177
1178 // Set the row of a 3x3 matrix referred to by the specified index
1179 //
1180 inline Matrix3 &setRow(int row, const Vector3 &vec);
1181
1182 // Get the column of a 3x3 matrix referred to by the specified index
1183 //
1184 inline const Vector3 getCol(int col) const;
1185
1186 // Get the row of a 3x3 matrix referred to by the specified index
1187 //
1188 inline const Vector3 getRow(int row) const;
1189
1190 // Subscripting operator to set or get a column
1191 //
1192 inline Vector3 &operator[](int col);
1193
1194 // Subscripting operator to get a column
1195 //
1196 inline const Vector3 operator[](int col) const;
1197
1198 // Set the element of a 3x3 matrix referred to by column and row indices
1199 //
1200 inline Matrix3 &setElem(int col, int row, float val);
1201
1202 // Get the element of a 3x3 matrix referred to by column and row indices
1203 //
1204 inline float getElem(int col, int row) const;
1205
1206 // Add two 3x3 matrices
1207 //
1208 inline const Matrix3 operator+(const Matrix3 &mat) const;
1209
1210 // Subtract a 3x3 matrix from another 3x3 matrix
1211 //
1212 inline const Matrix3 operator-(const Matrix3 &mat) const;
1213
1214 // Negate all elements of a 3x3 matrix
1215 //
1216 inline const Matrix3 operator-() const;
1217
1218 // Multiply a 3x3 matrix by a scalar
1219 //
1220 inline const Matrix3 operator*(float scalar) const;
1221
1222 // Multiply a 3x3 matrix by a 3-D vector
1223 //
1224 inline const Vector3 operator*(const Vector3 &vec) const;
1225
1226 // Multiply two 3x3 matrices
1227 //
1228 inline const Matrix3 operator*(const Matrix3 &mat) const;
1229
1230 // Perform compound assignment and addition with a 3x3 matrix
1231 //
1232 inline Matrix3 &operator+=(const Matrix3 &mat);
1233
1234 // Perform compound assignment and subtraction by a 3x3 matrix
1235 //
1236 inline Matrix3 &operator-=(const Matrix3 &mat);
1237
1238 // Perform compound assignment and multiplication by a scalar
1239 //
1240 inline Matrix3 &operator*=(float scalar);
1241
1242 // Perform compound assignment and multiplication by a 3x3 matrix
1243 //
1244 inline Matrix3 &operator*=(const Matrix3 &mat);
1245
1246 // Construct an identity 3x3 matrix
1247 //
1248 static inline const Matrix3 identity();
1249
1250 // Construct a 3x3 matrix to rotate around the x axis
1251 //
1252 static inline const Matrix3 rotationX(float radians);
1253
1254 // Construct a 3x3 matrix to rotate around the y axis
1255 //
1256 static inline const Matrix3 rotationY(float radians);
1257
1258 // Construct a 3x3 matrix to rotate around the z axis
1259 //
1260 static inline const Matrix3 rotationZ(float radians);
1261
1262 // Construct a 3x3 matrix to rotate around the x, y, and z axes
1263 //
1264 static inline const Matrix3 rotationZYX(const Vector3 &radiansXYZ);
1265
1266 // Construct a 3x3 matrix to rotate around a unit-length 3-D vector
1267 //
1268 static inline const Matrix3 rotation(float radians, const Vector3 &unitVec);
1269
1270 // Construct a rotation matrix from a unit-length quaternion
1271 //
1272 static inline const Matrix3 rotation(const Quat &unitQuat);
1273
1274 // Construct a 3x3 matrix to perform scaling
1275 //
1276 static inline const Matrix3 scale(const Vector3 &scaleVec);
1277 };
1278 // Multiply a 3x3 matrix by a scalar
1279 //
1280 inline const Matrix3 operator*(float scalar, const Matrix3 &mat);
1281
1282 // Append (post-multiply) a scale transformation to a 3x3 matrix
1283 // NOTE:
1284 // Faster than creating and multiplying a scale transformation matrix.
1285 //
1286 inline const Matrix3 appendScale(const Matrix3 &mat, const Vector3 &scaleVec);
1287
1288 // Prepend (pre-multiply) a scale transformation to a 3x3 matrix
1289 // NOTE:
1290 // Faster than creating and multiplying a scale transformation matrix.
1291 //
1292 inline const Matrix3 prependScale(const Vector3 &scaleVec, const Matrix3 &mat);
1293
1294 // Multiply two 3x3 matrices per element
1295 //
1296 inline const Matrix3 mulPerElem(const Matrix3 &mat0, const Matrix3 &mat1);
1297
1298 // Compute the absolute value of a 3x3 matrix per element
1299 //
1300 inline const Matrix3 absPerElem(const Matrix3 &mat);
1301
1302 // Transpose of a 3x3 matrix
1303 //
1304 inline const Matrix3 transpose(const Matrix3 &mat);
1305
1306 // Compute the inverse of a 3x3 matrix
1307 // NOTE:
1308 // Result is unpredictable when the determinant of mat is equal to or near 0.
1309 //
1310 inline const Matrix3 inverse(const Matrix3 &mat);
1311
1312 // Determinant of a 3x3 matrix
1313 //
1314 inline float determinant(const Matrix3 &mat);
1315
1316 // Conditionally select between two 3x3 matrices
1317 //
1318 inline const Matrix3 select(const Matrix3 &mat0, const Matrix3 &mat1, bool select1);
1319
1320 #ifdef _VECTORMATH_DEBUG
1321
1322 // Print a 3x3 matrix
1323 // NOTE:
1324 // Function is only defined when _VECTORMATH_DEBUG is defined.
1325 //
1326 inline void print(const Matrix3 &mat);
1327
1328 // Print a 3x3 matrix and an associated string identifier
1329 // NOTE:
1330 // Function is only defined when _VECTORMATH_DEBUG is defined.
1331 //
1332 inline void print(const Matrix3 &mat, const char *name);
1333
1334 #endif
1335
1336 // A 4x4 matrix in array-of-structures format
1337 //
1338 class Matrix4
1339 {
1340 Vector4 mCol0;
1341 Vector4 mCol1;
1342 Vector4 mCol2;
1343 Vector4 mCol3;
1344
1345 public:
1346 // Default constructor; does no initialization
1347 //
1348 inline Matrix4(){};
1349
1350 // Copy a 4x4 matrix
1351 //
1352 inline Matrix4(const Matrix4 &mat);
1353
1354 // Construct a 4x4 matrix containing the specified columns
1355 //
1356 inline Matrix4(const Vector4 &col0, const Vector4 &col1, const Vector4 &col2, const Vector4 &col3);
1357
1358 // Construct a 4x4 matrix from a 3x4 transformation matrix
1359 //
1360 explicit inline Matrix4(const Transform3 &mat);
1361
1362 // Construct a 4x4 matrix from a 3x3 matrix and a 3-D vector
1363 //
1364 inline Matrix4(const Matrix3 &mat, const Vector3 &translateVec);
1365
1366 // Construct a 4x4 matrix from a unit-length quaternion and a 3-D vector
1367 //
1368 inline Matrix4(const Quat &unitQuat, const Vector3 &translateVec);
1369
1370 // Set all elements of a 4x4 matrix to the same scalar value
1371 //
1372 explicit inline Matrix4(float scalar);
1373
1374 // Assign one 4x4 matrix to another
1375 //
1376 inline Matrix4 &operator=(const Matrix4 &mat);
1377
1378 // Set the upper-left 3x3 submatrix
1379 // NOTE:
1380 // This function does not change the bottom row elements.
1381 //
1382 inline Matrix4 &setUpper3x3(const Matrix3 &mat3);
1383
1384 // Get the upper-left 3x3 submatrix of a 4x4 matrix
1385 //
1386 inline const Matrix3 getUpper3x3() const;
1387
1388 // Set translation component
1389 // NOTE:
1390 // This function does not change the bottom row elements.
1391 //
1392 inline Matrix4 &setTranslation(const Vector3 &translateVec);
1393
1394 // Get the translation component of a 4x4 matrix
1395 //
1396 inline const Vector3 getTranslation() const;
1397
1398 // Set column 0 of a 4x4 matrix
1399 //
1400 inline Matrix4 &setCol0(const Vector4 &col0);
1401
1402 // Set column 1 of a 4x4 matrix
1403 //
1404 inline Matrix4 &setCol1(const Vector4 &col1);
1405
1406 // Set column 2 of a 4x4 matrix
1407 //
1408 inline Matrix4 &setCol2(const Vector4 &col2);
1409
1410 // Set column 3 of a 4x4 matrix
1411 //
1412 inline Matrix4 &setCol3(const Vector4 &col3);
1413
1414 // Get column 0 of a 4x4 matrix
1415 //
1416 inline const Vector4 getCol0() const;
1417
1418 // Get column 1 of a 4x4 matrix
1419 //
1420 inline const Vector4 getCol1() const;
1421
1422 // Get column 2 of a 4x4 matrix
1423 //
1424 inline const Vector4 getCol2() const;
1425
1426 // Get column 3 of a 4x4 matrix
1427 //
1428 inline const Vector4 getCol3() const;
1429
1430 // Set the column of a 4x4 matrix referred to by the specified index
1431 //
1432 inline Matrix4 &setCol(int col, const Vector4 &vec);
1433
1434 // Set the row of a 4x4 matrix referred to by the specified index
1435 //
1436 inline Matrix4 &setRow(int row, const Vector4 &vec);
1437
1438 // Get the column of a 4x4 matrix referred to by the specified index
1439 //
1440 inline const Vector4 getCol(int col) const;
1441
1442 // Get the row of a 4x4 matrix referred to by the specified index
1443 //
1444 inline const Vector4 getRow(int row) const;
1445
1446 // Subscripting operator to set or get a column
1447 //
1448 inline Vector4 &operator[](int col);
1449
1450 // Subscripting operator to get a column
1451 //
1452 inline const Vector4 operator[](int col) const;
1453
1454 // Set the element of a 4x4 matrix referred to by column and row indices
1455 //
1456 inline Matrix4 &setElem(int col, int row, float val);
1457
1458 // Get the element of a 4x4 matrix referred to by column and row indices
1459 //
1460 inline float getElem(int col, int row) const;
1461
1462 // Add two 4x4 matrices
1463 //
1464 inline const Matrix4 operator+(const Matrix4 &mat) const;
1465
1466 // Subtract a 4x4 matrix from another 4x4 matrix
1467 //
1468 inline const Matrix4 operator-(const Matrix4 &mat) const;
1469
1470 // Negate all elements of a 4x4 matrix
1471 //
1472 inline const Matrix4 operator-() const;
1473
1474 // Multiply a 4x4 matrix by a scalar
1475 //
1476 inline const Matrix4 operator*(float scalar) const;
1477
1478 // Multiply a 4x4 matrix by a 4-D vector
1479 //
1480 inline const Vector4 operator*(const Vector4 &vec) const;
1481
1482 // Multiply a 4x4 matrix by a 3-D vector
1483 //
1484 inline const Vector4 operator*(const Vector3 &vec) const;
1485
1486 // Multiply a 4x4 matrix by a 3-D point
1487 //
1488 inline const Vector4 operator*(const Point3 &pnt) const;
1489
1490 // Multiply two 4x4 matrices
1491 //
1492 inline const Matrix4 operator*(const Matrix4 &mat) const;
1493
1494 // Multiply a 4x4 matrix by a 3x4 transformation matrix
1495 //
1496 inline const Matrix4 operator*(const Transform3 &tfrm) const;
1497
1498 // Perform compound assignment and addition with a 4x4 matrix
1499 //
1500 inline Matrix4 &operator+=(const Matrix4 &mat);
1501
1502 // Perform compound assignment and subtraction by a 4x4 matrix
1503 //
1504 inline Matrix4 &operator-=(const Matrix4 &mat);
1505
1506 // Perform compound assignment and multiplication by a scalar
1507 //
1508 inline Matrix4 &operator*=(float scalar);
1509
1510 // Perform compound assignment and multiplication by a 4x4 matrix
1511 //
1512 inline Matrix4 &operator*=(const Matrix4 &mat);
1513
1514 // Perform compound assignment and multiplication by a 3x4 transformation matrix
1515 //
1516 inline Matrix4 &operator*=(const Transform3 &tfrm);
1517
1518 // Construct an identity 4x4 matrix
1519 //
1520 static inline const Matrix4 identity();
1521
1522 // Construct a 4x4 matrix to rotate around the x axis
1523 //
1524 static inline const Matrix4 rotationX(float radians);
1525
1526 // Construct a 4x4 matrix to rotate around the y axis
1527 //
1528 static inline const Matrix4 rotationY(float radians);
1529
1530 // Construct a 4x4 matrix to rotate around the z axis
1531 //
1532 static inline const Matrix4 rotationZ(float radians);
1533
1534 // Construct a 4x4 matrix to rotate around the x, y, and z axes
1535 //
1536 static inline const Matrix4 rotationZYX(const Vector3 &radiansXYZ);
1537
1538 // Construct a 4x4 matrix to rotate around a unit-length 3-D vector
1539 //
1540 static inline const Matrix4 rotation(float radians, const Vector3 &unitVec);
1541
1542 // Construct a rotation matrix from a unit-length quaternion
1543 //
1544 static inline const Matrix4 rotation(const Quat &unitQuat);
1545
1546 // Construct a 4x4 matrix to perform scaling
1547 //
1548 static inline const Matrix4 scale(const Vector3 &scaleVec);
1549
1550 // Construct a 4x4 matrix to perform translation
1551 //
1552 static inline const Matrix4 translation(const Vector3 &translateVec);
1553
1554 // Construct viewing matrix based on eye position, position looked at, and up direction
1555 //
1556 static inline const Matrix4 lookAt(const Point3 &eyePos, const Point3 &lookAtPos, const Vector3 &upVec);
1557
1558 // Construct a perspective projection matrix
1559 //
1560 static inline const Matrix4 perspective(float fovyRadians, float aspect, float zNear, float zFar);
1561
1562 // Construct a perspective projection matrix based on frustum
1563 //
1564 static inline const Matrix4 frustum(float left, float right, float bottom, float top, float zNear, float zFar);
1565
1566 // Construct an orthographic projection matrix
1567 //
1568 static inline const Matrix4 orthographic(float left, float right, float bottom, float top, float zNear, float zFar);
1569 };
1570 // Multiply a 4x4 matrix by a scalar
1571 //
1572 inline const Matrix4 operator*(float scalar, const Matrix4 &mat);
1573
1574 // Append (post-multiply) a scale transformation to a 4x4 matrix
1575 // NOTE:
1576 // Faster than creating and multiplying a scale transformation matrix.
1577 //
1578 inline const Matrix4 appendScale(const Matrix4 &mat, const Vector3 &scaleVec);
1579
1580 // Prepend (pre-multiply) a scale transformation to a 4x4 matrix
1581 // NOTE:
1582 // Faster than creating and multiplying a scale transformation matrix.
1583 //
1584 inline const Matrix4 prependScale(const Vector3 &scaleVec, const Matrix4 &mat);
1585
1586 // Multiply two 4x4 matrices per element
1587 //
1588 inline const Matrix4 mulPerElem(const Matrix4 &mat0, const Matrix4 &mat1);
1589
1590 // Compute the absolute value of a 4x4 matrix per element
1591 //
1592 inline const Matrix4 absPerElem(const Matrix4 &mat);
1593
1594 // Transpose of a 4x4 matrix
1595 //
1596 inline const Matrix4 transpose(const Matrix4 &mat);
1597
1598 // Compute the inverse of a 4x4 matrix
1599 // NOTE:
1600 // Result is unpredictable when the determinant of mat is equal to or near 0.
1601 //
1602 inline const Matrix4 inverse(const Matrix4 &mat);
1603
1604 // Compute the inverse of a 4x4 matrix, which is expected to be an affine matrix
1605 // NOTE:
1606 // 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.
1607 //
1608 inline const Matrix4 affineInverse(const Matrix4 &mat);
1609
1610 // Compute the inverse of a 4x4 matrix, which is expected to be an affine matrix with an orthogonal upper-left 3x3 submatrix
1611 // NOTE:
1612 // This can be used to achieve better performance than a general inverse when the specified 4x4 matrix meets the given restrictions.
1613 //
1614 inline const Matrix4 orthoInverse(const Matrix4 &mat);
1615
1616 // Determinant of a 4x4 matrix
1617 //
1618 inline float determinant(const Matrix4 &mat);
1619
1620 // Conditionally select between two 4x4 matrices
1621 //
1622 inline const Matrix4 select(const Matrix4 &mat0, const Matrix4 &mat1, bool select1);
1623
1624 #ifdef _VECTORMATH_DEBUG
1625
1626 // Print a 4x4 matrix
1627 // NOTE:
1628 // Function is only defined when _VECTORMATH_DEBUG is defined.
1629 //
1630 inline void print(const Matrix4 &mat);
1631
1632 // Print a 4x4 matrix and an associated string identifier
1633 // NOTE:
1634 // Function is only defined when _VECTORMATH_DEBUG is defined.
1635 //
1636 inline void print(const Matrix4 &mat, const char *name);
1637
1638 #endif
1639
1640 // A 3x4 transformation matrix in array-of-structures format
1641 //
1642 class Transform3
1643 {
1644 Vector3 mCol0;
1645 Vector3 mCol1;
1646 Vector3 mCol2;
1647 Vector3 mCol3;
1648
1649 public:
1650 // Default constructor; does no initialization
1651 //
1652 inline Transform3(){};
1653
1654 // Copy a 3x4 transformation matrix
1655 //
1656 inline Transform3(const Transform3 &tfrm);
1657
1658 // Construct a 3x4 transformation matrix containing the specified columns
1659 //
1660 inline Transform3(const Vector3 &col0, const Vector3 &col1, const Vector3 &col2, const Vector3 &col3);
1661
1662 // Construct a 3x4 transformation matrix from a 3x3 matrix and a 3-D vector
1663 //
1664 inline Transform3(const Matrix3 &tfrm, const Vector3 &translateVec);
1665
1666 // Construct a 3x4 transformation matrix from a unit-length quaternion and a 3-D vector
1667 //
1668 inline Transform3(const Quat &unitQuat, const Vector3 &translateVec);
1669
1670 // Set all elements of a 3x4 transformation matrix to the same scalar value
1671 //
1672 explicit inline Transform3(float scalar);
1673
1674 // Assign one 3x4 transformation matrix to another
1675 //
1676 inline Transform3 &operator=(const Transform3 &tfrm);
1677
1678 // Set the upper-left 3x3 submatrix
1679 //
1680 inline Transform3 &setUpper3x3(const Matrix3 &mat3);
1681
1682 // Get the upper-left 3x3 submatrix of a 3x4 transformation matrix
1683 //
1684 inline const Matrix3 getUpper3x3() const;
1685
1686 // Set translation component
1687 //
1688 inline Transform3 &setTranslation(const Vector3 &translateVec);
1689
1690 // Get the translation component of a 3x4 transformation matrix
1691 //
1692 inline const Vector3 getTranslation() const;
1693
1694 // Set column 0 of a 3x4 transformation matrix
1695 //
1696 inline Transform3 &setCol0(const Vector3 &col0);
1697
1698 // Set column 1 of a 3x4 transformation matrix
1699 //
1700 inline Transform3 &setCol1(const Vector3 &col1);
1701
1702 // Set column 2 of a 3x4 transformation matrix
1703 //
1704 inline Transform3 &setCol2(const Vector3 &col2);
1705
1706 // Set column 3 of a 3x4 transformation matrix
1707 //
1708 inline Transform3 &setCol3(const Vector3 &col3);
1709
1710 // Get column 0 of a 3x4 transformation matrix
1711 //
1712 inline const Vector3 getCol0() const;
1713
1714 // Get column 1 of a 3x4 transformation matrix
1715 //
1716 inline const Vector3 getCol1() const;
1717
1718 // Get column 2 of a 3x4 transformation matrix
1719 //
1720 inline const Vector3 getCol2() const;
1721
1722 // Get column 3 of a 3x4 transformation matrix
1723 //
1724 inline const Vector3 getCol3() const;
1725
1726 // Set the column of a 3x4 transformation matrix referred to by the specified index
1727 //
1728 inline Transform3 &setCol(int col, const Vector3 &vec);
1729
1730 // Set the row of a 3x4 transformation matrix referred to by the specified index
1731 //
1732 inline Transform3 &setRow(int row, const Vector4 &vec);
1733
1734 // Get the column of a 3x4 transformation matrix referred to by the specified index
1735 //
1736 inline const Vector3 getCol(int col) const;
1737
1738 // Get the row of a 3x4 transformation matrix referred to by the specified index
1739 //
1740 inline const Vector4 getRow(int row) const;
1741
1742 // Subscripting operator to set or get a column
1743 //
1744 inline Vector3 &operator[](int col);
1745
1746 // Subscripting operator to get a column
1747 //
1748 inline const Vector3 operator[](int col) const;
1749
1750 // Set the element of a 3x4 transformation matrix referred to by column and row indices
1751 //
1752 inline Transform3 &setElem(int col, int row, float val);
1753
1754 // Get the element of a 3x4 transformation matrix referred to by column and row indices
1755 //
1756 inline float getElem(int col, int row) const;
1757
1758 // Multiply a 3x4 transformation matrix by a 3-D vector
1759 //
1760 inline const Vector3 operator*(const Vector3 &vec) const;
1761
1762 // Multiply a 3x4 transformation matrix by a 3-D point
1763 //
1764 inline const Point3 operator*(const Point3 &pnt) const;
1765
1766 // Multiply two 3x4 transformation matrices
1767 //
1768 inline const Transform3 operator*(const Transform3 &tfrm) const;
1769
1770 // Perform compound assignment and multiplication by a 3x4 transformation matrix
1771 //
1772 inline Transform3 &operator*=(const Transform3 &tfrm);
1773
1774 // Construct an identity 3x4 transformation matrix
1775 //
1776 static inline const Transform3 identity();
1777
1778 // Construct a 3x4 transformation matrix to rotate around the x axis
1779 //
1780 static inline const Transform3 rotationX(float radians);
1781
1782 // Construct a 3x4 transformation matrix to rotate around the y axis
1783 //
1784 static inline const Transform3 rotationY(float radians);
1785
1786 // Construct a 3x4 transformation matrix to rotate around the z axis
1787 //
1788 static inline const Transform3 rotationZ(float radians);
1789
1790 // Construct a 3x4 transformation matrix to rotate around the x, y, and z axes
1791 //
1792 static inline const Transform3 rotationZYX(const Vector3 &radiansXYZ);
1793
1794 // Construct a 3x4 transformation matrix to rotate around a unit-length 3-D vector
1795 //
1796 static inline const Transform3 rotation(float radians, const Vector3 &unitVec);
1797
1798 // Construct a rotation matrix from a unit-length quaternion
1799 //
1800 static inline const Transform3 rotation(const Quat &unitQuat);
1801
1802 // Construct a 3x4 transformation matrix to perform scaling
1803 //
1804 static inline const Transform3 scale(const Vector3 &scaleVec);
1805
1806 // Construct a 3x4 transformation matrix to perform translation
1807 //
1808 static inline const Transform3 translation(const Vector3 &translateVec);
1809 };
1810 // Append (post-multiply) a scale transformation to a 3x4 transformation matrix
1811 // NOTE:
1812 // Faster than creating and multiplying a scale transformation matrix.
1813 //
1814 inline const Transform3 appendScale(const Transform3 &tfrm, const Vector3 &scaleVec);
1815
1816 // Prepend (pre-multiply) a scale transformation to a 3x4 transformation matrix
1817 // NOTE:
1818 // Faster than creating and multiplying a scale transformation matrix.
1819 //
1820 inline const Transform3 prependScale(const Vector3 &scaleVec, const Transform3 &tfrm);
1821
1822 // Multiply two 3x4 transformation matrices per element
1823 //
1824 inline const Transform3 mulPerElem(const Transform3 &tfrm0, const Transform3 &tfrm1);
1825
1826 // Compute the absolute value of a 3x4 transformation matrix per element
1827 //
1828 inline const Transform3 absPerElem(const Transform3 &tfrm);
1829
1830 // Inverse of a 3x4 transformation matrix
1831 // NOTE:
1832 // Result is unpredictable when the determinant of the left 3x3 submatrix is equal to or near 0.
1833 //
1834 inline const Transform3 inverse(const Transform3 &tfrm);
1835
1836 // Compute the inverse of a 3x4 transformation matrix, expected to have an orthogonal upper-left 3x3 submatrix
1837 // NOTE:
1838 // This can be used to achieve better performance than a general inverse when the specified 3x4 transformation matrix meets the given restrictions.
1839 //
1840 inline const Transform3 orthoInverse(const Transform3 &tfrm);
1841
1842 // Conditionally select between two 3x4 transformation matrices
1843 //
1844 inline const Transform3 select(const Transform3 &tfrm0, const Transform3 &tfrm1, bool select1);
1845
1846 #ifdef _VECTORMATH_DEBUG
1847
1848 // Print a 3x4 transformation matrix
1849 // NOTE:
1850 // Function is only defined when _VECTORMATH_DEBUG is defined.
1851 //
1852 inline void print(const Transform3 &tfrm);
1853
1854 // Print a 3x4 transformation matrix and an associated string identifier
1855 // NOTE:
1856 // Function is only defined when _VECTORMATH_DEBUG is defined.
1857 //
1858 inline void print(const Transform3 &tfrm, const char *name);
1859
1860 #endif
1861
1862 } // namespace Aos
1863 } // namespace Vectormath
1864
1865 #include "vec_aos.h"
1866 #include "quat_aos.h"
1867 #include "mat_aos.h"
1868
1869 #endif