]> git.mxchange.org Git - simgear.git/blob - simgear/scene/sky/clouds3d/mat44.hpp
Clouds3D crashes because there is no Light
[simgear.git] / simgear / scene / sky / clouds3d / mat44.hpp
1 //------------------------------------------------------------------------------
2 // File : mat44.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 // mat44.hpp : 4x4 OpenGL-style matrix template.
20 //============================================================================
21
22 #ifndef _MAT44_
23 #define _MAT44_
24
25 #include "vec3f.hpp"
26 #include "vec4f.hpp"
27
28 static const float Mat44TORADS = 0.0174532f;
29 static const float Mat44VIEWPORT_TOL = 0.001f;
30
31 //----------------------------------------------------------------------------
32 // M[16] = [ 0  4  8 12 ]   |  16 floats were used instead of the normal [4][4]
33 //         [ 1  5  9 13 ]   |  to be compliant with OpenGL. OpenGL uses
34 //         [ 2  6 10 14 ]   |  premultiplication with column vectors. These
35 //         [ 3  7 11 15 ]   |  matrices can be fed directly into the OpenGL
36 //                          |  matrix stack with glLoadMatrix or glMultMatrix.
37 //
38 // [ x' y' z' w' ] = [ 0  4  8 12 ]   [ x ]
39 //                   [ 1  5  9 13 ] * [ y ] 
40 //                   [ 2  6 10 14 ]   [ z ]
41 //                   [ 3  7 11 15 ]   [ w ]
42 // 
43 // Loading a [4][4] format matrix directly into the matrix stack (assuming
44 // premult/col vecs) results in a transpose matrix. M[0]=M[0][0], but
45 // M[1]!=M[1][0] since M[0][1] would cast to M[1].
46 //
47 // However, if we assumed postmult/row vectors we could use [4][4] format,
48 // but all transformations in this module would be transposed.
49 //----------------------------------------------------------------------------
50 template<class Type>
51 class Mat44
52
53   public:
54     Type M[16];  // 0,1,2,3 = 1st col; 4,5,6,7 = 2nd col; etc.
55
56     Mat44();
57     Mat44(const Type *N);
58     Mat44(Type M0, Type M4, Type M8, Type M12,
59           Type M1, Type M5, Type M9, Type M13,
60           Type M2, Type M6, Type M10, Type M14,
61           Type M3, Type M7, Type M11, Type M15);
62     Mat44<Type>& operator = (const Mat44& A);         // ASSIGNMENT (=)
63     Mat44<Type>& operator = (const Type* a);                // ASSIGNMENT (=) FROM AN ARRAY OF TypeS 
64     Mat44<Type> operator * (const Mat44& A) const;    // MULTIPLICATION (*)
65     Vec3<Type> operator * (const Vec3<Type>& V) const;      // MAT-VECTOR MULTIPLICATION (*) W/ PERSP DIV
66     Vec3<Type> multNormal(const Vec3<Type>& V) const;      // MAT-VECTOR MULTIPLICATION _WITHOUT_ PERSP DIV
67     Vec3<Type> multPoint(const Vec3<Type>& V) const;      // MAT-POINT MULTIPLICATION _WITHOUT_ PERSP DIV
68     Vec4<Type> operator * (const Vec4<Type>& V) const;      // MAT-VECTOR MULTIPLICATION (*)
69     Mat44<Type> operator * (Type a) const;                  // SCALAR POST-MULTIPLICATION
70     Mat44<Type>& operator *= (Type a);                    // ACCUMULATE MULTIPLY (*=)
71 ////////////// NOT IMPLEMENTED YET. ANY TAKERS?
72 //    friend Vec3<Type> operator * (const Vec3<Type>& V, const Mat44& M);   // MAT-VECTOR PRE-MULTIPLICATON (*) W/ PERP DIV
73 //    friend Vec4<Type> operator * (const Vec4<Type>& V, const Mat44& M);   // MAT-VECTOR PRE-MULTIPLICATON (*)
74 //    friend Mat44<Type> operator * (Type a, const Mat44& M) const;         // SCALAR PRE-MULTIPLICATION
75 //    Mat44<Type> operator / (Type a) const;                // SCALAR DIVISION
76 //    Mat44<Type> operator + (Mat44& M) const;        // ADDITION (+)
77 //    Mat44<Type>& operator += (Mat44& M);            // ACCUMULATE ADD (+=)
78 //    Mat44<Type>& operator /= (Type a);                    // ACCUMULATE DIVIDE (/=)
79 //    bool Invserse();                                      // MATRIX INVERSE
80 ////////////// NOT IMPLEMENTED YET. ANY TAKERS?
81
82     operator const Type*() const;                           // CAST TO A Type ARRAY
83     operator Type*();                                       // CAST TO A Type ARRAY
84     Type& operator()(int col, int row);                     // 2D ARRAY ACCESSOR
85     const Type& operator()(int col, int row) const;         // 2D ARRAY ACCESSOR
86     void Set(const Type* a);                                // SAME AS ASSIGNMENT (=) FROM AN ARRAY OF TypeS
87     void Set(Type M0, Type M4, Type M8, Type M12,
88              Type M1, Type M5, Type M9, Type M13,
89              Type M2, Type M6, Type M10, Type M14,
90              Type M3, Type M7, Type M11, Type M15);
91
92
93     void Identity();
94     void Transpose();
95     void Translate(Type Tx, Type Ty, Type Tz);
96     void Translate(const Vec3<Type>& T);
97     void invTranslate(Type Tx, Type Ty, Type Tz);
98     void invTranslate(const Vec3<Type>& T);
99     void Scale(Type Sx, Type Sy, Type Sz);
100     void Scale(const Vec3<Type>& S);
101     void invScale(Type Sx, Type Sy, Type Sz);
102     void invScale(const Vec3<Type>& S);
103     void Rotate(Type DegAng, const Vec3<Type>& Axis);
104     void invRotate(Type DegAng, const Vec3<Type>& Axis);
105     Type Trace(void) const;
106     void Frustum(Type l, Type r, Type b, Type t, Type n, Type f);
107     void invFrustum(Type l, Type r, Type b, Type t, Type n, Type f);
108     void Perspective(Type Yfov, Type Aspect, Type Ndist, Type Fdist);
109     void invPerspective(Type Yfov, Type Aspect, Type Ndist, Type Fdist);
110     void Viewport(int WW, int WH);
111     void invViewport(int WW, int WH);
112     void LookAt(const Vec3<Type>& Eye, 
113                 const Vec3<Type>& LookAtPt,
114                 const Vec3<Type>& ViewUp);
115     void invLookAt(const Vec3<Type>& Eye, 
116                    const Vec3<Type>& LookAtPt, 
117                    const Vec3<Type>& ViewUp);
118     void Viewport2(int WW, int WH);
119     void invViewport2(int WW, int WH);
120     void Print() const;
121     void CopyInto(Type *Mat) const;
122
123     static void SWAP(Type& a, Type& b) {Type t; t=a;a=b;b=t;}
124 };
125
126 #include "mat44impl.hpp"
127
128 typedef Mat44<float> Mat44f;
129 typedef Mat44<double> Mat44d;
130
131 #endif
132
133
134
135