1 //------------------------------------------------------------------------------
3 //------------------------------------------------------------------------------
4 // GLVU : Copyright 1997 - 2002
5 // The University of North Carolina at Chapel Hill
6 //------------------------------------------------------------------------------
7 // Permission to use, copy, modify, distribute and sell this software and its
8 // documentation for any purpose is hereby granted without fee, provided that
9 // the above copyright notice appear in all copies and that both that copyright
10 // notice and this permission notice appear in supporting documentation.
11 // Binaries may be compiled with this software without any royalties or
14 // The University of North Carolina at Chapel Hill makes no representations
15 // about the suitability of this software for any purpose. It is provided
16 // "as is" without express or implied warranty.
18 //============================================================================
19 // mat33.hpp : 3x3 matrix template.
20 //============================================================================
28 static const float Mat33TORADS = 0.0174532f;
29 static const float Mat33VIEWPORT_TOL = 0.001f;
31 //----------------------------------------------------------------------------
38 // [ x' y' z' ] = [ 0 3 6 ] [ x ]
41 //----------------------------------------------------------------------------
46 Type M[9]; // 0,1,2 = 1st col; 3,4,5 = 2nd col; etc.
50 Mat33(Type M0, Type M3, Type M6,
51 Type M1, Type M4, Type M7,
52 Type M2, Type M5, Type M8);
53 Mat33<Type>& operator = (const Mat33& A); // ASSIGNMENT (=)
54 // ASSIGNMENT (=) FROM AN ARRAY OF Type
55 Mat33<Type>& operator = (const Type* a);
56 Mat33<Type> operator * (const Mat33& A) const; // MULTIPLICATION (*)
57 // MAT-VECTOR MULTIPLICATION (*)
58 Vec3<Type> operator * (const Vec3<Type>& V) const;
59 // MAT-VECTOR PRE-MULTIPLICATON (*)
60 friend Vec3<Type> operator * (const Vec3<Type>& V, const Mat33<Type>& M);
61 // SCALAR POST-MULTIPLICATION
62 Mat33<Type> operator * (Type a) const;
63 // SCALAR PRE-MULTIPLICATION
64 friend Mat33<Type> operator * (Type a, const Mat44<Type>& M);
66 Mat33<Type> operator / (Type a) const; // SCALAR DIVISION
67 Mat33<Type> operator + (Mat33& M) const; // ADDITION (+)
68 Mat33<Type>& operator += (Mat33& M); // ACCUMULATE ADD (+=)
69 Mat33<Type>& operator -= (Mat33& M); // ACCUMULATE SUB (-=)
70 Mat33<Type>& operator *= (Type a); // ACCUMULATE MULTIPLY (*=)
71 Mat33<Type>& operator /= (Type a); // ACCUMULATE DIVIDE (/=)
73 bool Inverse(Mat33<Type> &inv, Type tolerance) const;// MATRIX INVERSE
75 operator const Type*() const; // CAST TO A Type ARRAY
76 operator Type*(); // CAST TO A Type ARRAY
78 void RowMajor(Type m[9]); // return array in row-major order
80 Type& operator()(int col, int row); // 2D ARRAY ACCESSOR
81 const Type& operator()(int col, int row) const; // 2D ARRAY ACCESSOR
82 void Set(const Type* a); // SAME AS ASSIGNMENT (=) FROM AN ARRAY OF TypeS
83 void Set(Type M0, Type M3, Type M6,
84 Type M1, Type M4, Type M7,
85 Type M2, Type M5, Type M8);
90 void Scale(Type Sx, Type Sy, Type Sz);
91 void Scale(const Vec3<Type>& S);
92 void invScale(Type Sx, Type Sy, Type Sz);
93 void invScale(const Vec3<Type>& S);
94 void Rotate(Type DegAng, const Vec3<Type>& Axis);
95 void invRotate(Type DegAng, const Vec3<Type>& Axis);
96 void Star(const Vec3<Type>& v); // SKEW-SYMM MATRIX EQUIV TO CROSS PROD WITH V
97 void OuterProduct(const Vec3<Type>& u, const Vec3<Type>& v); // SET TO u * v^t
100 void CopyInto(Type *Mat) const;
101 static void SWAP(Type& a, Type& b) {Type t; t=a;a=b;b=t;}
104 #include "mat33impl.hpp"
106 typedef Mat33<float> Mat33f;
107 typedef Mat33<double> Mat33d;