Main Page   Class Hierarchy   Compound List   File List   Compound Members  

geMatrix4.inline.h

00001 //////////////////////////////////////////////////////////////////////
00002 // Copyright (c) 2002-2003 David Pritchard <drpritch@alumni.uwaterloo.ca>
00003 // 
00004 // This program is free software; you can redistribute it and/or
00005 // modify it under the terms of the GNU Lesser General Public License
00006 // as published by the Free Software Foundation; either
00007 // version 2 of the License, or (at your option) any later
00008 // version.
00009 // 
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU Lesser General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU Lesser General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 
00019 #ifndef freecloth_geom_geMatrix4_inline_h
00020 #define freecloth_geom_geMatrix4_inline_h
00021 
00022 #include <freecloth/geom/geVector.h>
00023 #include <freecloth/geom/gePoint.h>
00024 #include <freecloth/geom/geMatrix3.h>
00025 
00026 FREECLOTH_NAMESPACE_START
00027 
00028 ////////////////////////////////////////////////////////////////////////////////
00029 // CLASS GeMatrix4
00030 
00031 //------------------------------------------------------------------------------
00032 
00033 inline GeMatrix4::GeMatrix4()
00034 {}
00035 
00036 //------------------------------------------------------------------------------
00037 
00038 inline GeMatrix4::GeMatrix4(
00039     Float d00, Float d01, Float d02, Float d03,
00040     Float d10, Float d11, Float d12, Float d13,
00041     Float d20, Float d21, Float d22, Float d23,
00042     Float d30, Float d31, Float d32, Float d33
00043 ) {
00044     _data[ 0 ] = d00; _data[ 4 ] = d01; _data[ 8 ] = d02; _data[ 12 ] = d03;
00045     _data[ 1 ] = d10; _data[ 5 ] = d11; _data[ 9 ] = d12; _data[ 13 ] = d13;
00046     _data[ 2 ] = d20; _data[ 6 ] = d21; _data[ 10 ] = d22; _data[ 14 ] = d23;
00047     _data[ 3 ] = d30; _data[ 7 ] = d31; _data[ 11 ] = d32; _data[ 15 ] = d33;
00048 }
00049 
00050 //------------------------------------------------------------------------------
00051 
00052 inline GeMatrix4 GeMatrix4::rotation( const GeMatrix3& m3 )
00053 {
00054     return GeMatrix4(
00055         m3(0,0), m3(0,1), m3(0,2), 0,
00056         m3(1,0), m3(1,1), m3(1,2), 0,
00057         m3(2,0), m3(2,1), m3(2,2), 0,
00058         0, 0, 0, 1
00059     );
00060 }
00061 
00062 //------------------------------------------------------------------------------
00063 
00064 inline GeMatrix4 GeMatrix4::rotation( const GeVector& axis, Float theta )
00065 {
00066     return rotation( GeMatrix3::rotation( axis, theta ) );
00067 }
00068 
00069 //------------------------------------------------------------------------------
00070 
00071 inline GeMatrix4 GeMatrix4::translation( const GeVector& v )
00072 {
00073     return GeMatrix4(
00074         1, 0, 0, v._x,
00075         0, 1, 0, v._y,
00076         0, 0, 1, v._z,
00077         0, 0, 0, 1
00078     );
00079 }
00080 
00081 //------------------------------------------------------------------------------
00082 
00083 inline GeMatrix4 GeMatrix4::scaling( Float sx, Float sy, Float sz )
00084 {
00085     return GeMatrix4(
00086         sx, 0, 0, 0,
00087         0, sy, 0, 0,
00088         0, 0, sz, 0,
00089         0, 0, 0, 1
00090     );
00091 }
00092 
00093 //------------------------------------------------------------------------------
00094 
00095 inline GeMatrix4 GeMatrix4::outerProduct( const GeVector& a, const GeVector& b )
00096 {
00097     return GeMatrix4(
00098         a._x * b._x, a._x * b._y, a._x * b._z, 0,
00099         a._y * b._x, a._y * b._y, a._y * b._z, 0,
00100         a._z * b._x, a._z * b._y, a._z * b._z, 0,
00101         0, 0, 0, 1
00102     );
00103 }
00104 
00105 //------------------------------------------------------------------------------
00106 
00107 inline GeMatrix4 GeMatrix4::from3x3( const GeMatrix3& m3 )
00108 {
00109     return GeMatrix4(
00110         m3( 0, 0 ), m3( 0, 1 ), m3( 0, 2 ), 0,
00111         m3( 1, 0 ), m3( 1, 1 ), m3( 1, 2 ), 0,
00112         m3( 2, 0 ), m3( 2, 1 ), m3( 2, 2 ), 0,
00113         0, 0, 0, 1
00114     );
00115 }
00116 
00117 //------------------------------------------------------------------------------
00118 
00119 inline Float& GeMatrix4::operator()( UInt32 row, UInt32 col )
00120 {
00121     DGFX_ASSERT( row < 4 && col < 4 );
00122     return _data[ col * 4 + row ];
00123 }
00124 
00125 //------------------------------------------------------------------------------
00126 
00127 inline Float GeMatrix4::operator()( UInt32 row, UInt32 col ) const
00128 {
00129     DGFX_ASSERT( row < 4 && col < 4 );
00130     return _data[ col * 4 + row ];
00131 }
00132 
00133 //------------------------------------------------------------------------------
00134 
00135 inline bool GeMatrix4::operator==( const GeMatrix4& rhs ) const
00136 {
00137     bool result = true;
00138     for( UInt32 i = 0; i < 16; ++i ) {
00139         result = result && _data[ i ] == rhs._data[ i ];
00140     }
00141     return result;
00142 }
00143 
00144 //------------------------------------------------------------------------------
00145 
00146 inline bool GeMatrix4::operator!=( const GeMatrix4& rhs ) const
00147 {
00148     return !operator==( rhs );
00149 }
00150 
00151 //------------------------------------------------------------------------------
00152 
00153 inline GeMatrix4& GeMatrix4::operator*=( const GeMatrix4& rhs )
00154 {
00155     return operator=( operator*( rhs ) );
00156 }
00157 
00158 //------------------------------------------------------------------------------
00159 
00160 inline GeMatrix4& GeMatrix4::operator*=( Float rhs )
00161 {
00162     for( UInt32 i = 0; i < 16; ++i ) {
00163         _data[ i ] *= rhs;
00164     }
00165     return *this;
00166 }
00167 
00168 //------------------------------------------------------------------------------
00169 
00170 inline GeMatrix4& GeMatrix4::operator+=( const GeMatrix4& rhs )
00171 {
00172     for( UInt32 i = 0; i < 16; ++i ) {
00173         _data[ i ] += rhs._data[ i ];
00174     }
00175     return *this;
00176 }
00177 
00178 //------------------------------------------------------------------------------
00179 
00180 inline GeMatrix4& GeMatrix4::operator-=( const GeMatrix4& rhs )
00181 {
00182     for( UInt32 i = 0; i < 16; ++i ) {
00183         _data[ i ] -= rhs._data[ i ];
00184     }
00185     return *this;
00186 }
00187 
00188 //------------------------------------------------------------------------------
00189 
00190 inline GeMatrix4 GeMatrix4::operator*( Float rhs ) const
00191 {
00192     GeMatrix4 temp( *this );
00193     temp *= rhs;
00194     return temp;
00195 }
00196 
00197 //------------------------------------------------------------------------------
00198 
00199 inline GeVector GeMatrix4::operator*( const GeVector& rhs ) const
00200 {
00201     // _data[ c*4+r ]
00202     return GeVector(
00203         _data[ 0*4+0 ]*rhs._x + _data[ 1*4+0 ]*rhs._y + _data[ 2*4+0 ]*rhs._z,
00204         _data[ 0*4+1 ]*rhs._x + _data[ 1*4+1 ]*rhs._y + _data[ 2*4+1 ]*rhs._z,
00205         _data[ 0*4+2 ]*rhs._x + _data[ 1*4+2 ]*rhs._y + _data[ 2*4+2 ]*rhs._z
00206     );
00207 }
00208 
00209 //------------------------------------------------------------------------------
00210 
00211 inline GePoint GeMatrix4::operator*( const GePoint& rhs ) const
00212 {
00213     // _data[ c*4+r ]
00214     return GePoint(
00215         _data[ 0*4+0 ]*rhs._x + _data[ 1*4+0 ]*rhs._y + _data[ 2*4+0 ]*rhs._z
00216             + _data[ 3*4+0 ],
00217         _data[ 0*4+1 ]*rhs._x + _data[ 1*4+1 ]*rhs._y + _data[ 2*4+1 ]*rhs._z
00218             + _data[ 3*4+1 ],
00219         _data[ 0*4+2 ]*rhs._x + _data[ 1*4+2 ]*rhs._y + _data[ 2*4+2 ]*rhs._z
00220             + _data[ 3*4+2 ]
00221     );
00222 }
00223 
00224 //------------------------------------------------------------------------------
00225 
00226 inline GeMatrix4 GeMatrix4::operator+( const GeMatrix4& rhs ) const
00227 {
00228     GeMatrix4 temp( *this );
00229     temp += rhs;
00230     return temp;
00231 }
00232 
00233 //------------------------------------------------------------------------------
00234 
00235 inline GeMatrix4 GeMatrix4::operator-( const GeMatrix4& rhs ) const
00236 {
00237     GeMatrix4 temp( *this );
00238     temp -= rhs;
00239     return temp;
00240 }
00241 
00242 //------------------------------------------------------------------------------
00243 
00244 inline Float GeMatrix4::getTrace() const
00245 {
00246     return _data[ 0 ] + _data[ 5 ] + _data[ 10 ] + _data[ 15 ];
00247 }
00248 
00249 //------------------------------------------------------------------------------
00250 
00251 inline GeMatrix4 GeMatrix4::getTranspose() const
00252 {
00253     return GeMatrix4::rowMajor( _data );
00254 }
00255 
00256 //------------------------------------------------------------------------------
00257 
00258 inline const Float* GeMatrix4::asColMajor() const
00259 {
00260     return _data;
00261 }
00262 
00263 
00264 ////////////////////////////////////////////////////////////////////////////////
00265 // GLOBAL FUNCTIONS
00266 //
00267 
00268 //------------------------------------------------------------------------------
00269 
00270 inline GeMatrix4 operator*( Float lhs, const GeMatrix4& rhs )
00271 {
00272     return rhs * lhs;
00273 }
00274 
00275 FREECLOTH_NAMESPACE_END
00276 
00277 #endif

Generated on Fri May 2 16:51:12 2003 for Freecloth by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002