Matrix3f.h

Go to the documentation of this file.
00001 
00002 //    Copyright 2004, SenseGraphics AB
00003 //
00004 //    This file is part of H3D API.
00005 //
00006 //    H3D API is free software; you can redistribute it and/or modify
00007 //    it under the terms of the GNU General Public License as published by
00008 //    the Free Software Foundation; either version 2 of the License, or
00009 //    (at your option) any later version.
00010 //
00011 //    H3D API is distributed in the hope that it will be useful,
00012 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //    GNU General Public License for more details.
00015 //
00016 //    You should have received a copy of the GNU General Public License
00017 //    along with H3D API; if not, write to the Free Software
00018 //    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 //
00020 //    A commercial license is also available. Please contact us at 
00021 //    www.sensegraphics.com for more information.
00022 //
00023 //
00027 //
00029 
00030 #ifndef __MATRIX3F_H__
00031 #define __MATRIX3F_H__
00032 
00033 #include "H3DApi.h"
00034 #include "H3DBasicTypes.h"
00035 #include "Vec3f.h"
00036 #include "Exception.h"
00037 
00038 namespace H3D {
00039   namespace ArithmeticTypes {
00041     class Quaternion;
00042     class Rotation;
00043     class Matrix3d;
00044 
00047     class H3DAPI_API Matrix3f {
00048     public:
00051       H3D_API_EXCEPTION( SingularMatrix3f );
00052 
00054       inline Matrix3f() {
00055         setToIdentity();
00056       }
00057 
00059       inline Matrix3f( H3DFloat m00, H3DFloat m01, H3DFloat m02,
00060                        H3DFloat m10, H3DFloat m11, H3DFloat m12,
00061                        H3DFloat m20, H3DFloat m21, H3DFloat m22 ) {
00062         m[0][0] = m00; m[0][1] = m01; m[0][2] = m02; 
00063         m[1][0] = m10; m[1][1] = m11; m[1][2] = m12; 
00064         m[2][0] = m20; m[2][1] = m21; m[2][2] = m22; 
00065       }
00066 
00068       Matrix3f( const Rotation &r );
00069 
00071       Matrix3f( const Quaternion &q );
00072 
00074       explicit Matrix3f( const Matrix3d &v );
00075 
00077       inline void setToIdentity() {
00078         m[0][0] = 1; m[0][1] = 0; m[0][2] = 0;
00079         m[1][0] = 0; m[1][1] = 1; m[1][2] = 0;
00080         m[2][0] = 0; m[2][1] = 0; m[2][2] = 1;
00081       }
00082                                 
00084       inline Matrix3f transpose() const {
00085         return Matrix3f( m[0][0], m[1][0], m[2][0],
00086                                                                                                  m[0][1], m[1][1], m[2][1],
00087                                                                                                  m[0][2], m[1][2], m[2][2] );
00088       };
00089 
00091       Matrix3f inverse() const;
00092 
00094       inline H3DFloat* operator[]( int i ) { return m[i]; }
00095 
00097       inline const H3DFloat* operator[]( int i ) const { return m[i]; }
00098 
00100       inline Vec3f getRow( int i ) const { 
00101         return Vec3f( m[i][0], m[i][1], m[i][2] ); 
00102       }
00103 
00105       inline H3DFloat getElement( int i, int j ) const { 
00106         return m[i][j];
00107       }
00108 
00110       inline void setElement( int i, int j, H3DFloat v ) { 
00111         m[i][j] = v;
00112       }
00113 
00115       Vec3f getScalePart() const;
00116 
00119       Vec3f toEulerAngles();
00120 
00122       inline Vec3f getColumn( int i ) const { 
00123         return Vec3f( m[0][i], m[1][i], m[2][i] ); 
00124       }
00125 
00126     private:
00128       H3DFloat m[3][3];
00129     };
00130     
00137                                 
00139     inline Matrix3f operator*( const Matrix3f &m1, const Matrix3f &m2 ) {
00140       return Matrix3f( 
00141                       m1[0][0]*m2[0][0] + m1[0][1]*m2[1][0] + m1[0][2]*m2[2][0],
00142                       m1[0][0]*m2[0][1] + m1[0][1]*m2[1][1] + m1[0][2]*m2[2][1],
00143                       m1[0][0]*m2[0][2] + m1[0][1]*m2[1][2] + m1[0][2]*m2[2][2],
00144                       m1[1][0]*m2[0][0] + m1[1][1]*m2[1][0] + m1[1][2]*m2[2][0],
00145                       m1[1][0]*m2[0][1] + m1[1][1]*m2[1][1] + m1[1][2]*m2[2][1],
00146                       m1[1][0]*m2[0][2] + m1[1][1]*m2[1][2] + m1[1][2]*m2[2][2],
00147                       m1[2][0]*m2[0][0] + m1[2][1]*m2[1][0] + m1[2][2]*m2[2][0],
00148                       m1[2][0]*m2[0][1] + m1[2][1]*m2[1][1] + m1[2][2]*m2[2][1],
00149                       m1[2][0]*m2[0][2] + m1[2][1]*m2[1][2] + m1[2][2]*m2[2][2] );
00150     }
00151     
00153     inline Matrix3f operator+( const Matrix3f &m1, const Matrix3f &m2 ) {
00154       return Matrix3f( 
00155                       m1[0][0]+m2[0][0], m1[0][1]+m2[0][1], m1[0][2]+m2[0][2],
00156                       m1[1][0]+m2[1][0], m1[1][1]+m2[1][1], m1[1][2]+m2[1][2],
00157                       m1[2][0]+m2[2][0], m1[2][1]+m2[2][1], m1[2][2]+m2[2][2] );
00158     }
00159                 
00161     inline Matrix3f operator*( const Matrix3f &m, const float &f ) {
00162       return Matrix3f( m[0][0]*f, m[0][1]*f, m[0][2]*f,
00163                        m[1][0]*f, m[1][1]*f, m[1][2]*f,
00164                        m[2][0]*f, m[2][1]*f, m[2][2]*f );
00165     }
00166 
00168     inline Matrix3f operator*( const Matrix3f &m, const double &d ) {
00169       return Matrix3f( 
00170    (H3DFloat)(m[0][0]*d), (H3DFloat)(m[0][1]*d), (H3DFloat)(m[0][2]*d),
00171    (H3DFloat)(m[1][0]*d), (H3DFloat)(m[1][1]*d), (H3DFloat)(m[1][2]*d),
00172    (H3DFloat)(m[2][0]*d), (H3DFloat)(m[2][1]*d), (H3DFloat)(m[2][2]*d ));
00173     }
00174 
00176     inline Matrix3f operator*( const Matrix3f &m, const int &f ) {
00177       return Matrix3f( m[0][0]*f, m[0][1]*f, m[0][2]*f,
00178                        m[1][0]*f, m[1][1]*f, m[1][2]*f,
00179                        m[2][0]*f, m[2][1]*f, m[2][2]*f );
00180     }
00181 
00183     inline Matrix3f operator*( const Matrix3f &m, const long &f ) {
00184       return Matrix3f( m[0][0]*f, m[0][1]*f, m[0][2]*f,
00185                        m[1][0]*f, m[1][1]*f, m[1][2]*f,
00186                        m[2][0]*f, m[2][1]*f, m[2][2]*f );
00187     }
00188 
00190     inline bool operator==( const Matrix3f &m1, const Matrix3f &m2 ) {
00191       return (
00192          m1[0][0]==m2[0][0] && m1[0][1]==m2[0][1] && m1[0][2]==m2[0][2] &&
00193          m1[1][0]==m2[1][0] && m1[1][1]==m2[1][1] && m1[1][2]==m2[1][2] && 
00194          m1[2][0]==m2[2][0] && m1[2][1]==m2[2][1] && m1[2][2]==m2[2][2] 
00195          );
00196      }
00197 
00199           H3DAPI_API ostream& operator<<( ostream &os, const Matrix3f &m );
00200 
00202     inline Matrix3f operator*( const float &a, const Matrix3f &b ) { return b * a; }
00203 
00205     inline Matrix3f operator*( const double &a, const Matrix3f &b ) { return b * a; }
00206 
00208     inline Matrix3f operator*( const int &a, const Matrix3f &b ) { return b * a; }
00209 
00211     inline Matrix3f operator*( const long &a, const Matrix3f &b ) { return b * a; }
00212     
00214     inline Matrix3f operator-( const Matrix3f &m ) { return m * -1; }
00215     
00217     inline Matrix3f operator-( const Matrix3f &a, const Matrix3f &b ) 
00218         { return a + (-b); }
00219 
00221   }
00222 }
00223 
00224 #endif

Generated on Thu Aug 24 12:38:33 2006 for H3D API by  doxygen 1.4.5