00001
00032 #ifndef LL_M3MATH_H
00033 #define LL_M3MATH_H
00034
00035 #include "llerror.h"
00036 #include "stdtypes.h"
00037
00038 class LLVector4;
00039 class LLVector3;
00040 class LLVector3d;
00041 class LLQuaternion;
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 static const U32 NUM_VALUES_IN_MAT3 = 3;
00059 class LLMatrix3
00060 {
00061 public:
00062 F32 mMatrix[NUM_VALUES_IN_MAT3][NUM_VALUES_IN_MAT3];
00063
00064 LLMatrix3(void);
00065 explicit LLMatrix3(const F32 *mat);
00066 explicit LLMatrix3(const LLQuaternion &q);
00067
00068 LLMatrix3(const F32 angle, const F32 x, const F32 y, const F32 z);
00069 LLMatrix3(const F32 angle, const LLVector3 &vec);
00070 LLMatrix3(const F32 angle, const LLVector3d &vec);
00071 LLMatrix3(const F32 angle, const LLVector4 &vec);
00072 LLMatrix3(const F32 roll, const F32 pitch, const F32 yaw);
00073
00075
00076
00077
00078
00079
00080 const LLMatrix3& setIdentity();
00081 const LLMatrix3& clear();
00082 const LLMatrix3& setZero();
00083
00085
00086
00087
00088
00089
00090 const LLMatrix3& setRot(const F32 angle, const F32 x, const F32 y, const F32 z);
00091 const LLMatrix3& setRot(const F32 angle, const LLVector3 &vec);
00092 const LLMatrix3& setRot(const F32 roll, const F32 pitch, const F32 yaw);
00093 const LLMatrix3& setRot(const LLQuaternion &q);
00094
00095 const LLMatrix3& setRows(const LLVector3 &x_axis, const LLVector3 &y_axis, const LLVector3 &z_axis);
00096 const LLMatrix3& setRow( U32 rowIndex, const LLVector3& row );
00097 const LLMatrix3& setCol( U32 colIndex, const LLVector3& col );
00098
00099
00101
00102
00103
00104 LLQuaternion quaternion() const;
00105 void getEulerAngles(F32 *roll, F32 *pitch, F32 *yaw) const;
00106
00107
00108 LLVector3 getFwdRow() const;
00109 LLVector3 getLeftRow() const;
00110 LLVector3 getUpRow() const;
00111 F32 determinant() const;
00112
00113
00115
00116
00117
00118 const LLMatrix3& transpose();
00119 const LLMatrix3& orthogonalize();
00120 void invert();
00121 const LLMatrix3& adjointTranspose();
00122
00123
00124
00125
00126
00127
00128
00129 const LLMatrix3& rotate(const F32 angle, const F32 x, const F32 y, const F32 z);
00130 const LLMatrix3& rotate(const F32 angle, const LLVector3 &vec);
00131 const LLMatrix3& rotate(const F32 roll, const F32 pitch, const F32 yaw);
00132 const LLMatrix3& rotate(const LLQuaternion &q);
00133
00134 void add(const LLMatrix3& other_matrix);
00135
00136
00137
00138
00139 friend LLVector3 operator*(const LLVector3 &a, const LLMatrix3 &b);
00140 friend LLVector3d operator*(const LLVector3d &a, const LLMatrix3 &b);
00141 friend LLMatrix3 operator*(const LLMatrix3 &a, const LLMatrix3 &b);
00142
00143 friend bool operator==(const LLMatrix3 &a, const LLMatrix3 &b);
00144 friend bool operator!=(const LLMatrix3 &a, const LLMatrix3 &b);
00145
00146 friend const LLMatrix3& operator*=(LLMatrix3 &a, const LLMatrix3 &b);
00147 friend const LLMatrix3& operator*=(LLMatrix3 &a, F32 scalar );
00148
00149 friend std::ostream& operator<<(std::ostream& s, const LLMatrix3 &a);
00150 };
00151
00152 inline LLMatrix3::LLMatrix3(void)
00153 {
00154 mMatrix[0][0] = 1.f;
00155 mMatrix[0][1] = 0.f;
00156 mMatrix[0][2] = 0.f;
00157
00158 mMatrix[1][0] = 0.f;
00159 mMatrix[1][1] = 1.f;
00160 mMatrix[1][2] = 0.f;
00161
00162 mMatrix[2][0] = 0.f;
00163 mMatrix[2][1] = 0.f;
00164 mMatrix[2][2] = 1.f;
00165 }
00166
00167 inline LLMatrix3::LLMatrix3(const F32 *mat)
00168 {
00169 mMatrix[0][0] = mat[0];
00170 mMatrix[0][1] = mat[1];
00171 mMatrix[0][2] = mat[2];
00172
00173 mMatrix[1][0] = mat[3];
00174 mMatrix[1][1] = mat[4];
00175 mMatrix[1][2] = mat[5];
00176
00177 mMatrix[2][0] = mat[6];
00178 mMatrix[2][1] = mat[7];
00179 mMatrix[2][2] = mat[8];
00180 }
00181
00182
00183 #endif
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222