00001
00008 #ifndef _MAT_H_
00009 #define _MAT_H_
00010 #include "globals.h"
00012 #define PI 3.1415926535898f
00013
00016 class TVector
00017 {
00018 public:
00021 GLfloat x;
00023 GLfloat y;
00025 GLfloat z;
00027 GLfloat w;
00028
00030 TVector(GLfloat vx = 0.0,GLfloat vy = 0.0,GLfloat vz = 0.0, GLfloat vw = 0.0)
00031 {x=vx; y=vy; z=vz; w=vw; }
00032
00033
00034 TVector(const TVector &start, const TVector &end);
00035 void Create(const TVector &start, const TVector &end);
00036
00038 void Set(GLfloat vx,GLfloat vy,GLfloat vz, GLfloat vw = 0.0)
00039 {x=vx; y=vy; z=vz; w=vw; }
00041 void LoadIdentity()
00042 { x = 0.0; y = 0.0; z = 0.0; w = 0.0; }
00043
00044
00045 GLfloat Lenght();
00046
00047 void Normalize();
00049 bool IsEmpty()
00050 { return (x == 0.0 && y == 0.0 && z == 0.0 && w == 0.0); }
00051
00053 operator GLfloat* () const {return (GLfloat*) this;}
00055 friend TVector operator + (const TVector &v, const float con)
00056 { return TVector(v.x+con,v.y+con,v.z+con,v.w+con); }
00058 friend TVector operator * (const TVector &v, const float con)
00059 { return TVector(v.x*con,v.y*con,v.z*con,v.w*con); }
00061 friend TVector operator-(const TVector &v1, const TVector &v2)
00062 { return TVector(v1.x-v2.x, v1.y-v2.y, v1.z-v2.z, v1.w-v2.z); }
00064 friend TVector operator/(const TVector &v, const float con)
00065 { return TVector(v.x/con, v.y/con, v.z/con, v.w/con); }
00067 friend TVector operator-(const TVector &v)
00068 { return TVector(-v.x, -v.y, -v.z, -v.w); }
00069 };
00070
00071
00072
00075 class TMatrix
00076 {
00077 private:
00079 float values[16];
00080 public:
00081
00082 TMatrix();
00083 TMatrix( float v0, float v1, float v2, float v3,
00084 float v4, float v5, float v6, float v7,
00085 float v8, float v9, float v10, float v11,
00086 float v12, float v13, float v14, float v15);
00087 TMatrix(const TMatrix &ref);
00088
00089
00090 void GetRow(int position, float *ref) const;
00091
00092 TMatrix Inverse();
00093 TMatrix Transpose();
00094
00095 void LoadIdentity();
00096
00097
00098 TMatrix operator*(const TMatrix &ref) const;
00099
00100 friend ostream& operator<<(ostream &os, const TMatrix &m);
00101
00104 float* operator [](int index)
00105 { return &values[index]; }
00106
00108 operator float* () const {return (float*) this;}
00110 operator const float* () const {return (const float*) this;}
00111 };
00112
00114
00115
00116 TVector CrossProduct(const TVector &v1, const TVector &v2);
00117
00118
00119 float DotProduct(const TVector &v1, const TVector &v2);
00120
00121
00122 float VecAngle(TVector &v1, TVector &v2);
00123
00124 #endif