source: GTP/trunk/App/Demos/Vis/CHC_revisited/src/Matrix4x4.h @ 2782

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