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