00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00027
00029
00030 #ifndef __MATRIX3D_H__
00031 #define __MATRIX3D_H__
00032
00033 #include "H3DApi.h"
00034 #include "H3DBasicTypes.h"
00035 #include "Vec3d.h"
00036 #include "Exception.h"
00037
00038 namespace H3D {
00039 namespace ArithmeticTypes {
00041 class Quaternion;
00042 class Rotation;
00043 class Matrix3f;
00044
00047 class H3DAPI_API Matrix3d {
00048 public:
00051 H3D_API_EXCEPTION( SingularMatrix3d );
00052
00054 inline Matrix3d() {
00055 setToIdentity();
00056 }
00057
00059 inline Matrix3d( H3DDouble m00, H3DDouble m01, H3DDouble m02,
00060 H3DDouble m10, H3DDouble m11, H3DDouble m12,
00061 H3DDouble m20, H3DDouble m21, H3DDouble 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 Matrix3d( const Matrix3f &matrix );
00069
00071 Matrix3d( const Rotation &r );
00072
00074 Matrix3d( const Quaternion &q );
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 Matrix3d transpose() const {
00085 return Matrix3d( 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 Matrix3d inverse() const;
00092
00094 inline H3DDouble* operator[]( int i ) { return m[i]; }
00095
00097 inline const H3DDouble* operator[]( int i ) const { return m[i]; }
00098
00100 inline Vec3d getRow( int i ) const {
00101 return Vec3d( m[i][0], m[i][1], m[i][2] );
00102 }
00103
00105 inline H3DDouble getElement( int i, int j ) const {
00106 return m[i][j];
00107 }
00108
00110 inline void setElement( int i, int j, H3DDouble v ) {
00111 m[i][j] = v;
00112 }
00113
00116 Vec3d toEulerAngles();
00117
00119 inline Vec3d getColumn( int i ) const {
00120 return Vec3d( m[0][i], m[1][i], m[2][i] );
00121 }
00122
00124 Vec3d getScalePart() const;
00125
00126 private:
00128 H3DDouble m[3][3];
00129 };
00130
00137
00139 inline Matrix3d operator*( const Matrix3d &m1, const Matrix3d &m2 ) {
00140 return Matrix3d(
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 Matrix3d operator+( const Matrix3d &m1, const Matrix3d &m2 ) {
00154 return Matrix3d(
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 Matrix3d operator*( const Matrix3d &m, const float &f ) {
00162 return Matrix3d( 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 Matrix3d operator*( const Matrix3d &m, const double &d ) {
00169 return Matrix3d(
00170 (H3DDouble)(m[0][0]*d), (H3DDouble)(m[0][1]*d), (H3DDouble)(m[0][2]*d),
00171 (H3DDouble)(m[1][0]*d), (H3DDouble)(m[1][1]*d), (H3DDouble)(m[1][2]*d),
00172 (H3DDouble)(m[2][0]*d), (H3DDouble)(m[2][1]*d), (H3DDouble)(m[2][2]*d ));
00173 }
00174
00176 inline Matrix3d operator*( const Matrix3d &m, const int &f ) {
00177 return Matrix3d( 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 Matrix3d operator*( const Matrix3d &m, const long &f ) {
00184 return Matrix3d( 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 Matrix3d &m1, const Matrix3d &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 Matrix3d &m );
00200
00202 inline Matrix3d operator*( const float &a, const Matrix3d &b ) { return b * a; }
00203
00205 inline Matrix3d operator*( const double &a, const Matrix3d &b ) { return b * a; }
00206
00208 inline Matrix3d operator*( const int &a, const Matrix3d &b ) { return b * a; }
00209
00211 inline Matrix3d operator*( const long &a, const Matrix3d &b ) { return b * a; }
00212
00214 inline Matrix3d operator-( const Matrix3d &m ) { return m * -1; }
00215
00217 inline Matrix3d operator-( const Matrix3d &a, const Matrix3d &b )
00218 { return a + (-b); }
00219
00221 }
00222 }
00223
00224 #endif