00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef VRS_MATRIX_H
00019 #define VRS_MATRIX_H
00020
00021 #include <vrs/errorhandler.h>
00022 #include <vrs/vector.h>
00023 #include <iostream>
00024
00025 namespace VRS {
00026
00028 template<typename T>
00029 class Matrix4x4Base {
00030 public:
00031 enum MatrixType { MT_Identity, MT_Scale, MT_Translate, MT_Unknown, MT_Check, MT_Invalid };
00032 VRS_SERIALIZABLE_CLASS_ENUM(MatrixType);
00033
00034 Matrix4x4Base();
00035 Matrix4x4Base(const Matrix4x4Base& m1, const Matrix4x4Base& m2);
00036 Matrix4x4Base(
00037 T m00, T m01, T m02, T m03,
00038 T m10, T m11, T m12, T m13,
00039 T m20, T m21, T m22, T m23,
00040 T m30, T m31, T m32, T m33,
00041 MatrixType hint = Matrix4x4Base::MT_Unknown
00042 );
00044
00045 bool operator==(const Matrix4x4Base& m) const;
00046 bool operator!=(const Matrix4x4Base& m) const;
00047
00048 T element(unsigned int i, unsigned int j) const;
00049 T& element(unsigned int i, unsigned int j);
00050 void setElement(unsigned int i, unsigned int j, T value);
00054 Matrix4x4Base& operator*=(T scalar);
00055 Matrix4x4Base& operator*=(const Matrix4x4Base& m);
00056
00057 void transpose();
00059
00060 bool inverse(Matrix4x4Base& result) const;
00065
00066
00067
00068 Matrix4x4Base inverse() const;
00070
00071 void toUpperLeft3x3();
00076
00077 T det() const;
00078
00080 T subDet3x3(unsigned int omitColumn, unsigned int omitRow) const;
00081
00082 const T* pointer() const;
00087 void setHint(MatrixType matrixtype = Matrix4x4Base::MT_Check);
00088 MatrixType getHint() const;
00089
00090 static Matrix4x4Base scaling(const Vector3Base<T>& s);
00091 static Matrix4x4Base translation(const Vector3Base<T>& t);
00092 static Matrix4x4Base rotation(const Vector3Base<T>& axis,
00093 const Vector3Base<T>& center, T angle);
00094
00095 static const Matrix4x4Base& identity;
00096
00097
00098 VRS_SERIALIZABLE_NO_SO_CLASS(Matrix4x4Base);
00099
00100 private:
00101 explicit Matrix4x4Base(MatrixType hint);
00102
00103 T rep_[4][4];
00104 MatrixType hint_;
00105 };
00106
00107 template<typename T>
00108 std::ostream& operator<<(std::ostream&, const Matrix4x4Base<T>& mat);
00109
00110 template<typename T>
00111 std::istream& operator>>(std::istream&, Matrix4x4Base<T>& mat);
00112
00113 typedef Matrix4x4Base<float> Matrix4x4f;
00114 typedef Matrix4x4Base<double> Matrix4x4d;
00115
00116 typedef Matrix4x4d Matrix;
00117
00118 }
00119
00120 #include <vrs/matrix.tli>
00121
00122 #endif // VRS_MATRIX_H