Main Page   Modules   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

mat33.hpp

00001 //============================================================================
00002 // mat33.hpp : 3x3 matrix template.
00003 //============================================================================
00004 
00005 #ifndef _MAT33_
00006 #define _MAT33_
00007 
00008 #include "vec3f.hpp"
00009 
00010 static const float Mat33TORADS = 0.0174532f;
00011 static const float Mat33VIEWPORT_TOL = 0.001f;
00012 
00013 //----------------------------------------------------------------------------
00014 // M[9] = [ 0  3  6 ]   
00015 //        [ 1  4  7 ]  
00016 //        [ 2  5  8 ]  
00017 //
00018 //                         
00019 //
00020 // [ x' y' z' ] = [ 0  3  6 ]   [ x ]
00021 //                [ 1  4  7 ] * [ y ] 
00022 //                [ 2  5  8 ]   [ z ]
00023 //----------------------------------------------------------------------------
00024 template<class Type>
00025 class Mat33
00026 { 
00027 public:
00028   Type M[9];  // 0,1,2 = 1st col; 3,4,5 = 2nd col; etc.
00029   
00030   Mat33();
00031   Mat33(const Type *N);
00032   Mat33(Type M0, Type M3, Type M6,
00033         Type M1, Type M4, Type M7,
00034         Type M2, Type M5, Type M8);
00035   Mat33<Type>& operator = (const Mat33& A);  // ASSIGNMENT (=)
00036   // ASSIGNMENT (=) FROM AN ARRAY OF Type 
00037   Mat33<Type>& operator = (const Type* a);
00038   Mat33<Type> operator * (const Mat33& A) const; // MULTIPLICATION (*)
00039   // MAT-VECTOR MULTIPLICATION (*)
00040   Vec3<Type> operator * (const Vec3<Type>& V) const; 
00041   // MAT-VECTOR PRE-MULTIPLICATON (*)
00042   friend Vec3<Type> operator * (const Vec3<Type>& V, const Mat33<Type>& M);   
00043   // SCALAR POST-MULTIPLICATION
00044   Mat33<Type> operator * (Type a) const;
00045   // SCALAR PRE-MULTIPLICATION
00046   friend Mat33<Type> operator * (Type a, const Mat44& M); 
00047 
00048   Mat33<Type> operator / (Type a) const;      // SCALAR DIVISION
00049   Mat33<Type> operator + (Mat33& M) const;    // ADDITION (+)
00050   Mat33<Type>& operator += (Mat33& M);        // ACCUMULATE ADD (+=)
00051   Mat33<Type>& operator -= (Mat33& M);        // ACCUMULATE SUB (-=)
00052   Mat33<Type>& operator *= (Type a);          // ACCUMULATE MULTIPLY (*=)
00053   Mat33<Type>& operator /= (Type a);          // ACCUMULATE DIVIDE (/=)
00054 
00055   bool Inverse(Mat33<Type> &inv, Type tolerance) const;// MATRIX INVERSE
00056   
00057   operator const Type*() const;                     // CAST TO A Type ARRAY
00058   operator Type*();                                 // CAST TO A Type ARRAY
00059 
00060   void RowMajor(Type m[9]);                // return array in row-major order
00061 
00062   Type& operator()(int col, int row);               // 2D ARRAY ACCESSOR
00063   const Type& operator()(int col, int row) const;   // 2D ARRAY ACCESSOR
00064   void Set(const Type* a);    // SAME AS ASSIGNMENT (=) FROM AN ARRAY OF TypeS
00065   void Set(Type M0, Type M3, Type M6,
00066            Type M1, Type M4, Type M7,
00067            Type M2, Type M5, Type M8);
00068   
00069   void Identity();
00070   void Zero();
00071   void Transpose();
00072   void Scale(Type Sx, Type Sy, Type Sz);
00073   void Scale(const Vec3<Type>& S);
00074   void invScale(Type Sx, Type Sy, Type Sz);
00075   void invScale(const Vec3<Type>& S);
00076   void Rotate(Type DegAng, const Vec3<Type>& Axis);
00077   void invRotate(Type DegAng, const Vec3<Type>& Axis);
00078   void Star(const Vec3<Type>& v);  // SKEW-SYMM MATRIX EQUIV TO CROSS PROD WITH V
00079   void OuterProduct(const Vec3<Type>& u, const Vec3<Type>& v);  // SET TO  u * v^t
00080   Type Trace() const;
00081   void Print() const;
00082   void CopyInto(Type *Mat) const;
00083   static void SWAP(Type& a, Type& b) {Type t; t=a;a=b;b=t;}
00084 };
00085 
00086 #include "mat33impl.hpp"
00087 
00088 typedef Mat33<float> Mat33f;
00089 typedef Mat33<double> Mat33d;
00090 
00091 #endif
00092 
00093 
00094 
00095 

Generated at Fri Oct 12 15:12:21 2001 for GLVU by doxygen1.2.10 written by Dimitri van Heesch, © 1997-2001