00001
00002
00003
00004
00005
00006
00007 #ifndef COURNIA_MATRIX4_H
00008 #define COURNIA_MATRIX4_H 1
00009
00010 #include <iostream>
00011 #include <cassert>
00012 #include "vector.h"
00013 #include "mathematics.h"
00014
00015 namespace math {
00016 class matrix4;
00017 }
00018
00019 math::vector3 operator* ( const math::vector3& v, const math::matrix4& m );
00020 std::ostream& operator<< ( std::ostream& o, const math::matrix4& m );
00021
00023
00038 class math::matrix4
00039 {
00040 protected:
00041 real_t m_data[ 4 ][ 4 ];
00042
00044
00063 friend math::vector3 operator* ( const math::vector3& v, const math::matrix4& m );
00064
00066 friend std::ostream& operator<< ( std::ostream& o, const math::matrix4& m );
00067
00068 public:
00070 matrix4( void );
00071
00073
00086 matrix4(
00087 real_t d00, real_t d01, real_t d02,
00088 real_t d10, real_t d11, real_t d12,
00089 real_t d20, real_t d21, real_t d22
00090 );
00091
00093
00106 matrix4(
00107 real_t d00, real_t d01, real_t d02, real_t d03,
00108 real_t d10, real_t d11, real_t d12, real_t d13,
00109 real_t d20, real_t d21, real_t d22, real_t d23,
00110 real_t d30, real_t d31, real_t d32, real_t d33
00111 );
00112
00114 matrix4( const math::matrix4& m );
00115
00117 virtual ~matrix4( void ) { }
00118
00120 math::matrix4& operator= ( const math::matrix4 &m );
00121
00124
00126 operator const real_t* ( void ) const {
00127 return static_cast<const real_t*>(m_data[ 0 ]);
00128 }
00129
00131
00144 void set(
00145 real_t d00, real_t d01, real_t d02,
00146 real_t d10, real_t d11, real_t d12,
00147 real_t d20, real_t d21, real_t d22
00148 );
00149
00151
00164 void set(
00165 real_t d00, real_t d01, real_t d02, real_t d03,
00166 real_t d10, real_t d11, real_t d12, real_t d13,
00167 real_t d20, real_t d21, real_t d22, real_t d23,
00168 real_t d30, real_t d31, real_t d32, real_t d33
00169 );
00170
00172
00176 inline void set( unsigned int row, unsigned int col, real_t x ) {
00177 assert( (row < 4) && (col < 4) );
00178 m_data[ row ][ col ] = x;
00179 }
00180
00182
00186 inline real_t operator()( unsigned int row, unsigned int col ) const {
00187 assert( (row < 4) && (col < 4) );
00188 return m_data[ row ][ col ];
00189 }
00190
00192
00196 inline real_t& operator()( unsigned int row, unsigned int col ) {
00197 assert( (row < 4) && (col < 4) );
00198 return m_data[ row ][ col ];
00199 }
00200
00202
00224 math::vector3 operator* ( const math::vector3& v ) const;
00225
00227 math::matrix4 operator* ( const math::matrix4& rhs ) const;
00228
00230 math::matrix4 operator+ ( const math::matrix4& rhs ) const;
00231
00233 math::matrix4 operator- ( const math::matrix4& rhs ) const;
00234
00236
00239 void transpose( void );
00240
00242
00255 inline void set_identity( ) {
00256 *this = math::matrix4::IDENTITY;
00257 }
00258
00260
00268 void from_angle_axis( real_t radians, const math::vector3& axis );
00269
00271
00275 math::matrix4 get_inverted_rotation( void ) const;
00276
00278
00292 inline void set_translation( const math::vector3& trans ) {
00293 m_data[ 0 ][ 3 ] = trans.x( );
00294 m_data[ 1 ][ 3 ] = trans.y( );
00295 m_data[ 2 ][ 3 ] = trans.z( );
00296 }
00297
00299 inline math::vector3 get_translation( void ) const {
00300 return math::vector3( m_data[ 0 ][ 3 ],
00301 m_data[ 1 ][ 3 ],
00302 m_data[ 2 ][ 3 ]
00303 );
00304 }
00305
00307
00319 static const math::matrix4 IDENTITY;
00320
00322
00334 static const math::matrix4 ZERO;
00335 };
00336
00337 #endif