00001
00002 #ifndef __MATRIX4_H__
00003 #define __MATRIX4_H__
00004
00005 #include "Vector4.h"
00006 #include "Matrix3.h"
00007
00008 class Matrix4
00009 {
00010 public:
00011
00012 Matrix4();
00013
00014
00015 Matrix4(float e11, float e12, float e13, float e14,
00016 float e21, float e22, float e23, float e24,
00017 float e31, float e32, float e33, float e34,
00018 float e41, float e42, float e43, float e44);
00019 Matrix4(const Matrix4& other);
00020
00021
00022 const float* operator[](int row) const;
00023 float* operator[](int row);
00024 float operator()(int row, int col) const;
00025 float& operator()(int row, int col);
00026
00027
00028 const Matrix4& operator=(const Matrix4& other);
00029
00031 bool operator==(const Matrix4& other) const;
00032 bool operator!=(const Matrix4& other) const;
00033
00034
00035 Matrix4 operator+(const Matrix4& other) const;
00036 const Matrix4& operator+=(const Matrix4& other);
00037
00038
00039 Matrix4 operator-(const Matrix4& other) const;
00040 const Matrix4& operator-=(const Matrix4& other);
00041
00042
00043 Matrix4 operator*(float scalar) const;
00044 const Matrix4& operator*=(float scalar);
00045
00046
00047 Matrix4 operator*(const Matrix4& other) const;
00048 const Matrix4& operator*=(const Matrix4& other);
00049
00050
00051 Vector3 operator*(const Vector3& vector3d) const;
00052 Vector4 operator*(const Vector4& vector4d) const;
00053
00054
00055 Matrix4 operator/(float scalar) const;
00056 const Matrix4& operator/=(float scalar);
00057
00058
00059 const Matrix4 Transposed(void) const;
00060 const Matrix4 Inverse(void) const;
00061 void Invert(void);
00062 float Determinant(void) const;
00063 bool IsIdentity(void) const;
00064
00065 void SetTranslation(float x, float y, float z);
00066 void SetTranslation(const Vector3& trans) { SetTranslation(trans.x, trans.y, trans.z); }
00067 void Translate(const Vector3& trans);
00068 Vector3 GetTranslation(void) const;
00069
00070 void Scale(float x, float y, float z);
00071 void SetScale(float x, float y, float z);
00072 Vector3 GetScale(void) const;
00073 void OrthoNormalize(void);
00074
00075 Matrix3 GetRotation(void) const;
00076 void SetRotation(const Matrix3& m);
00077
00078 Vector3 GetRight(void) const;
00079 Vector3 GetUp(void) const;
00080 Vector3 GetDir(void) const;
00081
00082 void SetRight(const Vector3& right);
00083 void SetUp(const Vector3& up);
00084 void SetDir(const Vector3& dir);
00085
00086
00087 void BuildTranslation(const Vector3& translation);
00088 void BuildTranslation(float x, float y, float z);
00089 void BuildScale(float x, float y, float z);
00090 void BuildRotationX(float angle);
00091 void BuildRotationY(float angle);
00092 void BuildRotationZ(float angle);
00093 void BuildRotation(float yaw, float pitch, float roll);
00094 void BuildPerspective(float fieldOfView, float aspectRatio,
00095 float nearPlaneZ, float farPlaneZ,
00096 bool leftHanded = true);
00097
00098 void BuildLookDir(const Vector3& position, const Vector3& direction, const Vector3& up);
00099 void BuildLookAt(const Vector3& position, const Vector3& at, const Vector3& up);
00100
00101 void BuildPlaneMirrorMatrix(const Vector4& planeEquation);
00102
00103 void BuildOrthogonal(float width, float height, float zNear, float zFar);
00104
00105
00106 static Matrix4 Matrix4Translation(const Vector3& translation);
00107 static Matrix4 Matrix4Translation(float x, float y, float z);
00108
00109 static Matrix4 Matrix4Scale(float x, float y, float z);
00110 static Matrix4 Matrix4Scale(const Vector3& scale);
00111
00112 static Matrix4 Matrix4Rotation(float yaw, float pitch, float roll);
00113 static Matrix4 Matrix4RotationX(float angle);
00114 static Matrix4 Matrix4RotationY(float angle);
00115 static Matrix4 Matrix4RotationZ(float angle);
00116
00117 static Matrix4 Matrix4Perspective(float fieldOfView, float aspectRatio,
00118 float nearPlaneZ, float farPlaneZ,
00119 bool leftHanded = true);
00120
00121 static Matrix4 Matrix4LookDir(const Vector3& position, const Vector3& direction, const Vector3& up);
00122 static Matrix4 Matrix4LookAt(const Vector3& position, const Vector3& at, const Vector3& up);
00123
00124 static Matrix4 Matrix4PlaneMirrorMatrix(const Vector4& planeEquation);
00125
00126 static Matrix4 Matrix4Orthogonal(float width, float height, float zNear, float zFar);
00127
00128 public:
00129 static const Matrix4 ZERO;
00130 static const Matrix4 IDENTITY;
00131
00132 union
00133 {
00134 struct
00135 {
00136
00137 float entry[16];
00138 };
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161 struct
00162 {
00163
00164 float m11;
00165 float m21;
00166 float m31;
00167 float m41;
00168 float m12;
00169 float m22;
00170 float m32;
00171 float m42;
00172 float m13;
00173 float m23;
00174 float m33;
00175 float m43;
00176 float m14;
00177 float m24;
00178 float m34;
00179 float m44;
00180 };
00181
00182 };
00183 };
00184
00185
00186 #endif //__MATRIX4_H__