1 /**************************************************************************/ 2 /* Copyright 2009 Tim Day */ 3 /* */ 4 /* This file is part of Fracplanet */ 5 /* */ 6 /* Fracplanet is free software: you can redistribute it and/or modify */ 7 /* it under the terms of the GNU General Public License as published by */ 8 /* the Free Software Foundation, either version 3 of the License, or */ 9 /* (at your option) any later version. */ 10 /* */ 11 /* Fracplanet is distributed in the hope that it will be useful, */ 12 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */ 13 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */ 14 /* GNU General Public License for more details. */ 15 /* */ 16 /* You should have received a copy of the GNU General Public License */ 17 /* along with Fracplanet. If not, see <http://www.gnu.org/licenses/>. */ 18 /**************************************************************************/ 19 20 /*! \file 21 \brief Interface for class Matrix34. 22 */ 23 24 #ifndef _matrix34_h_ 25 #define _matrix34_h_ 26 27 #include "common.h" 28 #include "matrix33.h" 29 #include "xyz.h" 30 31 //! Class to hold 3x4 matrices 32 /*! Rotation below actually means any sort of origin preserving transform; 33 it's just easier to visualize rotations and most of the time that's what they are. 34 */ 35 class Matrix34 36 { 37 public: 38 39 //! 3x3 rotational component 40 Matrix33 rotate; 41 42 //! Translational component 43 XYZ translate; 44 //! Null constructor. 45 /*! NB The components are not cleared to zero. 46 */ Matrix34()47 Matrix34() 48 {} 49 50 //! Construct from a rotation and translation Matrix34(const Matrix33 & r,const XYZ & t)51 Matrix34(const Matrix33& r,const XYZ& t) 52 :rotate(r) 53 ,translate(t) 54 {} 55 56 //! Construct from column vectors Matrix34(const XYZ & rx,const XYZ & ry,const XYZ & rz,const XYZ & tr)57 Matrix34(const XYZ& rx,const XYZ& ry,const XYZ& rz,const XYZ& tr) 58 :rotate(rx,ry,rz) 59 ,translate(tr) 60 {} 61 62 //! Destructor. ~Matrix34()63 ~Matrix34() 64 {} 65 assign(const Matrix34 & m)66 void assign(const Matrix34& m) 67 { 68 rotate=m.rotate; 69 translate=m.translate; 70 } 71 }; 72 73 inline const XYZ operator*(const Matrix34& m,const XYZ& v) 74 { 75 return m.rotate*v+m.translate; 76 } 77 78 inline const Matrix34 operator*(const Matrix34& a,const Matrix34& b) 79 { 80 return Matrix34 81 ( 82 a.rotate*b.rotate, 83 a.rotate*b.translate+a.translate 84 ); 85 } 86 87 class Matrix34Identity : public Matrix34 88 { 89 public: Matrix34Identity()90 Matrix34Identity() 91 :Matrix34(Matrix33Identity(),XYZ(0.0f,0.0f,0.0f)) 92 {} 93 }; 94 95 class Matrix34Translate : public Matrix34 96 { 97 public: Matrix34Translate(const XYZ & t)98 Matrix34Translate(const XYZ& t) 99 :Matrix34(Matrix33Identity(),t) 100 {} 101 }; 102 103 class Matrix34RotateAboutAxisThrough : public Matrix34 104 { 105 public: 106 //! Axis must be normalized 107 Matrix34RotateAboutAxisThrough(const XYZ& axis,float angle,const XYZ& pt); 108 109 //! Axis size gives rotation size 110 Matrix34RotateAboutAxisThrough(const XYZ& axis,const XYZ& pt); 111 }; 112 113 #endif 114 115 116 117 118 119