00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef GEOM_MAT4_HH
00020 #define GEOM_MAT4_HH
00021
00022 #include <cassert>
00023 #include <cstddef>
00024 #include <ostream>
00025 #include <vector>
00026
00027 #include <boost/operators.hpp>
00028
00029 #include <ost/geom/module_config.hh>
00030
00031 namespace geom {
00032
00033
00034 class Mat2;
00035 class Mat3;
00036 class Vec3;
00037
00038 class DLLEXPORT_OST_GEOM Mat4:
00039 private boost::equality_comparable<Mat4>,
00040 private boost::additive<Mat4>,
00041 private boost::multiplicative<Mat4, Real>
00042 {
00043 public:
00044 static Mat4 Identity();
00045
00047 Mat4();
00048
00050
00061 Mat4(Real i00, Real i01, Real i02, Real i03, Real i10, Real i11, Real i12, Real i13,
00062 Real i20, Real i21, Real i22, Real i23, Real i30, Real i31, Real i32, Real i33);
00064 Mat4(const Mat4& m);
00065
00067 explicit Mat4(const Mat2& m);
00068
00070 explicit Mat4(const Mat3& m);
00071
00073 explicit Mat4(const float[16]);
00074
00075 explicit Mat4(const double[16]);
00077 Mat4& operator=(const Mat4& m);
00078
00080 bool operator==(const Mat4& rhs) const;
00081
00082 const Real& At(std::size_t r, std::size_t c) const
00083 {
00084 if (r>3 || c>3) {
00085 throw std::out_of_range("indices must be smaller than 4");
00086 }
00087 return data_[r][c];
00088 }
00089
00090 Real& At(std::size_t r, std::size_t c)
00091 {
00092 if (r>3 || c>3) {
00093 throw std::out_of_range("indices must be smaller than 4");
00094 }
00095 return data_[r][c];
00096 }
00097
00098 Real& operator()(std::size_t r, std::size_t c)
00099 {
00100 assert(r<4 && c < 4);
00101 return data_[r][c];
00102 }
00103
00104 const Real& operator()(std::size_t r, std::size_t c) const
00105 {
00106 assert(r<4 && c < 4);
00107 return data_[r][c];
00108 }
00109
00111 Mat4& operator+=(const Mat4& rhs);
00113 Mat4& operator-=(const Mat4& rhs);
00114
00115 Mat4& operator*=(const Real d);
00116 Mat4& operator/=(const Real d);
00117
00118 Mat4& operator*=(const Mat4& m);
00119
00120 Mat3 ExtractRotation() const;
00121 void PasteRotation(const Mat3& m);
00122 Vec3 ExtractTranslation() const;
00123 void PasteTranslation(const Vec3& v);
00124
00125 Real* Data() {return &data_[0][0];}
00126 const Real* Data() const {return &data_[0][0];}
00127
00128 private:
00129 Real data_[4][4];
00130
00131 void set(float i00, float i01, float i02, float i03, float i10, float i11, float i12,
00132 float i13, float i20, float i21, float i22, float i23, float i30, float i31, float i32,
00133 float i33);
00134 void set(double i00, double i01, double i02, double i03, double i10, double i11, double
00135 i12, double i13, double i20, double i21, double i22, double i23, double i30, double i31,
00136 double i32, double i33);
00137
00138 };
00139
00140 typedef std::vector<Mat4> Mat4List;
00141
00142 DLLEXPORT_OST_GEOM std::ostream& operator<<(std::ostream& os, const Mat4& m);
00143
00144 }
00145
00146
00147 #endif