]> git.mxchange.org Git - simgear.git/blob - simgear/scene/sky/clouds3d/mat33.hpp
Clouds3D crashes because there is no Light
[simgear.git] / simgear / scene / sky / clouds3d / mat33.hpp
1 //------------------------------------------------------------------------------
2 // File : mat33.hpp
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 
12 // restrictions. 
13 //
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.
17
18 //============================================================================
19 // mat33.hpp : 3x3 matrix template.
20 //============================================================================
21
22 #ifndef _MAT33_
23 #define _MAT33_
24
25 #include "vec3f.hpp"
26 #include "mat44.hpp"
27
28 static const float Mat33TORADS = 0.0174532f;
29 static const float Mat33VIEWPORT_TOL = 0.001f;
30
31 //----------------------------------------------------------------------------
32 // M[9] = [ 0  3  6 ]   
33 //        [ 1  4  7 ]  
34 //        [ 2  5  8 ]  
35 //
36 //                         
37 //
38 // [ x' y' z' ] = [ 0  3  6 ]   [ x ]
39 //                [ 1  4  7 ] * [ y ] 
40 //                [ 2  5  8 ]   [ z ]
41 //----------------------------------------------------------------------------
42 template<class Type>
43 class Mat33
44
45 public:
46   Type M[9];  // 0,1,2 = 1st col; 3,4,5 = 2nd col; etc.
47   
48   Mat33();
49   Mat33(const Type *N);
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); 
65
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 (/=)
72
73   bool Inverse(Mat33<Type> &inv, Type tolerance) const;// MATRIX INVERSE
74   
75   operator const Type*() const;                     // CAST TO A Type ARRAY
76   operator Type*();                                 // CAST TO A Type ARRAY
77
78   void RowMajor(Type m[9]);                // return array in row-major order
79
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);
86   
87   void Identity();
88   void Zero();
89   void Transpose();
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
98   Type Trace() const;
99   void Print() const;
100   void CopyInto(Type *Mat) const;
101   static void SWAP(Type& a, Type& b) {Type t; t=a;a=b;b=t;}
102 };
103
104 #include "mat33impl.hpp"
105
106 typedef Mat33<float> Mat33f;
107 typedef Mat33<double> Mat33d;
108
109 #endif
110
111
112
113