OpenStructure
mat4.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // This file is part of the OpenStructure project <www.openstructure.org>
3 //
4 // Copyright (C) 2008-2011 by the OpenStructure authors
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License as published by the Free
8 // Software Foundation; either version 3.0 of the License, or (at your option)
9 // any later version.
10 // This library is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 //------------------------------------------------------------------------------
19 #ifndef GEOM_MAT4_HH
20 #define GEOM_MAT4_HH
21 
22 #include <cstddef> // for size_t
23 #include <ostream>
24 
25 #include <boost/operators.hpp>
26 
28 
29 namespace geom {
30 
31 // fw decl
32 class Mat2;
33 class Mat3;
34 class Vec3;
35 
37  private boost::equality_comparable<Mat4>,
38  private boost::additive<Mat4>,
39  private boost::multiplicative<Mat4, Real>
40 {
41 public:
42  static Mat4 Identity();
43 
45  Mat4();
46 
48 
59  Mat4(Real i00, Real i01, Real i02, Real i03, Real i10, Real i11, Real i12, Real i13,
60  Real i20, Real i21, Real i22, Real i23, Real i30, Real i31, Real i32, Real i33);
62  Mat4(const Mat4& m);
63 
65  explicit Mat4(const Mat2& m);
66 
68  explicit Mat4(const Mat3& m);
69 
71  explicit Mat4(const float[16]);
72 
73  explicit Mat4(const double[16]);
75  Mat4& operator=(const Mat4& m);
76 
78  bool operator==(const Mat4& rhs) const;
79 
81  Real& operator()(std::size_t r, std::size_t c);
83  const Real& operator()(std::size_t r, std::size_t c) const;
84 
86  Mat4& operator+=(const Mat4& rhs);
88  Mat4& operator-=(const Mat4& rhs);
89 
90  Mat4& operator*=(const Real d);
91  Mat4& operator/=(const Real d);
92 
93  Mat4& operator*=(const Mat4& m);
94 
95  Mat3 ExtractRotation() const;
96  void PasteRotation(const Mat3& m);
97  Vec3 ExtractTranslation() const;
98  void PasteTranslation(const Vec3& v);
99 
100  Real* Data() {return &data_[0][0];}
101  const Real* Data() const {return &data_[0][0];}
102 
103 private:
104  Real data_[4][4];
105 
106  void set(float i00, float i01, float i02, float i03, float i10, float i11, float i12,
107 float i13, float i20, float i21, float i22, float i23, float i30, float i31, float i32,
108 float i33);
109  void set(double i00, double i01, double i02, double i03, double i10, double i11, double
110 i12, double i13, double i20, double i21, double i22, double i23, double i30, double i31,
111 double i32, double i33);
112 
113 };
114 
115 DLLEXPORT_OST_GEOM std::ostream& operator<<(std::ostream& os, const Mat4& m);
116 
117 } // ns geom
118 
119 
120 #endif