Main Page | Namespace List | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

PS2Math.h

Go to the documentation of this file.
00001 
00007 #ifndef NABLA_MATRIX_H__
00008 #define NABLA_MATRIX_H__
00009 
00010 #include <iostream>
00011 #include <cstdlib>
00012 #include <cstring>
00013 
00018 namespace PS2Math {
00019 
00021     enum MainAxis {
00022     
00023         X_AXIS,
00024         Y_AXIS, 
00025         Z_AXIS
00026     };
00027 
00028     class Vector4;
00029 
00040     class Matrix44 {
00041 
00042     public:
00043 
00045         float           elem[4][4]; 
00046 
00048         Matrix44(bool Identity = false);    
00049 
00051         Matrix44(float Angle, MainAxis Axis);   
00052 
00054         void Reset() {memset(elem, 0, sizeof(elem));}
00055         
00057         Matrix44 &AddRotation(float Angle, MainAxis Axis);
00058 
00064 
00065         Matrix44 &SetRotationX(float Angle);
00067         Matrix44 &SetRotationY(float Angle);
00069         Matrix44 &SetRotationZ(float Angle);
00071         Matrix44 &AddRotationX(float Angle);
00073         Matrix44 &AddRotationY(float Angle);
00075         Matrix44 &AddRotationZ(float Angle);
00077 
00079         Matrix44 &ViewLH(const Vector4 &Eye, const Vector4 &At, const Vector4 &Up);
00081         Matrix44 &ViewRH(const Vector4 &Eye, const Vector4 &At, const Vector4 &Up);
00082         
00084         Matrix44 &PerspectiveLH(float Width, float Height, float zNear, float zFar);
00086         Matrix44 &PerspectiveRH(float Width, float Height, float zNear, float zFar);
00088         Matrix44 &MapToViewPort(float xMin, float xMax, 
00089                                         float yMin, float yMax,
00090                                         float zMin, float zMax);
00091 
00093         float * const operator[](int Index) {return elem[Index];}
00095         const float *operator[](int Index) const {return elem[Index];}
00096     };
00097 
00099     Matrix44 &Matrix44Multiply(const Matrix44 &M1, 
00100                                        const Matrix44 &M2, 
00101                                                 Matrix44 &Result); 
00103     Matrix44 &Matrix44MultiplyL(Matrix44 &M1_result, 
00104                                        const Matrix44 &M2); 
00106     Matrix44 &Matrix44MultiplyR(const Matrix44 &M1, 
00107                                        Matrix44 &M2_result); 
00108 
00110     const Matrix44 operator*(const Matrix44 &M1, 
00111                                      const Matrix44 &M2);
00112 
00114     Matrix44 &operator*=(Matrix44 &M1, 
00115                                const Matrix44 &M2);
00116 
00118     std::ostream &operator<<(std::ostream &outStream, const Matrix44 &Mat);
00119 
00125     class Vector4 {
00126     
00127     public:
00128 
00130         float x, y, z, w;
00131 
00133         Vector4() {}
00135         Vector4(float x, float y, float z, float w = 1);
00136 
00138         Vector4 &Omogenize();
00139 
00141         Vector4 &Normalize();
00142 
00144         Vector4 &OmogenizeWtoZ();
00145         
00147         float     ConvertToFixedPoint(int []);
00148 
00150         float &operator[](int Index);
00152         const float operator[](int Index) const;
00153     };
00154 
00156     const Vector4 operator*(const Matrix44 &M, const Vector4 &V);
00158     const Vector4 operator-(const Vector4 &V);
00160     const Vector4 operator*(const Vector4 &V1, const Vector4 &V2);
00162     const Vector4 operator-(const Vector4 &V1, const Vector4 &V2);
00164     const Vector4 operator+(const Vector4 &V1, const Vector4 &V2);
00165 
00169     float Dot(const Vector4 &V1, const Vector4 &V2);
00170     
00172     std::ostream &operator<<(std::ostream &outStream, const Vector4 &V);
00173 }
00174 
00175 #endif

Generated on Wed Jan 7 19:11:57 2004 for PS2 Tutorial by doxygen 1.3.4