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(
00053     Float d00, Float d01, Float d02,
00054     Float d10, Float d11, Float d12,
00055     Float d20, Float d21, Float d22
00056 ) {
00057     return GeMatrix4(
00058         d00, d01, d02, 0,
00059         d10, d11, d12, 0,
00060         d20, d21, d22, 0,
00061         0, 0, 0, 1
00062     );
00063 }
00064 
00065 //------------------------------------------------------------------------------
00066 
00067 inline GeMatrix4 GeMatrix4::translation( const GeVector& v )
00068 {
00069     return GeMatrix4(
00070         1, 0, 0, v._x,
00071         0, 1, 0, v._y,
00072         0, 0, 1, v._z,
00073         0, 0, 0, 1
00074     );
00075 }
00076 
00077 //------------------------------------------------------------------------------
00078 
00079 inline GeMatrix4 GeMatrix4::scaling( Float sx, Float sy, Float sz )
00080 {
00081     return GeMatrix4(
00082         sx, 0, 0, 0,
00083         0, sy, 0, 0,
00084         0, 0, sz, 0,
00085         0, 0, 0, 1
00086     );
00087 }
00088 
00089 //------------------------------------------------------------------------------
00090 
00091 inline GeMatrix4 GeMatrix4::outerProduct( const GeVector& a, const GeVector& b )
00092 {
00093     return GeMatrix4(
00094         a._x * b._x, a._x * b._y, a._x * b._z, 0,
00095         a._y * b._x, a._y * b._y, a._y * b._z, 0,
00096         a._z * b._x, a._z * b._y, a._z * b._z, 0,
00097         0, 0, 0, 1
00098     );
00099 }
00100 
00101 //------------------------------------------------------------------------------
00102 
00103 inline GeMatrix4 GeMatrix4::from3x3( const GeMatrix3& m3 )
00104 {
00105     return GeMatrix4(
00106         m3( 0, 0 ), m3( 0, 1 ), m3( 0, 2 ), 0,
00107         m3( 1, 0 ), m3( 1, 1 ), m3( 1, 2 ), 0,
00108         m3( 2, 0 ), m3( 2, 1 ), m3( 2, 2 ), 0,
00109         0, 0, 0, 1
00110     );
00111 }
00112 
00113 //------------------------------------------------------------------------------
00114 
00115 inline Float& GeMatrix4::operator()( UInt32 row, UInt32 col )
00116 {
00117     DGFX_ASSERT( row < 4 && col < 4 );
00118     return _data[ col * 4 + row ];
00119 }
00120 
00121 //------------------------------------------------------------------------------
00122 
00123 inline Float GeMatrix4::operator()( UInt32 row, UInt32 col ) const
00124 {
00125     DGFX_ASSERT( row < 4 && col < 4 );
00126     return _data[ col * 4 + row ];
00127 }
00128 
00129 //------------------------------------------------------------------------------
00130 
00131 inline bool GeMatrix4::operator==( const GeMatrix4& rhs ) const
00132 {
00133     bool result = true;
00134     for( UInt32 i = 0; i < 16; ++i ) {
00135         result = result && _data[ i ] == rhs._data[ i ];
00136     }
00137     return result;
00138 }
00139 
00140 //------------------------------------------------------------------------------
00141 
00142 inline bool GeMatrix4::operator!=( const GeMatrix4& rhs ) const
00143 {
00144     return !operator==( rhs );
00145 }
00146 
00147 //------------------------------------------------------------------------------
00148 
00149 inline GeMatrix4& GeMatrix4::operator*=( const GeMatrix4& rhs )
00150 {
00151     return operator=( operator*( rhs ) );
00152 }
00153 
00154 //------------------------------------------------------------------------------
00155 
00156 inline GeMatrix4& GeMatrix4::operator*=( Float rhs )
00157 {
00158     for( UInt32 i = 0; i < 16; ++i ) {
00159         _data[ i ] *= rhs;
00160     }
00161     return *this;
00162 }
00163 
00164 //------------------------------------------------------------------------------
00165 
00166 inline GeMatrix4& GeMatrix4::operator+=( const GeMatrix4& rhs )
00167 {
00168     for( UInt32 i = 0; i < 16; ++i ) {
00169         _data[ i ] += rhs._data[ i ];
00170     }
00171     return *this;
00172 }
00173 
00174 //------------------------------------------------------------------------------
00175 
00176 inline GeMatrix4& GeMatrix4::operator-=( const GeMatrix4& rhs )
00177 {
00178     for( UInt32 i = 0; i < 16; ++i ) {
00179         _data[ i ] -= rhs._data[ i ];
00180     }
00181     return *this;
00182 }
00183 
00184 //------------------------------------------------------------------------------
00185 
00186 inline GeMatrix4 GeMatrix4::operator*( Float rhs ) const
00187 {
00188     GeMatrix4 temp( *this );
00189     temp *= rhs;
00190     return temp;
00191 }
00192 
00193 //------------------------------------------------------------------------------
00194 
00195 inline GeVector GeMatrix4::operator*( const GeVector& rhs ) const
00196 {
00197     // _data[ c*4+r ]
00198     return GeVector(
00199         _data[ 0*4+0 ]*rhs._x + _data[ 1*4+0 ]*rhs._y + _data[ 2*4+0 ]*rhs._z,
00200         _data[ 0*4+1 ]*rhs._x + _data[ 1*4+1 ]*rhs._y + _data[ 2*4+1 ]*rhs._z,
00201         _data[ 0*4+2 ]*rhs._x + _data[ 1*4+2 ]*rhs._y + _data[ 2*4+2 ]*rhs._z
00202     );
00203 }
00204 
00205 //------------------------------------------------------------------------------
00206 
00207 inline GePoint GeMatrix4::operator*( const GePoint& rhs ) const
00208 {
00209     // _data[ c*4+r ]
00210     return GePoint(
00211         _data[ 0*4+0 ]*rhs._x + _data[ 1*4+0 ]*rhs._y + _data[ 2*4+0 ]*rhs._z
00212             + _data[ 3*4+0 ],
00213         _data[ 0*4+1 ]*rhs._x + _data[ 1*4+1 ]*rhs._y + _data[ 2*4+1 ]*rhs._z
00214             + _data[ 3*4+1 ],
00215         _data[ 0*4+2 ]*rhs._x + _data[ 1*4+2 ]*rhs._y + _data[ 2*4+2 ]*rhs._z
00216             + _data[ 3*4+2 ]
00217     );
00218 }
00219 
00220 //------------------------------------------------------------------------------
00221 
00222 inline GeMatrix4 GeMatrix4::operator+( const GeMatrix4& rhs ) const
00223 {
00224     GeMatrix4 temp( *this );
00225     temp += rhs;
00226     return temp;
00227 }
00228 
00229 //------------------------------------------------------------------------------
00230 
00231 inline GeMatrix4 GeMatrix4::operator-( const GeMatrix4& rhs ) const
00232 {
00233     GeMatrix4 temp( *this );
00234     temp -= rhs;
00235     return temp;
00236 }
00237 
00238 //------------------------------------------------------------------------------
00239 
00240 inline Float GeMatrix4::getTrace() const
00241 {
00242     return _data[ 0 ] + _data[ 5 ] + _data[ 10 ] + _data[ 15 ];
00243 }
00244 
00245 //------------------------------------------------------------------------------
00246 
00247 inline GeMatrix4 GeMatrix4::getTranspose() const
00248 {
00249     return GeMatrix4::rowMajor( _data );
00250 }
00251 
00252 //------------------------------------------------------------------------------
00253 
00254 inline const Float* GeMatrix4::asColMajor() const
00255 {
00256     return _data;
00257 }
00258 
00259 
00260 ////////////////////////////////////////////////////////////////////////////////
00261 // GLOBAL FUNCTIONS
00262 //
00263 
00264 //------------------------------------------------------------------------------
00265 
00266 inline GeMatrix4 operator*( Float lhs, const GeMatrix4& rhs )
00267 {
00268     return rhs * lhs;
00269 }
00270 
00271 FREECLOTH_NAMESPACE_END
00272 
00273 #endif

Generated on Wed Apr 23 15:58:52 2003 for Freecloth by doxygen1.3-rc3