source: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/Matrix4x4.h @ 2934

Revision 2934, 5.8 KB checked in by mattausch, 16 years ago (diff)
Line 
1#ifndef __MATRIX4x4_H
2#define __MATRIX4x4_H
3
4#include <iostream>
5
6
7namespace CHCDemoEngine
8{
9
10class Vector3;
11class AxisAlignedBox3;
12
13
14class Matrix4x4
15{
16public:
17        /** Default constructor initialising nothig.
18        */
19        Matrix4x4();
20        /** here xXY - 'X' is row, and 'Y' is column - classical mathematical notation
21        */
22        Matrix4x4(float x11, float x12, float x13, float x14,
23                      float x21, float x22, float x23, float x24,
24                          float x31, float x32, float x33, float x34,
25                          float x41, float x42, float x43, float x44);
26        /** Constructor setting the columns of the 3x3 part of the matrix.
27        */
28        Matrix4x4(const Vector3 &a, const Vector3 &b, const Vector3 &c);
29
30
31        ////////////////
32        //-- Assignment operators
33
34        Matrix4x4& operator+= (const Matrix4x4 &A);     // add-to
35        Matrix4x4& operator-= (const Matrix4x4 &A);     // subtract-from
36        Matrix4x4& operator*= (const Matrix4x4 &A);     // multiply by matrix
37        Matrix4x4& operator*= (float A);                // scale by scalar
38
39
40        ////////////////
41        //-- Fundamental operations
42
43        /** Invert the matrix .. returns 0 = regular
44        */
45        int Invert();           
46        /** Transpose the matrix
47        */
48        void Transpose();       
49        /** Sets the columns of the 3x3 part of the matrix.
50        */
51        void SetColumns(const Vector3 &a, const Vector3 &b, const Vector3 &c);
52
53        float Det3x3() const;
54
55
56        ////////////
57        //-- members
58
59        float x[4][4]; // first index is column [x], the second is row [y]
60
61
62        ////////////////////
63
64        // Invert a given matrix
65        friend Matrix4x4 Invert(const Matrix4x4 &M);
66        // Transpose a given matrix
67        friend Matrix4x4 Transpose(const Matrix4x4 &M);
68
69
70        ///////////
71        //-- Create various types of matrix.
72
73        friend Matrix4x4 IdentityMatrix();
74        friend Matrix4x4 ZeroMatrix();
75        friend Matrix4x4 TranslationMatrix(const Vector3 &Location);
76        friend Matrix4x4 RotationXMatrix(float Angle);
77        friend Matrix4x4 RotationYMatrix(float Angle);
78        friend Matrix4x4 RotationZMatrix(float Angle);
79        friend Matrix4x4 RotationYPRMatrix(float Yaw, float Pitch, float Roll);
80        // about axis 'axis' by angle 'Angle'
81        friend Matrix4x4 RotationAxisMatrix(const Vector3 &axis, float Angle);
82        // create the rotation matrix that rotates 'vecFrom' to 'vecTo'
83        friend Matrix4x4 RotationVectorsMatrix(const Vector3 &vecFrom,
84                                                   const Vector3 &vecTo);
85
86        friend Matrix4x4 ScaleMatrix(float X, float Y, float Z);
87        friend Matrix4x4 GenRotation(const Vector3 &x, const Vector3 &y,
88                                        const Vector3 &z);
89        friend Matrix4x4 QuadricMatrix(float a, float b, float c, float d, float e,
90                                           float f, float g, float h, float j, float k);
91        // returns matrix for transforming normal
92        friend Matrix4x4 NormalTransformMatrix(const Matrix4x4 &M);
93
94        friend Matrix4x4 MirrorX();
95        friend Matrix4x4 MirrorY();
96        friend Matrix4x4 MirrorZ();
97        friend Matrix4x4 RotationOnly(const Matrix4x4 &x);
98
99        // Binary operators
100        friend Matrix4x4 operator+ (const Matrix4x4 &A, const Matrix4x4 &B);
101        friend Matrix4x4 operator- (const Matrix4x4 &A, const Matrix4x4 &B);
102        friend Matrix4x4 operator* (const Matrix4x4 &A, float B);
103        friend Matrix4x4 operator* (const Matrix4x4 &A, const Matrix4x4 &B);
104
105        // friends returning Vector3
106        friend Vector3 operator*(const Matrix4x4 &M, const Vector3 &v);
107        friend Vector3 RotateOnly(const Matrix4x4 &M, const Vector3 &v);
108        friend Vector3 TransformNormal(const Matrix4x4 &M, const Vector3 &v);
109        friend Vector3 GetTranslation(const Matrix4x4 &M);
110
111        friend Matrix4x4 GetFittingProjectionMatrix(const AxisAlignedBox3 &box);
112
113        //output is initialized with the same result as glFrustum
114        friend Matrix4x4 GetFrustum(float left, float right, float bottom, float top, float near, float far);
115
116        // look from position into given direction with given up vector
117        friend Matrix4x4 LookAt(const Vector3 &pos, const Vector3 &dir, const Vector3& up);
118
119        // Overloaded output operator.
120        friend std::ostream& operator<< (std::ostream &s, const Matrix4x4 &M);
121};
122
123
124/////////
125//-- forward declaration
126
127
128Matrix4x4 IdentityMatrix();
129Matrix4x4 Invert(const Matrix4x4 &M);   
130Matrix4x4 Transpose(const Matrix4x4 &M);       
131Matrix4x4 IdentityMatrix();
132Matrix4x4 ZeroMatrix();
133Matrix4x4 TranslationMatrix(const Vector3 &Location);
134Matrix4x4 RotationXMatrix(float Angle);
135Matrix4x4 RotationYMatrix(float Angle);
136Matrix4x4 RotationZMatrix(float Angle);
137Matrix4x4 RotationYPRMatrix(float Yaw, float Pitch, float Roll);
138Matrix4x4 RotationAxisMatrix(const Vector3 &axis, float Angle);
139Matrix4x4 RotationVectorsMatrix(const Vector3 &vecFrom,
140                                                                const Vector3 &vecTo);
141Matrix4x4 ScaleMatrix(float X, float Y, float Z);
142Matrix4x4 GenRotation(const Vector3 &x, const Vector3 &y,
143                                          const Vector3 &z);
144Matrix4x4 QuadricMatrix(float a, float b, float c, float d, float e,
145                                                float f, float g, float h, float j, float k);
146Matrix4x4 NormalTransformMatrix(const Matrix4x4 &M);
147Matrix4x4 MirrorX();
148Matrix4x4 MirrorY();
149Matrix4x4 MirrorZ();
150Matrix4x4 RotationOnly(const Matrix4x4 &x);
151Matrix4x4 operator+ (const Matrix4x4 &A, const Matrix4x4 &B);
152Matrix4x4 operator- (const Matrix4x4 &A, const Matrix4x4 &B);
153Matrix4x4 operator* (const Matrix4x4 &A, float B);
154Matrix4x4 operator* (const Matrix4x4 &A, const Matrix4x4 &B);
155Vector3 operator*(const Matrix4x4 &M, const Vector3 &v);
156Vector3 RotateOnly(const Matrix4x4 &M, const Vector3 &v);
157Vector3 TransformNormal(const Matrix4x4 &M, const Vector3 &v);
158Vector3 GetTranslation(const Matrix4x4 &M);
159Matrix4x4 GetFittingProjectionMatrix(const AxisAlignedBox3 &box);
160Matrix4x4 GetFrustum(float left, float right, float bottom, float top, float near, float far);
161Matrix4x4 LookAt(const Vector3 &pos, const Vector3 &dir, const Vector3& up);
162Matrix4x4 MyLookAt(const Vector3 &pos, const Vector3 &dir, const Vector3& up);
163Matrix4x4 MyLookAt2(const Vector3 &pos, const Vector3 &dir, const Vector3& up);
164
165
166}
167
168
169#endif
Note: See TracBrowser for help on using the repository browser.