neon/vectormath_aos.h

Go to the documentation of this file.
00001 /*
00002    Copyright (C) 2009 Sony Computer Entertainment Inc.
00003    All rights reserved.
00004 
00005 This software is provided 'as-is', without any express or implied warranty.
00006 In no event will the authors be held liable for any damages arising from the use of this software.
00007 Permission is granted to anyone to use this software for any purpose, 
00008 including commercial applications, and to alter it and redistribute it freely, 
00009 subject to the following restrictions:
00010 
00011 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.
00012 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
00013 3. This notice may not be removed or altered from any source distribution.
00014  
00015 This source version has been altered.
00016 
00017 */
00018 
00019 #ifndef _VECTORMATH_AOS_CPP_H
00020 #define _VECTORMATH_AOS_CPP_H
00021 
00022 #include <math.h>
00023 
00024 #ifdef _VECTORMATH_DEBUG
00025 #include <stdio.h>
00026 #endif
00027 
00028 namespace Vectormath {
00029 
00030 namespace Aos {
00031 
00032 //-----------------------------------------------------------------------------
00033 // Forward Declarations
00034 //
00035 
00036 class Vector3;
00037 class Vector4;
00038 class Point3;
00039 class Quat;
00040 class Matrix3;
00041 class Matrix4;
00042 class Transform3;
00043 
00044 // A 3-D vector in array-of-structures format
00045 //
00046 class Vector3
00047 {
00048     float mX;
00049     float mY;
00050     float mZ;
00051 #ifndef __GNUC__
00052     float d;
00053 #endif
00054 
00055 public:
00056     // Default constructor; does no initialization
00057     // 
00058     inline Vector3( ) { };
00059 
00060     // Copy a 3-D vector
00061     // 
00062     inline Vector3( const Vector3 & vec );
00063 
00064     // Construct a 3-D vector from x, y, and z elements
00065     // 
00066     inline Vector3( float x, float y, float z );
00067 
00068     // Copy elements from a 3-D point into a 3-D vector
00069     // 
00070     explicit inline Vector3( const Point3 & pnt );
00071 
00072     // Set all elements of a 3-D vector to the same scalar value
00073     // 
00074     explicit inline Vector3( float scalar );
00075 
00076     // Assign one 3-D vector to another
00077     // 
00078     inline Vector3 & operator =( const Vector3 & vec );
00079 
00080     // Set the x element of a 3-D vector
00081     // 
00082     inline Vector3 & setX( float x );
00083 
00084     // Set the y element of a 3-D vector
00085     // 
00086     inline Vector3 & setY( float y );
00087 
00088     // Set the z element of a 3-D vector
00089     // 
00090     inline Vector3 & setZ( float z );
00091 
00092     // Get the x element of a 3-D vector
00093     // 
00094     inline float getX( ) const;
00095 
00096     // Get the y element of a 3-D vector
00097     // 
00098     inline float getY( ) const;
00099 
00100     // Get the z element of a 3-D vector
00101     // 
00102     inline float getZ( ) const;
00103 
00104     // Set an x, y, or z element of a 3-D vector by index
00105     // 
00106     inline Vector3 & setElem( int idx, float value );
00107 
00108     // Get an x, y, or z element of a 3-D vector by index
00109     // 
00110     inline float getElem( int idx ) const;
00111 
00112     // Subscripting operator to set or get an element
00113     // 
00114     inline float & operator []( int idx );
00115 
00116     // Subscripting operator to get an element
00117     // 
00118     inline float operator []( int idx ) const;
00119 
00120     // Add two 3-D vectors
00121     // 
00122     inline const Vector3 operator +( const Vector3 & vec ) const;
00123 
00124     // Subtract a 3-D vector from another 3-D vector
00125     // 
00126     inline const Vector3 operator -( const Vector3 & vec ) const;
00127 
00128     // Add a 3-D vector to a 3-D point
00129     // 
00130     inline const Point3 operator +( const Point3 & pnt ) const;
00131 
00132     // Multiply a 3-D vector by a scalar
00133     // 
00134     inline const Vector3 operator *( float scalar ) const;
00135 
00136     // Divide a 3-D vector by a scalar
00137     // 
00138     inline const Vector3 operator /( float scalar ) const;
00139 
00140     // Perform compound assignment and addition with a 3-D vector
00141     // 
00142     inline Vector3 & operator +=( const Vector3 & vec );
00143 
00144     // Perform compound assignment and subtraction by a 3-D vector
00145     // 
00146     inline Vector3 & operator -=( const Vector3 & vec );
00147 
00148     // Perform compound assignment and multiplication by a scalar
00149     // 
00150     inline Vector3 & operator *=( float scalar );
00151 
00152     // Perform compound assignment and division by a scalar
00153     // 
00154     inline Vector3 & operator /=( float scalar );
00155 
00156     // Negate all elements of a 3-D vector
00157     // 
00158     inline const Vector3 operator -( ) const;
00159 
00160     // Construct x axis
00161     // 
00162     static inline const Vector3 xAxis( );
00163 
00164     // Construct y axis
00165     // 
00166     static inline const Vector3 yAxis( );
00167 
00168     // Construct z axis
00169     // 
00170     static inline const Vector3 zAxis( );
00171 
00172 }
00173 #ifdef __GNUC__
00174 __attribute__ ((aligned(16)))
00175 #endif
00176 ;
00177 
00178 // Multiply a 3-D vector by a scalar
00179 // 
00180 inline const Vector3 operator *( float scalar, const Vector3 & vec );
00181 
00182 // Multiply two 3-D vectors per element
00183 // 
00184 inline const Vector3 mulPerElem( const Vector3 & vec0, const Vector3 & vec1 );
00185 
00186 // Divide two 3-D vectors per element
00187 // NOTE: 
00188 // Floating-point behavior matches standard library function divf4.
00189 // 
00190 inline const Vector3 divPerElem( const Vector3 & vec0, const Vector3 & vec1 );
00191 
00192 // Compute the reciprocal of a 3-D vector per element
00193 // NOTE: 
00194 // Floating-point behavior matches standard library function recipf4.
00195 // 
00196 inline const Vector3 recipPerElem( const Vector3 & vec );
00197 
00198 // Compute the square root of a 3-D vector per element
00199 // NOTE: 
00200 // Floating-point behavior matches standard library function sqrtf4.
00201 // 
00202 inline const Vector3 sqrtPerElem( const Vector3 & vec );
00203 
00204 // Compute the reciprocal square root of a 3-D vector per element
00205 // NOTE: 
00206 // Floating-point behavior matches standard library function rsqrtf4.
00207 // 
00208 inline const Vector3 rsqrtPerElem( const Vector3 & vec );
00209 
00210 // Compute the absolute value of a 3-D vector per element
00211 // 
00212 inline const Vector3 absPerElem( const Vector3 & vec );
00213 
00214 // Copy sign from one 3-D vector to another, per element
00215 // 
00216 inline const Vector3 copySignPerElem( const Vector3 & vec0, const Vector3 & vec1 );
00217 
00218 // Maximum of two 3-D vectors per element
00219 // 
00220 inline const Vector3 maxPerElem( const Vector3 & vec0, const Vector3 & vec1 );
00221 
00222 // Minimum of two 3-D vectors per element
00223 // 
00224 inline const Vector3 minPerElem( const Vector3 & vec0, const Vector3 & vec1 );
00225 
00226 // Maximum element of a 3-D vector
00227 // 
00228 inline float maxElem( const Vector3 & vec );
00229 
00230 // Minimum element of a 3-D vector
00231 // 
00232 inline float minElem( const Vector3 & vec );
00233 
00234 // Compute the sum of all elements of a 3-D vector
00235 // 
00236 inline float sum( const Vector3 & vec );
00237 
00238 // Compute the dot product of two 3-D vectors
00239 // 
00240 inline float dot( const Vector3 & vec0, const Vector3 & vec1 );
00241 
00242 // Compute the square of the length of a 3-D vector
00243 // 
00244 inline float lengthSqr( const Vector3 & vec );
00245 
00246 // Compute the length of a 3-D vector
00247 // 
00248 inline float length( const Vector3 & vec );
00249 
00250 // Normalize a 3-D vector
00251 // NOTE: 
00252 // The result is unpredictable when all elements of vec are at or near zero.
00253 // 
00254 inline const Vector3 normalize( const Vector3 & vec );
00255 
00256 // Compute cross product of two 3-D vectors
00257 // 
00258 inline const Vector3 cross( const Vector3 & vec0, const Vector3 & vec1 );
00259 
00260 // Outer product of two 3-D vectors
00261 // 
00262 inline const Matrix3 outer( const Vector3 & vec0, const Vector3 & vec1 );
00263 
00264 // Pre-multiply a row vector by a 3x3 matrix
00265 // 
00266 inline const Vector3 rowMul( const Vector3 & vec, const Matrix3 & mat );
00267 
00268 // Cross-product matrix of a 3-D vector
00269 // 
00270 inline const Matrix3 crossMatrix( const Vector3 & vec );
00271 
00272 // Create cross-product matrix and multiply
00273 // NOTE: 
00274 // Faster than separately creating a cross-product matrix and multiplying.
00275 // 
00276 inline const Matrix3 crossMatrixMul( const Vector3 & vec, const Matrix3 & mat );
00277 
00278 // Linear interpolation between two 3-D vectors
00279 // NOTE: 
00280 // Does not clamp t between 0 and 1.
00281 // 
00282 inline const Vector3 lerp( float t, const Vector3 & vec0, const Vector3 & vec1 );
00283 
00284 // Spherical linear interpolation between two 3-D vectors
00285 // NOTE: 
00286 // The result is unpredictable if the vectors point in opposite directions.
00287 // Does not clamp t between 0 and 1.
00288 // 
00289 inline const Vector3 slerp( float t, const Vector3 & unitVec0, const Vector3 & unitVec1 );
00290 
00291 // Conditionally select between two 3-D vectors
00292 // 
00293 inline const Vector3 select( const Vector3 & vec0, const Vector3 & vec1, bool select1 );
00294 
00295 // Load x, y, and z elements from the first three words of a float array.
00296 // 
00297 // 
00298 inline void loadXYZ( Vector3 & vec, const float * fptr );
00299 
00300 // Store x, y, and z elements of a 3-D vector in the first three words of a float array.
00301 // Memory area of previous 16 bytes and next 32 bytes from fptr might be accessed
00302 // 
00303 inline void storeXYZ( const Vector3 & vec, float * fptr );
00304 
00305 // Load three-half-floats as a 3-D vector
00306 // NOTE: 
00307 // This transformation does not support either denormalized numbers or NaNs.
00308 // 
00309 inline void loadHalfFloats( Vector3 & vec, const unsigned short * hfptr );
00310 
00311 // 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.
00312 // NOTE: 
00313 // 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.
00314 // 
00315 inline void storeHalfFloats( const Vector3 & vec, unsigned short * hfptr );
00316 
00317 #ifdef _VECTORMATH_DEBUG
00318 
00319 // Print a 3-D vector
00320 // NOTE: 
00321 // Function is only defined when _VECTORMATH_DEBUG is defined.
00322 // 
00323 inline void print( const Vector3 & vec );
00324 
00325 // Print a 3-D vector and an associated string identifier
00326 // NOTE: 
00327 // Function is only defined when _VECTORMATH_DEBUG is defined.
00328 // 
00329 inline void print( const Vector3 & vec, const char * name );
00330 
00331 #endif
00332 
00333 // A 4-D vector in array-of-structures format
00334 //
00335 class Vector4
00336 {
00337     float mX;
00338     float mY;
00339     float mZ;
00340     float mW;
00341 
00342 public:
00343     // Default constructor; does no initialization
00344     // 
00345     inline Vector4( ) { };
00346 
00347     // Copy a 4-D vector
00348     // 
00349     inline Vector4( const Vector4 & vec );
00350 
00351     // Construct a 4-D vector from x, y, z, and w elements
00352     // 
00353     inline Vector4( float x, float y, float z, float w );
00354 
00355     // Construct a 4-D vector from a 3-D vector and a scalar
00356     // 
00357     inline Vector4( const Vector3 & xyz, float w );
00358 
00359     // Copy x, y, and z from a 3-D vector into a 4-D vector, and set w to 0
00360     // 
00361     explicit inline Vector4( const Vector3 & vec );
00362 
00363     // Copy x, y, and z from a 3-D point into a 4-D vector, and set w to 1
00364     // 
00365     explicit inline Vector4( const Point3 & pnt );
00366 
00367     // Copy elements from a quaternion into a 4-D vector
00368     // 
00369     explicit inline Vector4( const Quat & quat );
00370 
00371     // Set all elements of a 4-D vector to the same scalar value
00372     // 
00373     explicit inline Vector4( float scalar );
00374 
00375     // Assign one 4-D vector to another
00376     // 
00377     inline Vector4 & operator =( const Vector4 & vec );
00378 
00379     // Set the x, y, and z elements of a 4-D vector
00380     // NOTE: 
00381     // This function does not change the w element.
00382     // 
00383     inline Vector4 & setXYZ( const Vector3 & vec );
00384 
00385     // Get the x, y, and z elements of a 4-D vector
00386     // 
00387     inline const Vector3 getXYZ( ) const;
00388 
00389     // Set the x element of a 4-D vector
00390     // 
00391     inline Vector4 & setX( float x );
00392 
00393     // Set the y element of a 4-D vector
00394     // 
00395     inline Vector4 & setY( float y );
00396 
00397     // Set the z element of a 4-D vector
00398     // 
00399     inline Vector4 & setZ( float z );
00400 
00401     // Set the w element of a 4-D vector
00402     // 
00403     inline Vector4 & setW( float w );
00404 
00405     // Get the x element of a 4-D vector
00406     // 
00407     inline float getX( ) const;
00408 
00409     // Get the y element of a 4-D vector
00410     // 
00411     inline float getY( ) const;
00412 
00413     // Get the z element of a 4-D vector
00414     // 
00415     inline float getZ( ) const;
00416 
00417     // Get the w element of a 4-D vector
00418     // 
00419     inline float getW( ) const;
00420 
00421     // Set an x, y, z, or w element of a 4-D vector by index
00422     // 
00423     inline Vector4 & setElem( int idx, float value );
00424 
00425     // Get an x, y, z, or w element of a 4-D vector by index
00426     // 
00427     inline float getElem( int idx ) const;
00428 
00429     // Subscripting operator to set or get an element
00430     // 
00431     inline float & operator []( int idx );
00432 
00433     // Subscripting operator to get an element
00434     // 
00435     inline float operator []( int idx ) const;
00436 
00437     // Add two 4-D vectors
00438     // 
00439     inline const Vector4 operator +( const Vector4 & vec ) const;
00440 
00441     // Subtract a 4-D vector from another 4-D vector
00442     // 
00443     inline const Vector4 operator -( const Vector4 & vec ) const;
00444 
00445     // Multiply a 4-D vector by a scalar
00446     // 
00447     inline const Vector4 operator *( float scalar ) const;
00448 
00449     // Divide a 4-D vector by a scalar
00450     // 
00451     inline const Vector4 operator /( float scalar ) const;
00452 
00453     // Perform compound assignment and addition with a 4-D vector
00454     // 
00455     inline Vector4 & operator +=( const Vector4 & vec );
00456 
00457     // Perform compound assignment and subtraction by a 4-D vector
00458     // 
00459     inline Vector4 & operator -=( const Vector4 & vec );
00460 
00461     // Perform compound assignment and multiplication by a scalar
00462     // 
00463     inline Vector4 & operator *=( float scalar );
00464 
00465     // Perform compound assignment and division by a scalar
00466     // 
00467     inline Vector4 & operator /=( float scalar );
00468 
00469     // Negate all elements of a 4-D vector
00470     // 
00471     inline const Vector4 operator -( ) const;
00472 
00473     // Construct x axis
00474     // 
00475     static inline const Vector4 xAxis( );
00476 
00477     // Construct y axis
00478     // 
00479     static inline const Vector4 yAxis( );
00480 
00481     // Construct z axis
00482     // 
00483     static inline const Vector4 zAxis( );
00484 
00485     // Construct w axis
00486     // 
00487     static inline const Vector4 wAxis( );
00488 
00489 }
00490 #ifdef __GNUC__
00491 __attribute__ ((aligned(16)))
00492 #endif
00493 ;
00494 
00495 // Multiply a 4-D vector by a scalar
00496 // 
00497 inline const Vector4 operator *( float scalar, const Vector4 & vec );
00498 
00499 // Multiply two 4-D vectors per element
00500 // 
00501 inline const Vector4 mulPerElem( const Vector4 & vec0, const Vector4 & vec1 );
00502 
00503 // Divide two 4-D vectors per element
00504 // NOTE: 
00505 // Floating-point behavior matches standard library function divf4.
00506 // 
00507 inline const Vector4 divPerElem( const Vector4 & vec0, const Vector4 & vec1 );
00508 
00509 // Compute the reciprocal of a 4-D vector per element
00510 // NOTE: 
00511 // Floating-point behavior matches standard library function recipf4.
00512 // 
00513 inline const Vector4 recipPerElem( const Vector4 & vec );
00514 
00515 // Compute the square root of a 4-D vector per element
00516 // NOTE: 
00517 // Floating-point behavior matches standard library function sqrtf4.
00518 // 
00519 inline const Vector4 sqrtPerElem( const Vector4 & vec );
00520 
00521 // Compute the reciprocal square root of a 4-D vector per element
00522 // NOTE: 
00523 // Floating-point behavior matches standard library function rsqrtf4.
00524 // 
00525 inline const Vector4 rsqrtPerElem( const Vector4 & vec );
00526 
00527 // Compute the absolute value of a 4-D vector per element
00528 // 
00529 inline const Vector4 absPerElem( const Vector4 & vec );
00530 
00531 // Copy sign from one 4-D vector to another, per element
00532 // 
00533 inline const Vector4 copySignPerElem( const Vector4 & vec0, const Vector4 & vec1 );
00534 
00535 // Maximum of two 4-D vectors per element
00536 // 
00537 inline const Vector4 maxPerElem( const Vector4 & vec0, const Vector4 & vec1 );
00538 
00539 // Minimum of two 4-D vectors per element
00540 // 
00541 inline const Vector4 minPerElem( const Vector4 & vec0, const Vector4 & vec1 );
00542 
00543 // Maximum element of a 4-D vector
00544 // 
00545 inline float maxElem( const Vector4 & vec );
00546 
00547 // Minimum element of a 4-D vector
00548 // 
00549 inline float minElem( const Vector4 & vec );
00550 
00551 // Compute the sum of all elements of a 4-D vector
00552 // 
00553 inline float sum( const Vector4 & vec );
00554 
00555 // Compute the dot product of two 4-D vectors
00556 // 
00557 inline float dot( const Vector4 & vec0, const Vector4 & vec1 );
00558 
00559 // Compute the square of the length of a 4-D vector
00560 // 
00561 inline float lengthSqr( const Vector4 & vec );
00562 
00563 // Compute the length of a 4-D vector
00564 // 
00565 inline float length( const Vector4 & vec );
00566 
00567 // Normalize a 4-D vector
00568 // NOTE: 
00569 // The result is unpredictable when all elements of vec are at or near zero.
00570 // 
00571 inline const Vector4 normalize( const Vector4 & vec );
00572 
00573 // Outer product of two 4-D vectors
00574 // 
00575 inline const Matrix4 outer( const Vector4 & vec0, const Vector4 & vec1 );
00576 
00577 // Linear interpolation between two 4-D vectors
00578 // NOTE: 
00579 // Does not clamp t between 0 and 1.
00580 // 
00581 inline const Vector4 lerp( float t, const Vector4 & vec0, const Vector4 & vec1 );
00582 
00583 // Spherical linear interpolation between two 4-D vectors
00584 // NOTE: 
00585 // The result is unpredictable if the vectors point in opposite directions.
00586 // Does not clamp t between 0 and 1.
00587 // 
00588 inline const Vector4 slerp( float t, const Vector4 & unitVec0, const Vector4 & unitVec1 );
00589 
00590 // Conditionally select between two 4-D vectors
00591 // 
00592 inline const Vector4 select( const Vector4 & vec0, const Vector4 & vec1, bool select1 );
00593 
00594 // Load x, y, z, and w elements from the first four words of a float array.
00595 // 
00596 // 
00597 inline void loadXYZW( Vector4 & vec, const float * fptr );
00598 
00599 // Store x, y, z, and w elements of a 4-D vector in the first four words of a float array.
00600 // Memory area of previous 16 bytes and next 32 bytes from fptr might be accessed
00601 // 
00602 inline void storeXYZW( const Vector4 & vec, float * fptr );
00603 
00604 // Load four-half-floats as a 4-D vector
00605 // NOTE: 
00606 // This transformation does not support either denormalized numbers or NaNs.
00607 // 
00608 inline void loadHalfFloats( Vector4 & vec, const unsigned short * hfptr );
00609 
00610 // 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.
00611 // NOTE: 
00612 // 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.
00613 // 
00614 inline void storeHalfFloats( const Vector4 & vec, unsigned short * hfptr );
00615 
00616 #ifdef _VECTORMATH_DEBUG
00617 
00618 // Print a 4-D vector
00619 // NOTE: 
00620 // Function is only defined when _VECTORMATH_DEBUG is defined.
00621 // 
00622 inline void print( const Vector4 & vec );
00623 
00624 // Print a 4-D vector and an associated string identifier
00625 // NOTE: 
00626 // Function is only defined when _VECTORMATH_DEBUG is defined.
00627 // 
00628 inline void print( const Vector4 & vec, const char * name );
00629 
00630 #endif
00631 
00632 // A 3-D point in array-of-structures format
00633 //
00634 class Point3
00635 {
00636     float mX;
00637     float mY;
00638     float mZ;
00639 #ifndef __GNUC__
00640     float d;
00641 #endif
00642 
00643 public:
00644     // Default constructor; does no initialization
00645     // 
00646     inline Point3( ) { };
00647 
00648     // Copy a 3-D point
00649     // 
00650     inline Point3( const Point3 & pnt );
00651 
00652     // Construct a 3-D point from x, y, and z elements
00653     // 
00654     inline Point3( float x, float y, float z );
00655 
00656     // Copy elements from a 3-D vector into a 3-D point
00657     // 
00658     explicit inline Point3( const Vector3 & vec );
00659 
00660     // Set all elements of a 3-D point to the same scalar value
00661     // 
00662     explicit inline Point3( float scalar );
00663 
00664     // Assign one 3-D point to another
00665     // 
00666     inline Point3 & operator =( const Point3 & pnt );
00667 
00668     // Set the x element of a 3-D point
00669     // 
00670     inline Point3 & setX( float x );
00671 
00672     // Set the y element of a 3-D point
00673     // 
00674     inline Point3 & setY( float y );
00675 
00676     // Set the z element of a 3-D point
00677     // 
00678     inline Point3 & setZ( float z );
00679 
00680     // Get the x element of a 3-D point
00681     // 
00682     inline float getX( ) const;
00683 
00684     // Get the y element of a 3-D point
00685     // 
00686     inline float getY( ) const;
00687 
00688     // Get the z element of a 3-D point
00689     // 
00690     inline float getZ( ) const;
00691 
00692     // Set an x, y, or z element of a 3-D point by index
00693     // 
00694     inline Point3 & setElem( int idx, float value );
00695 
00696     // Get an x, y, or z element of a 3-D point by index
00697     // 
00698     inline float getElem( int idx ) const;
00699 
00700     // Subscripting operator to set or get an element
00701     // 
00702     inline float & operator []( int idx );
00703 
00704     // Subscripting operator to get an element
00705     // 
00706     inline float operator []( int idx ) const;
00707 
00708     // Subtract a 3-D point from another 3-D point
00709     // 
00710     inline const Vector3 operator -( const Point3 & pnt ) const;
00711 
00712     // Add a 3-D point to a 3-D vector
00713     // 
00714     inline const Point3 operator +( const Vector3 & vec ) const;
00715 
00716     // Subtract a 3-D vector from a 3-D point
00717     // 
00718     inline const Point3 operator -( const Vector3 & vec ) const;
00719 
00720     // Perform compound assignment and addition with a 3-D vector
00721     // 
00722     inline Point3 & operator +=( const Vector3 & vec );
00723 
00724     // Perform compound assignment and subtraction by a 3-D vector
00725     // 
00726     inline Point3 & operator -=( const Vector3 & vec );
00727 
00728 }
00729 #ifdef __GNUC__
00730 __attribute__ ((aligned(16)))
00731 #endif
00732 ;
00733 
00734 // Multiply two 3-D points per element
00735 // 
00736 inline const Point3 mulPerElem( const Point3 & pnt0, const Point3 & pnt1 );
00737 
00738 // Divide two 3-D points per element
00739 // NOTE: 
00740 // Floating-point behavior matches standard library function divf4.
00741 // 
00742 inline const Point3 divPerElem( const Point3 & pnt0, const Point3 & pnt1 );
00743 
00744 // Compute the reciprocal of a 3-D point per element
00745 // NOTE: 
00746 // Floating-point behavior matches standard library function recipf4.
00747 // 
00748 inline const Point3 recipPerElem( const Point3 & pnt );
00749 
00750 // Compute the square root of a 3-D point per element
00751 // NOTE: 
00752 // Floating-point behavior matches standard library function sqrtf4.
00753 // 
00754 inline const Point3 sqrtPerElem( const Point3 & pnt );
00755 
00756 // Compute the reciprocal square root of a 3-D point per element
00757 // NOTE: 
00758 // Floating-point behavior matches standard library function rsqrtf4.
00759 // 
00760 inline const Point3 rsqrtPerElem( const Point3 & pnt );
00761 
00762 // Compute the absolute value of a 3-D point per element
00763 // 
00764 inline const Point3 absPerElem( const Point3 & pnt );
00765 
00766 // Copy sign from one 3-D point to another, per element
00767 // 
00768 inline const Point3 copySignPerElem( const Point3 & pnt0, const Point3 & pnt1 );
00769 
00770 // Maximum of two 3-D points per element
00771 // 
00772 inline const Point3 maxPerElem( const Point3 & pnt0, const Point3 & pnt1 );
00773 
00774 // Minimum of two 3-D points per element
00775 // 
00776 inline const Point3 minPerElem( const Point3 & pnt0, const Point3 & pnt1 );
00777 
00778 // Maximum element of a 3-D point
00779 // 
00780 inline float maxElem( const Point3 & pnt );
00781 
00782 // Minimum element of a 3-D point
00783 // 
00784 inline float minElem( const Point3 & pnt );
00785 
00786 // Compute the sum of all elements of a 3-D point
00787 // 
00788 inline float sum( const Point3 & pnt );
00789 
00790 // Apply uniform scale to a 3-D point
00791 // 
00792 inline const Point3 scale( const Point3 & pnt, float scaleVal );
00793 
00794 // Apply non-uniform scale to a 3-D point
00795 // 
00796 inline const Point3 scale( const Point3 & pnt, const Vector3 & scaleVec );
00797 
00798 // Scalar projection of a 3-D point on a unit-length 3-D vector
00799 // 
00800 inline float projection( const Point3 & pnt, const Vector3 & unitVec );
00801 
00802 // Compute the square of the distance of a 3-D point from the coordinate-system origin
00803 // 
00804 inline float distSqrFromOrigin( const Point3 & pnt );
00805 
00806 // Compute the distance of a 3-D point from the coordinate-system origin
00807 // 
00808 inline float distFromOrigin( const Point3 & pnt );
00809 
00810 // Compute the square of the distance between two 3-D points
00811 // 
00812 inline float distSqr( const Point3 & pnt0, const Point3 & pnt1 );
00813 
00814 // Compute the distance between two 3-D points
00815 // 
00816 inline float dist( const Point3 & pnt0, const Point3 & pnt1 );
00817 
00818 // Linear interpolation between two 3-D points
00819 // NOTE: 
00820 // Does not clamp t between 0 and 1.
00821 // 
00822 inline const Point3 lerp( float t, const Point3 & pnt0, const Point3 & pnt1 );
00823 
00824 // Conditionally select between two 3-D points
00825 // 
00826 inline const Point3 select( const Point3 & pnt0, const Point3 & pnt1, bool select1 );
00827 
00828 // Load x, y, and z elements from the first three words of a float array.
00829 // 
00830 // 
00831 inline void loadXYZ( Point3 & pnt, const float * fptr );
00832 
00833 // Store x, y, and z elements of a 3-D point in the first three words of a float array.
00834 // Memory area of previous 16 bytes and next 32 bytes from fptr might be accessed
00835 // 
00836 inline void storeXYZ( const Point3 & pnt, float * fptr );
00837 
00838 // Load three-half-floats as a 3-D point
00839 // NOTE: 
00840 // This transformation does not support either denormalized numbers or NaNs.
00841 // 
00842 inline void loadHalfFloats( Point3 & pnt, const unsigned short * hfptr );
00843 
00844 // 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.
00845 // NOTE: 
00846 // 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.
00847 // 
00848 inline void storeHalfFloats( const Point3 & pnt, unsigned short * hfptr );
00849 
00850 #ifdef _VECTORMATH_DEBUG
00851 
00852 // Print a 3-D point
00853 // NOTE: 
00854 // Function is only defined when _VECTORMATH_DEBUG is defined.
00855 // 
00856 inline void print( const Point3 & pnt );
00857 
00858 // Print a 3-D point and an associated string identifier
00859 // NOTE: 
00860 // Function is only defined when _VECTORMATH_DEBUG is defined.
00861 // 
00862 inline void print( const Point3 & pnt, const char * name );
00863 
00864 #endif
00865 
00866 // A quaternion in array-of-structures format
00867 //
00868 class Quat
00869 {
00870 #if defined( __APPLE__ ) && defined( BT_USE_NEON )
00871     union{
00872         float32x4_t vXYZW;
00873         float mXYZW[4];
00874     };
00875 #else
00876     float mX;
00877     float mY;
00878     float mZ;
00879     float mW;
00880 #endif
00881 
00882 public:
00883     // Default constructor; does no initialization
00884     // 
00885     inline Quat( ) { };
00886 
00887     // Copy a quaternion
00888     // 
00889     inline Quat( const Quat & quat );
00890 
00891     // Construct a quaternion from x, y, z, and w elements
00892     // 
00893     inline Quat( float x, float y, float z, float w );
00894     
00895     // Construct a quaternion from vector of x, y, z, and w elements
00896     // 
00897     inline Quat( float32x4_t fXYZW );
00898 
00899     // Construct a quaternion from a 3-D vector and a scalar
00900     // 
00901     inline Quat( const Vector3 & xyz, float w );
00902 
00903     // Copy elements from a 4-D vector into a quaternion
00904     // 
00905     explicit inline Quat( const Vector4 & vec );
00906 
00907     // Convert a rotation matrix to a unit-length quaternion
00908     // 
00909     explicit inline Quat( const Matrix3 & rotMat );
00910 
00911     // Set all elements of a quaternion to the same scalar value
00912     // 
00913     explicit inline Quat( float scalar );
00914     
00915     // Assign one quaternion to another
00916     // 
00917     inline Quat & operator =( const Quat & quat );
00918 
00919     // Set the x, y, and z elements of a quaternion
00920     // NOTE: 
00921     // This function does not change the w element.
00922     // 
00923     inline Quat & setXYZ( const Vector3 & vec );
00924 
00925     // Get the x, y, and z elements of a quaternion
00926     // 
00927     inline const Vector3 getXYZ( ) const;
00928 
00929     // Set the x element of a quaternion
00930     // 
00931     inline Quat & setX( float x );
00932 
00933     // Set the y element of a quaternion
00934     // 
00935     inline Quat & setY( float y );
00936 
00937     // Set the z element of a quaternion
00938     // 
00939     inline Quat & setZ( float z );
00940 
00941     // Set the w element of a quaternion
00942     // 
00943     inline Quat & setW( float w );
00944 
00945 #if defined( __APPLE__ ) && defined( BT_USE_NEON )
00946     inline float32x4_t getvXYZW( ) const;
00947 #endif
00948     
00949     // Get the x element of a quaternion
00950     // 
00951     inline float getX( ) const;
00952 
00953     // Get the y element of a quaternion
00954     // 
00955     inline float getY( ) const;
00956 
00957     // Get the z element of a quaternion
00958     // 
00959     inline float getZ( ) const;
00960 
00961     // Get the w element of a quaternion
00962     // 
00963     inline float getW( ) const;
00964 
00965     // Set an x, y, z, or w element of a quaternion by index
00966     // 
00967     inline Quat & setElem( int idx, float value );
00968 
00969     // Get an x, y, z, or w element of a quaternion by index
00970     // 
00971     inline float getElem( int idx ) const;
00972 
00973     // Subscripting operator to set or get an element
00974     // 
00975     inline float & operator []( int idx );
00976 
00977     // Subscripting operator to get an element
00978     // 
00979     inline float operator []( int idx ) const;
00980 
00981     // Add two quaternions
00982     // 
00983     inline const Quat operator +( const Quat & quat ) const;
00984 
00985     // Subtract a quaternion from another quaternion
00986     // 
00987     inline const Quat operator -( const Quat & quat ) const;
00988 
00989     // Multiply two quaternions
00990     // 
00991     inline const Quat operator *( const Quat & quat ) const;
00992 
00993     // Multiply a quaternion by a scalar
00994     // 
00995     inline const Quat operator *( float scalar ) const;
00996 
00997     // Divide a quaternion by a scalar
00998     // 
00999     inline const Quat operator /( float scalar ) const;
01000 
01001     // Perform compound assignment and addition with a quaternion
01002     // 
01003     inline Quat & operator +=( const Quat & quat );
01004 
01005     // Perform compound assignment and subtraction by a quaternion
01006     // 
01007     inline Quat & operator -=( const Quat & quat );
01008 
01009     // Perform compound assignment and multiplication by a quaternion
01010     // 
01011     inline Quat & operator *=( const Quat & quat );
01012 
01013     // Perform compound assignment and multiplication by a scalar
01014     // 
01015     inline Quat & operator *=( float scalar );
01016 
01017     // Perform compound assignment and division by a scalar
01018     // 
01019     inline Quat & operator /=( float scalar );
01020 
01021     // Negate all elements of a quaternion
01022     // 
01023     inline const Quat operator -( ) const;
01024 
01025     // Construct an identity quaternion
01026     // 
01027     static inline const Quat identity( );
01028 
01029     // Construct a quaternion to rotate between two unit-length 3-D vectors
01030     // NOTE: 
01031     // The result is unpredictable if unitVec0 and unitVec1 point in opposite directions.
01032     // 
01033     static inline const Quat rotation( const Vector3 & unitVec0, const Vector3 & unitVec1 );
01034 
01035     // Construct a quaternion to rotate around a unit-length 3-D vector
01036     // 
01037     static inline const Quat rotation( float radians, const Vector3 & unitVec );
01038 
01039     // Construct a quaternion to rotate around the x axis
01040     // 
01041     static inline const Quat rotationX( float radians );
01042 
01043     // Construct a quaternion to rotate around the y axis
01044     // 
01045     static inline const Quat rotationY( float radians );
01046 
01047     // Construct a quaternion to rotate around the z axis
01048     // 
01049     static inline const Quat rotationZ( float radians );
01050 
01051 }
01052 #ifdef __GNUC__
01053 __attribute__ ((aligned(16)))
01054 #endif
01055 ;
01056 
01057 // Multiply a quaternion by a scalar
01058 // 
01059 inline const Quat operator *( float scalar, const Quat & quat );
01060 
01061 // Compute the conjugate of a quaternion
01062 // 
01063 inline const Quat conj( const Quat & quat );
01064 
01065 // Use a unit-length quaternion to rotate a 3-D vector
01066 // 
01067 inline const Vector3 rotate( const Quat & unitQuat, const Vector3 & vec );
01068 
01069 // Compute the dot product of two quaternions
01070 // 
01071 inline float dot( const Quat & quat0, const Quat & quat1 );
01072 
01073 // Compute the norm of a quaternion
01074 // 
01075 inline float norm( const Quat & quat );
01076 
01077 // Compute the length of a quaternion
01078 // 
01079 inline float length( const Quat & quat );
01080 
01081 // Normalize a quaternion
01082 // NOTE: 
01083 // The result is unpredictable when all elements of quat are at or near zero.
01084 // 
01085 inline const Quat normalize( const Quat & quat );
01086 
01087 // Linear interpolation between two quaternions
01088 // NOTE: 
01089 // Does not clamp t between 0 and 1.
01090 // 
01091 inline const Quat lerp( float t, const Quat & quat0, const Quat & quat1 );
01092 
01093 // Spherical linear interpolation between two quaternions
01094 // NOTE: 
01095 // Interpolates along the shortest path between orientations.
01096 // Does not clamp t between 0 and 1.
01097 // 
01098 inline const Quat slerp( float t, const Quat & unitQuat0, const Quat & unitQuat1 );
01099 
01100 // Spherical quadrangle interpolation
01101 // 
01102 inline const Quat squad( float t, const Quat & unitQuat0, const Quat & unitQuat1, const Quat & unitQuat2, const Quat & unitQuat3 );
01103 
01104 // Conditionally select between two quaternions
01105 // 
01106 inline const Quat select( const Quat & quat0, const Quat & quat1, bool select1 );
01107 
01108 // Load x, y, z, and w elements from the first four words of a float array.
01109 // 
01110 // 
01111 inline void loadXYZW( Quat & quat, const float * fptr );
01112 
01113 // Store x, y, z, and w elements of a quaternion in the first four words of a float array.
01114 // Memory area of previous 16 bytes and next 32 bytes from fptr might be accessed
01115 // 
01116 inline void storeXYZW( const Quat & quat, float * fptr );
01117 
01118 #ifdef _VECTORMATH_DEBUG
01119 
01120 // Print a quaternion
01121 // NOTE: 
01122 // Function is only defined when _VECTORMATH_DEBUG is defined.
01123 // 
01124 inline void print( const Quat & quat );
01125 
01126 // Print a quaternion and an associated string identifier
01127 // NOTE: 
01128 // Function is only defined when _VECTORMATH_DEBUG is defined.
01129 // 
01130 inline void print( const Quat & quat, const char * name );
01131 
01132 #endif
01133 
01134 // A 3x3 matrix in array-of-structures format
01135 //
01136 class Matrix3
01137 {
01138     Vector3 mCol0;
01139     Vector3 mCol1;
01140     Vector3 mCol2;
01141 
01142 public:
01143     // Default constructor; does no initialization
01144     // 
01145     inline Matrix3( ) { };
01146 
01147     // Copy a 3x3 matrix
01148     // 
01149     inline Matrix3( const Matrix3 & mat );
01150 
01151     // Construct a 3x3 matrix containing the specified columns
01152     // 
01153     inline Matrix3( const Vector3 & col0, const Vector3 & col1, const Vector3 & col2 );
01154 
01155     // Construct a 3x3 rotation matrix from a unit-length quaternion
01156     // 
01157     explicit inline Matrix3( const Quat & unitQuat );
01158 
01159     // Set all elements of a 3x3 matrix to the same scalar value
01160     // 
01161     explicit inline Matrix3( float scalar );
01162 
01163     // Assign one 3x3 matrix to another
01164     // 
01165     inline Matrix3 & operator =( const Matrix3 & mat );
01166 
01167     // Set column 0 of a 3x3 matrix
01168     // 
01169     inline Matrix3 & setCol0( const Vector3 & col0 );
01170 
01171     // Set column 1 of a 3x3 matrix
01172     // 
01173     inline Matrix3 & setCol1( const Vector3 & col1 );
01174 
01175     // Set column 2 of a 3x3 matrix
01176     // 
01177     inline Matrix3 & setCol2( const Vector3 & col2 );
01178 
01179     // Get column 0 of a 3x3 matrix
01180     // 
01181     inline const Vector3 getCol0( ) const;
01182 
01183     // Get column 1 of a 3x3 matrix
01184     // 
01185     inline const Vector3 getCol1( ) const;
01186 
01187     // Get column 2 of a 3x3 matrix
01188     // 
01189     inline const Vector3 getCol2( ) const;
01190 
01191     // Set the column of a 3x3 matrix referred to by the specified index
01192     // 
01193     inline Matrix3 & setCol( int col, const Vector3 & vec );
01194 
01195     // Set the row of a 3x3 matrix referred to by the specified index
01196     // 
01197     inline Matrix3 & setRow( int row, const Vector3 & vec );
01198 
01199     // Get the column of a 3x3 matrix referred to by the specified index
01200     // 
01201     inline const Vector3 getCol( int col ) const;
01202 
01203     // Get the row of a 3x3 matrix referred to by the specified index
01204     // 
01205     inline const Vector3 getRow( int row ) const;
01206 
01207     // Subscripting operator to set or get a column
01208     // 
01209     inline Vector3 & operator []( int col );
01210 
01211     // Subscripting operator to get a column
01212     // 
01213     inline const Vector3 operator []( int col ) const;
01214 
01215     // Set the element of a 3x3 matrix referred to by column and row indices
01216     // 
01217     inline Matrix3 & setElem( int col, int row, float val );
01218 
01219     // Get the element of a 3x3 matrix referred to by column and row indices
01220     // 
01221     inline float getElem( int col, int row ) const;
01222 
01223     // Add two 3x3 matrices
01224     // 
01225     inline const Matrix3 operator +( const Matrix3 & mat ) const;
01226 
01227     // Subtract a 3x3 matrix from another 3x3 matrix
01228     // 
01229     inline const Matrix3 operator -( const Matrix3 & mat ) const;
01230 
01231     // Negate all elements of a 3x3 matrix
01232     // 
01233     inline const Matrix3 operator -( ) const;
01234 
01235     // Multiply a 3x3 matrix by a scalar
01236     // 
01237     inline const Matrix3 operator *( float scalar ) const;
01238 
01239     // Multiply a 3x3 matrix by a 3-D vector
01240     // 
01241     inline const Vector3 operator *( const Vector3 & vec ) const;
01242 
01243     // Multiply two 3x3 matrices
01244     // 
01245     inline const Matrix3 operator *( const Matrix3 & mat ) const;
01246 
01247     // Perform compound assignment and addition with a 3x3 matrix
01248     // 
01249     inline Matrix3 & operator +=( const Matrix3 & mat );
01250 
01251     // Perform compound assignment and subtraction by a 3x3 matrix
01252     // 
01253     inline Matrix3 & operator -=( const Matrix3 & mat );
01254 
01255     // Perform compound assignment and multiplication by a scalar
01256     // 
01257     inline Matrix3 & operator *=( float scalar );
01258 
01259     // Perform compound assignment and multiplication by a 3x3 matrix
01260     // 
01261     inline Matrix3 & operator *=( const Matrix3 & mat );
01262 
01263     // Construct an identity 3x3 matrix
01264     // 
01265     static inline const Matrix3 identity( );
01266 
01267     // Construct a 3x3 matrix to rotate around the x axis
01268     // 
01269     static inline const Matrix3 rotationX( float radians );
01270 
01271     // Construct a 3x3 matrix to rotate around the y axis
01272     // 
01273     static inline const Matrix3 rotationY( float radians );
01274 
01275     // Construct a 3x3 matrix to rotate around the z axis
01276     // 
01277     static inline const Matrix3 rotationZ( float radians );
01278 
01279     // Construct a 3x3 matrix to rotate around the x, y, and z axes
01280     // 
01281     static inline const Matrix3 rotationZYX( const Vector3 & radiansXYZ );
01282 
01283     // Construct a 3x3 matrix to rotate around a unit-length 3-D vector
01284     // 
01285     static inline const Matrix3 rotation( float radians, const Vector3 & unitVec );
01286 
01287     // Construct a rotation matrix from a unit-length quaternion
01288     // 
01289     static inline const Matrix3 rotation( const Quat & unitQuat );
01290 
01291     // Construct a 3x3 matrix to perform scaling
01292     // 
01293     static inline const Matrix3 scale( const Vector3 & scaleVec );
01294 
01295 };
01296 // Multiply a 3x3 matrix by a scalar
01297 // 
01298 inline const Matrix3 operator *( float scalar, const Matrix3 & mat );
01299 
01300 // Append (post-multiply) a scale transformation to a 3x3 matrix
01301 // NOTE: 
01302 // Faster than creating and multiplying a scale transformation matrix.
01303 // 
01304 inline const Matrix3 appendScale( const Matrix3 & mat, const Vector3 & scaleVec );
01305 
01306 // Prepend (pre-multiply) a scale transformation to a 3x3 matrix
01307 // NOTE: 
01308 // Faster than creating and multiplying a scale transformation matrix.
01309 // 
01310 inline const Matrix3 prependScale( const Vector3 & scaleVec, const Matrix3 & mat );
01311 
01312 // Multiply two 3x3 matrices per element
01313 // 
01314 inline const Matrix3 mulPerElem( const Matrix3 & mat0, const Matrix3 & mat1 );
01315 
01316 // Compute the absolute value of a 3x3 matrix per element
01317 // 
01318 inline const Matrix3 absPerElem( const Matrix3 & mat );
01319 
01320 // Transpose of a 3x3 matrix
01321 // 
01322 inline const Matrix3 transpose( const Matrix3 & mat );
01323 
01324 // Compute the inverse of a 3x3 matrix
01325 // NOTE: 
01326 // Result is unpredictable when the determinant of mat is equal to or near 0.
01327 // 
01328 inline const Matrix3 inverse( const Matrix3 & mat );
01329 
01330 // Determinant of a 3x3 matrix
01331 // 
01332 inline float determinant( const Matrix3 & mat );
01333 
01334 // Conditionally select between two 3x3 matrices
01335 // 
01336 inline const Matrix3 select( const Matrix3 & mat0, const Matrix3 & mat1, bool select1 );
01337 
01338 #ifdef _VECTORMATH_DEBUG
01339 
01340 // Print a 3x3 matrix
01341 // NOTE: 
01342 // Function is only defined when _VECTORMATH_DEBUG is defined.
01343 // 
01344 inline void print( const Matrix3 & mat );
01345 
01346 // Print a 3x3 matrix and an associated string identifier
01347 // NOTE: 
01348 // Function is only defined when _VECTORMATH_DEBUG is defined.
01349 // 
01350 inline void print( const Matrix3 & mat, const char * name );
01351 
01352 #endif
01353 
01354 // A 4x4 matrix in array-of-structures format
01355 //
01356 class Matrix4
01357 {
01358     Vector4 mCol0;
01359     Vector4 mCol1;
01360     Vector4 mCol2;
01361     Vector4 mCol3;
01362 
01363 public:
01364     // Default constructor; does no initialization
01365     // 
01366     inline Matrix4( ) { };
01367 
01368     // Copy a 4x4 matrix
01369     // 
01370     inline Matrix4( const Matrix4 & mat );
01371 
01372     // Construct a 4x4 matrix containing the specified columns
01373     // 
01374     inline Matrix4( const Vector4 & col0, const Vector4 & col1, const Vector4 & col2, const Vector4 & col3 );
01375 
01376     // Construct a 4x4 matrix from a 3x4 transformation matrix
01377     // 
01378     explicit inline Matrix4( const Transform3 & mat );
01379 
01380     // Construct a 4x4 matrix from a 3x3 matrix and a 3-D vector
01381     // 
01382     inline Matrix4( const Matrix3 & mat, const Vector3 & translateVec );
01383 
01384     // Construct a 4x4 matrix from a unit-length quaternion and a 3-D vector
01385     // 
01386     inline Matrix4( const Quat & unitQuat, const Vector3 & translateVec );
01387 
01388     // Set all elements of a 4x4 matrix to the same scalar value
01389     // 
01390     explicit inline Matrix4( float scalar );
01391 
01392     // Assign one 4x4 matrix to another
01393     // 
01394     inline Matrix4 & operator =( const Matrix4 & mat );
01395 
01396     // Set the upper-left 3x3 submatrix
01397     // NOTE: 
01398     // This function does not change the bottom row elements.
01399     // 
01400     inline Matrix4 & setUpper3x3( const Matrix3 & mat3 );
01401 
01402     // Get the upper-left 3x3 submatrix of a 4x4 matrix
01403     // 
01404     inline const Matrix3 getUpper3x3( ) const;
01405 
01406     // Set translation component
01407     // NOTE: 
01408     // This function does not change the bottom row elements.
01409     // 
01410     inline Matrix4 & setTranslation( const Vector3 & translateVec );
01411 
01412     // Get the translation component of a 4x4 matrix
01413     // 
01414     inline const Vector3 getTranslation( ) const;
01415 
01416     // Set column 0 of a 4x4 matrix
01417     // 
01418     inline Matrix4 & setCol0( const Vector4 & col0 );
01419 
01420     // Set column 1 of a 4x4 matrix
01421     // 
01422     inline Matrix4 & setCol1( const Vector4 & col1 );
01423 
01424     // Set column 2 of a 4x4 matrix
01425     // 
01426     inline Matrix4 & setCol2( const Vector4 & col2 );
01427 
01428     // Set column 3 of a 4x4 matrix
01429     // 
01430     inline Matrix4 & setCol3( const Vector4 & col3 );
01431 
01432     // Get column 0 of a 4x4 matrix
01433     // 
01434     inline const Vector4 getCol0( ) const;
01435 
01436     // Get column 1 of a 4x4 matrix
01437     // 
01438     inline const Vector4 getCol1( ) const;
01439 
01440     // Get column 2 of a 4x4 matrix
01441     // 
01442     inline const Vector4 getCol2( ) const;
01443 
01444     // Get column 3 of a 4x4 matrix
01445     // 
01446     inline const Vector4 getCol3( ) const;
01447 
01448     // Set the column of a 4x4 matrix referred to by the specified index
01449     // 
01450     inline Matrix4 & setCol( int col, const Vector4 & vec );
01451 
01452     // Set the row of a 4x4 matrix referred to by the specified index
01453     // 
01454     inline Matrix4 & setRow( int row, const Vector4 & vec );
01455 
01456     // Get the column of a 4x4 matrix referred to by the specified index
01457     // 
01458     inline const Vector4 getCol( int col ) const;
01459 
01460     // Get the row of a 4x4 matrix referred to by the specified index
01461     // 
01462     inline const Vector4 getRow( int row ) const;
01463 
01464     // Subscripting operator to set or get a column
01465     // 
01466     inline Vector4 & operator []( int col );
01467 
01468     // Subscripting operator to get a column
01469     // 
01470     inline const Vector4 operator []( int col ) const;
01471 
01472     // Set the element of a 4x4 matrix referred to by column and row indices
01473     // 
01474     inline Matrix4 & setElem( int col, int row, float val );
01475 
01476     // Get the element of a 4x4 matrix referred to by column and row indices
01477     // 
01478     inline float getElem( int col, int row ) const;
01479 
01480     // Add two 4x4 matrices
01481     // 
01482     inline const Matrix4 operator +( const Matrix4 & mat ) const;
01483 
01484     // Subtract a 4x4 matrix from another 4x4 matrix
01485     // 
01486     inline const Matrix4 operator -( const Matrix4 & mat ) const;
01487 
01488     // Negate all elements of a 4x4 matrix
01489     // 
01490     inline const Matrix4 operator -( ) const;
01491 
01492     // Multiply a 4x4 matrix by a scalar
01493     // 
01494     inline const Matrix4 operator *( float scalar ) const;
01495 
01496     // Multiply a 4x4 matrix by a 4-D vector
01497     // 
01498     inline const Vector4 operator *( const Vector4 & vec ) const;
01499 
01500     // Multiply a 4x4 matrix by a 3-D vector
01501     // 
01502     inline const Vector4 operator *( const Vector3 & vec ) const;
01503 
01504     // Multiply a 4x4 matrix by a 3-D point
01505     // 
01506     inline const Vector4 operator *( const Point3 & pnt ) const;
01507 
01508     // Multiply two 4x4 matrices
01509     // 
01510     inline const Matrix4 operator *( const Matrix4 & mat ) const;
01511 
01512     // Multiply a 4x4 matrix by a 3x4 transformation matrix
01513     // 
01514     inline const Matrix4 operator *( const Transform3 & tfrm ) const;
01515 
01516     // Perform compound assignment and addition with a 4x4 matrix
01517     // 
01518     inline Matrix4 & operator +=( const Matrix4 & mat );
01519 
01520     // Perform compound assignment and subtraction by a 4x4 matrix
01521     // 
01522     inline Matrix4 & operator -=( const Matrix4 & mat );
01523 
01524     // Perform compound assignment and multiplication by a scalar
01525     // 
01526     inline Matrix4 & operator *=( float scalar );
01527 
01528     // Perform compound assignment and multiplication by a 4x4 matrix
01529     // 
01530     inline Matrix4 & operator *=( const Matrix4 & mat );
01531 
01532     // Perform compound assignment and multiplication by a 3x4 transformation matrix
01533     // 
01534     inline Matrix4 & operator *=( const Transform3 & tfrm );
01535 
01536     // Construct an identity 4x4 matrix
01537     // 
01538     static inline const Matrix4 identity( );
01539 
01540     // Construct a 4x4 matrix to rotate around the x axis
01541     // 
01542     static inline const Matrix4 rotationX( float radians );
01543 
01544     // Construct a 4x4 matrix to rotate around the y axis
01545     // 
01546     static inline const Matrix4 rotationY( float radians );
01547 
01548     // Construct a 4x4 matrix to rotate around the z axis
01549     // 
01550     static inline const Matrix4 rotationZ( float radians );
01551 
01552     // Construct a 4x4 matrix to rotate around the x, y, and z axes
01553     // 
01554     static inline const Matrix4 rotationZYX( const Vector3 & radiansXYZ );
01555 
01556     // Construct a 4x4 matrix to rotate around a unit-length 3-D vector
01557     // 
01558     static inline const Matrix4 rotation( float radians, const Vector3 & unitVec );
01559 
01560     // Construct a rotation matrix from a unit-length quaternion
01561     // 
01562     static inline const Matrix4 rotation( const Quat & unitQuat );
01563 
01564     // Construct a 4x4 matrix to perform scaling
01565     // 
01566     static inline const Matrix4 scale( const Vector3 & scaleVec );
01567 
01568     // Construct a 4x4 matrix to perform translation
01569     // 
01570     static inline const Matrix4 translation( const Vector3 & translateVec );
01571 
01572     // Construct viewing matrix based on eye position, position looked at, and up direction
01573     // 
01574     static inline const Matrix4 lookAt( const Point3 & eyePos, const Point3 & lookAtPos, const Vector3 & upVec );
01575 
01576     // Construct a perspective projection matrix
01577     // 
01578     static inline const Matrix4 perspective( float fovyRadians, float aspect, float zNear, float zFar );
01579 
01580     // Construct a perspective projection matrix based on frustum
01581     // 
01582     static inline const Matrix4 frustum( float left, float right, float bottom, float top, float zNear, float zFar );
01583 
01584     // Construct an orthographic projection matrix
01585     // 
01586     static inline const Matrix4 orthographic( float left, float right, float bottom, float top, float zNear, float zFar );
01587 
01588 };
01589 // Multiply a 4x4 matrix by a scalar
01590 // 
01591 inline const Matrix4 operator *( float scalar, const Matrix4 & mat );
01592 
01593 // Append (post-multiply) a scale transformation to a 4x4 matrix
01594 // NOTE: 
01595 // Faster than creating and multiplying a scale transformation matrix.
01596 // 
01597 inline const Matrix4 appendScale( const Matrix4 & mat, const Vector3 & scaleVec );
01598 
01599 // Prepend (pre-multiply) a scale transformation to a 4x4 matrix
01600 // NOTE: 
01601 // Faster than creating and multiplying a scale transformation matrix.
01602 // 
01603 inline const Matrix4 prependScale( const Vector3 & scaleVec, const Matrix4 & mat );
01604 
01605 // Multiply two 4x4 matrices per element
01606 // 
01607 inline const Matrix4 mulPerElem( const Matrix4 & mat0, const Matrix4 & mat1 );
01608 
01609 // Compute the absolute value of a 4x4 matrix per element
01610 // 
01611 inline const Matrix4 absPerElem( const Matrix4 & mat );
01612 
01613 // Transpose of a 4x4 matrix
01614 // 
01615 inline const Matrix4 transpose( const Matrix4 & mat );
01616 
01617 // Compute the inverse of a 4x4 matrix
01618 // NOTE: 
01619 // Result is unpredictable when the determinant of mat is equal to or near 0.
01620 // 
01621 inline const Matrix4 inverse( const Matrix4 & mat );
01622 
01623 // Compute the inverse of a 4x4 matrix, which is expected to be an affine matrix
01624 // NOTE: 
01625 // 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.
01626 // 
01627 inline const Matrix4 affineInverse( const Matrix4 & mat );
01628 
01629 // Compute the inverse of a 4x4 matrix, which is expected to be an affine matrix with an orthogonal upper-left 3x3 submatrix
01630 // NOTE: 
01631 // This can be used to achieve better performance than a general inverse when the specified 4x4 matrix meets the given restrictions.
01632 // 
01633 inline const Matrix4 orthoInverse( const Matrix4 & mat );
01634 
01635 // Determinant of a 4x4 matrix
01636 // 
01637 inline float determinant( const Matrix4 & mat );
01638 
01639 // Conditionally select between two 4x4 matrices
01640 // 
01641 inline const Matrix4 select( const Matrix4 & mat0, const Matrix4 & mat1, bool select1 );
01642 
01643 #ifdef _VECTORMATH_DEBUG
01644 
01645 // Print a 4x4 matrix
01646 // NOTE: 
01647 // Function is only defined when _VECTORMATH_DEBUG is defined.
01648 // 
01649 inline void print( const Matrix4 & mat );
01650 
01651 // Print a 4x4 matrix and an associated string identifier
01652 // NOTE: 
01653 // Function is only defined when _VECTORMATH_DEBUG is defined.
01654 // 
01655 inline void print( const Matrix4 & mat, const char * name );
01656 
01657 #endif
01658 
01659 // A 3x4 transformation matrix in array-of-structures format
01660 //
01661 class Transform3
01662 {
01663     Vector3 mCol0;
01664     Vector3 mCol1;
01665     Vector3 mCol2;
01666     Vector3 mCol3;
01667 
01668 public:
01669     // Default constructor; does no initialization
01670     // 
01671     inline Transform3( ) { };
01672 
01673     // Copy a 3x4 transformation matrix
01674     // 
01675     inline Transform3( const Transform3 & tfrm );
01676 
01677     // Construct a 3x4 transformation matrix containing the specified columns
01678     // 
01679     inline Transform3( const Vector3 & col0, const Vector3 & col1, const Vector3 & col2, const Vector3 & col3 );
01680 
01681     // Construct a 3x4 transformation matrix from a 3x3 matrix and a 3-D vector
01682     // 
01683     inline Transform3( const Matrix3 & tfrm, const Vector3 & translateVec );
01684 
01685     // Construct a 3x4 transformation matrix from a unit-length quaternion and a 3-D vector
01686     // 
01687     inline Transform3( const Quat & unitQuat, const Vector3 & translateVec );
01688 
01689     // Set all elements of a 3x4 transformation matrix to the same scalar value
01690     // 
01691     explicit inline Transform3( float scalar );
01692 
01693     // Assign one 3x4 transformation matrix to another
01694     // 
01695     inline Transform3 & operator =( const Transform3 & tfrm );
01696 
01697     // Set the upper-left 3x3 submatrix
01698     // 
01699     inline Transform3 & setUpper3x3( const Matrix3 & mat3 );
01700 
01701     // Get the upper-left 3x3 submatrix of a 3x4 transformation matrix
01702     // 
01703     inline const Matrix3 getUpper3x3( ) const;
01704 
01705     // Set translation component
01706     // 
01707     inline Transform3 & setTranslation( const Vector3 & translateVec );
01708 
01709     // Get the translation component of a 3x4 transformation matrix
01710     // 
01711     inline const Vector3 getTranslation( ) const;
01712 
01713     // Set column 0 of a 3x4 transformation matrix
01714     // 
01715     inline Transform3 & setCol0( const Vector3 & col0 );
01716 
01717     // Set column 1 of a 3x4 transformation matrix
01718     // 
01719     inline Transform3 & setCol1( const Vector3 & col1 );
01720 
01721     // Set column 2 of a 3x4 transformation matrix
01722     // 
01723     inline Transform3 & setCol2( const Vector3 & col2 );
01724 
01725     // Set column 3 of a 3x4 transformation matrix
01726     // 
01727     inline Transform3 & setCol3( const Vector3 & col3 );
01728 
01729     // Get column 0 of a 3x4 transformation matrix
01730     // 
01731     inline const Vector3 getCol0( ) const;
01732 
01733     // Get column 1 of a 3x4 transformation matrix
01734     // 
01735     inline const Vector3 getCol1( ) const;
01736 
01737     // Get column 2 of a 3x4 transformation matrix
01738     // 
01739     inline const Vector3 getCol2( ) const;
01740 
01741     // Get column 3 of a 3x4 transformation matrix
01742     // 
01743     inline const Vector3 getCol3( ) const;
01744 
01745     // Set the column of a 3x4 transformation matrix referred to by the specified index
01746     // 
01747     inline Transform3 & setCol( int col, const Vector3 & vec );
01748 
01749     // Set the row of a 3x4 transformation matrix referred to by the specified index
01750     // 
01751     inline Transform3 & setRow( int row, const Vector4 & vec );
01752 
01753     // Get the column of a 3x4 transformation matrix referred to by the specified index
01754     // 
01755     inline const Vector3 getCol( int col ) const;
01756 
01757     // Get the row of a 3x4 transformation matrix referred to by the specified index
01758     // 
01759     inline const Vector4 getRow( int row ) const;
01760 
01761     // Subscripting operator to set or get a column
01762     // 
01763     inline Vector3 & operator []( int col );
01764 
01765     // Subscripting operator to get a column
01766     // 
01767     inline const Vector3 operator []( int col ) const;
01768 
01769     // Set the element of a 3x4 transformation matrix referred to by column and row indices
01770     // 
01771     inline Transform3 & setElem( int col, int row, float val );
01772 
01773     // Get the element of a 3x4 transformation matrix referred to by column and row indices
01774     // 
01775     inline float getElem( int col, int row ) const;
01776 
01777     // Multiply a 3x4 transformation matrix by a 3-D vector
01778     // 
01779     inline const Vector3 operator *( const Vector3 & vec ) const;
01780 
01781     // Multiply a 3x4 transformation matrix by a 3-D point
01782     // 
01783     inline const Point3 operator *( const Point3 & pnt ) const;
01784 
01785     // Multiply two 3x4 transformation matrices
01786     // 
01787     inline const Transform3 operator *( const Transform3 & tfrm ) const;
01788 
01789     // Perform compound assignment and multiplication by a 3x4 transformation matrix
01790     // 
01791     inline Transform3 & operator *=( const Transform3 & tfrm );
01792 
01793     // Construct an identity 3x4 transformation matrix
01794     // 
01795     static inline const Transform3 identity( );
01796 
01797     // Construct a 3x4 transformation matrix to rotate around the x axis
01798     // 
01799     static inline const Transform3 rotationX( float radians );
01800 
01801     // Construct a 3x4 transformation matrix to rotate around the y axis
01802     // 
01803     static inline const Transform3 rotationY( float radians );
01804 
01805     // Construct a 3x4 transformation matrix to rotate around the z axis
01806     // 
01807     static inline const Transform3 rotationZ( float radians );
01808 
01809     // Construct a 3x4 transformation matrix to rotate around the x, y, and z axes
01810     // 
01811     static inline const Transform3 rotationZYX( const Vector3 & radiansXYZ );
01812 
01813     // Construct a 3x4 transformation matrix to rotate around a unit-length 3-D vector
01814     // 
01815     static inline const Transform3 rotation( float radians, const Vector3 & unitVec );
01816 
01817     // Construct a rotation matrix from a unit-length quaternion
01818     // 
01819     static inline const Transform3 rotation( const Quat & unitQuat );
01820 
01821     // Construct a 3x4 transformation matrix to perform scaling
01822     // 
01823     static inline const Transform3 scale( const Vector3 & scaleVec );
01824 
01825     // Construct a 3x4 transformation matrix to perform translation
01826     // 
01827     static inline const Transform3 translation( const Vector3 & translateVec );
01828 
01829 };
01830 // Append (post-multiply) a scale transformation to a 3x4 transformation matrix
01831 // NOTE: 
01832 // Faster than creating and multiplying a scale transformation matrix.
01833 // 
01834 inline const Transform3 appendScale( const Transform3 & tfrm, const Vector3 & scaleVec );
01835 
01836 // Prepend (pre-multiply) a scale transformation to a 3x4 transformation matrix
01837 // NOTE: 
01838 // Faster than creating and multiplying a scale transformation matrix.
01839 // 
01840 inline const Transform3 prependScale( const Vector3 & scaleVec, const Transform3 & tfrm );
01841 
01842 // Multiply two 3x4 transformation matrices per element
01843 // 
01844 inline const Transform3 mulPerElem( const Transform3 & tfrm0, const Transform3 & tfrm1 );
01845 
01846 // Compute the absolute value of a 3x4 transformation matrix per element
01847 // 
01848 inline const Transform3 absPerElem( const Transform3 & tfrm );
01849 
01850 // Inverse of a 3x4 transformation matrix
01851 // NOTE: 
01852 // Result is unpredictable when the determinant of the left 3x3 submatrix is equal to or near 0.
01853 // 
01854 inline const Transform3 inverse( const Transform3 & tfrm );
01855 
01856 // Compute the inverse of a 3x4 transformation matrix, expected to have an orthogonal upper-left 3x3 submatrix
01857 // NOTE: 
01858 // This can be used to achieve better performance than a general inverse when the specified 3x4 transformation matrix meets the given restrictions.
01859 // 
01860 inline const Transform3 orthoInverse( const Transform3 & tfrm );
01861 
01862 // Conditionally select between two 3x4 transformation matrices
01863 // 
01864 inline const Transform3 select( const Transform3 & tfrm0, const Transform3 & tfrm1, bool select1 );
01865 
01866 #ifdef _VECTORMATH_DEBUG
01867 
01868 // Print a 3x4 transformation matrix
01869 // NOTE: 
01870 // Function is only defined when _VECTORMATH_DEBUG is defined.
01871 // 
01872 inline void print( const Transform3 & tfrm );
01873 
01874 // Print a 3x4 transformation matrix and an associated string identifier
01875 // NOTE: 
01876 // Function is only defined when _VECTORMATH_DEBUG is defined.
01877 // 
01878 inline void print( const Transform3 & tfrm, const char * name );
01879 
01880 #endif
01881 
01882 } // namespace Aos
01883 } // namespace Vectormath
01884 
01885 #include "vec_aos.h"
01886 #include "quat_aos.h"
01887 #include "mat_aos.h"
01888 
01889 #endif
01890