00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef COURNIA_MATRIX4_H
00030 #define COURNIA_MATRIX4_H 1
00031
00032 #include <iostream>
00033 #include <cassert>
00034 #include "fob/vector.h"
00035 #include "fob/mathematics.h"
00036
00037 namespace math {
00038 class matrix4;
00039 math::vector3 operator* ( const math::vector3& v, const math::matrix4& m );
00040 std::ostream& operator<< ( std::ostream& o, const math::matrix4& m );
00041 }
00042
00044
00059 class math::matrix4
00060 {
00061 protected:
00062 real_t m_data[ 4 ][ 4 ];
00063
00065
00084 friend math::vector3 math::operator* ( const math::vector3& v, const math::matrix4& m );
00085
00087 friend std::ostream& math::operator<< ( std::ostream& o, const math::matrix4& m );
00088
00089 public:
00091 matrix4( void );
00092
00094
00107 matrix4(
00108 real_t d00, real_t d01, real_t d02,
00109 real_t d10, real_t d11, real_t d12,
00110 real_t d20, real_t d21, real_t d22
00111 );
00112
00114
00127 matrix4(
00128 real_t d00, real_t d01, real_t d02, real_t d03,
00129 real_t d10, real_t d11, real_t d12, real_t d13,
00130 real_t d20, real_t d21, real_t d22, real_t d23,
00131 real_t d30, real_t d31, real_t d32, real_t d33
00132 );
00133
00135 matrix4( const math::matrix4& m );
00136
00138 virtual ~matrix4( void ) { }
00139
00141 math::matrix4& operator= ( const math::matrix4 &m );
00142
00145
00147 operator const real_t* ( void ) const {
00148 return static_cast<const real_t*>(m_data[ 0 ]);
00149 }
00150
00152
00165 void set(
00166 real_t d00, real_t d01, real_t d02,
00167 real_t d10, real_t d11, real_t d12,
00168 real_t d20, real_t d21, real_t d22
00169 );
00170
00172
00185 void set(
00186 real_t d00, real_t d01, real_t d02, real_t d03,
00187 real_t d10, real_t d11, real_t d12, real_t d13,
00188 real_t d20, real_t d21, real_t d22, real_t d23,
00189 real_t d30, real_t d31, real_t d32, real_t d33
00190 );
00191
00193
00197 inline void set( unsigned int row, unsigned int col, real_t x ) {
00198 assert( (row < 4) && (col < 4) );
00199 m_data[ row ][ col ] = x;
00200 }
00201
00203
00207 inline real_t operator()( unsigned int row, unsigned int col ) const {
00208 assert( (row < 4) && (col < 4) );
00209 return m_data[ row ][ col ];
00210 }
00211
00213
00217 inline real_t& operator()( unsigned int row, unsigned int col ) {
00218 assert( (row < 4) && (col < 4) );
00219 return m_data[ row ][ col ];
00220 }
00221
00223
00245 math::vector3 operator* ( const math::vector3& v ) const;
00246
00248 math::matrix4 operator* ( const math::matrix4& rhs ) const;
00249
00251 math::matrix4 operator+ ( const math::matrix4& rhs ) const;
00252
00254 math::matrix4 operator- ( const math::matrix4& rhs ) const;
00255
00257
00260 void transpose( void );
00261
00263
00276 inline void set_identity( ) {
00277 *this = math::matrix4::IDENTITY;
00278 }
00279
00281
00289 void from_angle_axis( real_t radians, const math::vector3& axis );
00290
00292
00296 math::matrix4 get_inverted_rotation( void ) const;
00297
00299
00313 inline void set_translation( const math::vector3& trans ) {
00314 m_data[ 0 ][ 3 ] = trans.x( );
00315 m_data[ 1 ][ 3 ] = trans.y( );
00316 m_data[ 2 ][ 3 ] = trans.z( );
00317 }
00318
00320 inline math::vector3 get_translation( void ) const {
00321 return math::vector3( m_data[ 0 ][ 3 ],
00322 m_data[ 1 ][ 3 ],
00323 m_data[ 2 ][ 3 ]
00324 );
00325 }
00326
00328 math::vector3 get_radians( void );
00329
00331 math::vector3 get_degrees( void );
00332
00334
00337 void from_matrix3( const real_t *mat );
00338
00340
00343 void from_matrix4( const real_t *mat );
00344
00346
00358 static const math::matrix4 IDENTITY;
00359
00361
00373 static const math::matrix4 ZERO;
00374 };
00375
00376 #endif