Main Page   Class Hierarchy   Compound List   File List   Compound Members  

geMatrix3.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_geMatrix3_inline_h
00020 #define freecloth_geom_geMatrix3_inline_h
00021 
00022 #include <freecloth/geom/geVector.h>
00023 #include <freecloth/geom/gePoint.h>
00024 
00025 FREECLOTH_NAMESPACE_START
00026 
00027 ////////////////////////////////////////////////////////////////////////////////
00028 // CLASS GeMatrix3
00029 
00030 //------------------------------------------------------------------------------
00031 
00032 inline GeMatrix3::GeMatrix3()
00033 {
00034 }
00035 
00036 //------------------------------------------------------------------------------
00037 
00038 inline GeMatrix3::GeMatrix3(
00039     Float d00, Float d01, Float d02,
00040     Float d10, Float d11, Float d12,
00041     Float d20, Float d21, Float d22
00042 ) {
00043     _data[ 0 ] = d00; _data[ 3 ] = d01; _data[ 6 ] = d02;
00044     _data[ 1 ] = d10; _data[ 4 ] = d11; _data[ 7 ] = d12;
00045     _data[ 2 ] = d20; _data[ 5 ] = d21; _data[ 8 ] = d22;
00046 }
00047 
00048 //------------------------------------------------------------------------------
00049 
00050 inline GeMatrix3 GeMatrix3::scaling( Float sx, Float sy, Float sz )
00051 {
00052     return GeMatrix3(
00053         sx, 0, 0,
00054         0, sy, 0,
00055         0, 0, sz
00056     );
00057 }
00058 
00059 //------------------------------------------------------------------------------
00060 
00061 inline GeMatrix3 GeMatrix3::outerProduct( const GeVector& a, const GeVector& b )
00062 {
00063     return GeMatrix3(
00064         a._x * b._x, a._x * b._y, a._x * b._z,
00065         a._y * b._x, a._y * b._y, a._y * b._z,
00066         a._z * b._x, a._z * b._y, a._z * b._z
00067     );
00068 }
00069 
00070 //------------------------------------------------------------------------------
00071 
00072 inline Float& GeMatrix3::operator()( UInt32 row, UInt32 col )
00073 {
00074     DGFX_ASSERT( row < 3 && col < 3 );
00075     return _data[ col * 3 + row ];
00076 }
00077 
00078 //------------------------------------------------------------------------------
00079 
00080 inline Float GeMatrix3::operator()( UInt32 row, UInt32 col ) const
00081 {
00082     DGFX_ASSERT( row < 3 && col < 3 );
00083     return _data[ col * 3 + row ];
00084 }
00085 
00086 //------------------------------------------------------------------------------
00087 
00088 inline bool GeMatrix3::operator==( const GeMatrix3& rhs ) const
00089 {
00090     bool result = true;
00091     for( UInt32 i = 0; i < 9; ++i ) {
00092         result = result && _data[ i ] == rhs._data[ i ];
00093     }
00094     return result;
00095 }
00096 
00097 //------------------------------------------------------------------------------
00098 
00099 inline bool GeMatrix3::operator!=( const GeMatrix3& rhs ) const
00100 {
00101     return !operator==( rhs );
00102 }
00103 
00104 //------------------------------------------------------------------------------
00105 
00106 inline GeMatrix3& GeMatrix3::operator*=( const GeMatrix3& rhs )
00107 {
00108     return operator=( operator*( rhs ) );
00109 }
00110 
00111 //------------------------------------------------------------------------------
00112 
00113 inline GeMatrix3& GeMatrix3::operator*=( Float rhs )
00114 {
00115     for( UInt32 i = 0; i < 9; ++i ) {
00116         _data[ i ] *= rhs;
00117     }
00118     return *this;
00119 }
00120 
00121 //------------------------------------------------------------------------------
00122 
00123 inline GeMatrix3& GeMatrix3::operator+=( const GeMatrix3& rhs )
00124 {
00125     for( UInt32 i = 0; i < 9; ++i ) {
00126         _data[ i ] += rhs._data[ i ];
00127     }
00128     return *this;
00129 }
00130 
00131 //------------------------------------------------------------------------------
00132 
00133 inline GeMatrix3& GeMatrix3::operator-=( const GeMatrix3& rhs )
00134 {
00135     for( UInt32 i = 0; i < 9; ++i ) {
00136         _data[ i ] -= rhs._data[ i ];
00137     }
00138     return *this;
00139 }
00140 
00141 //------------------------------------------------------------------------------
00142 
00143 inline GeMatrix3 GeMatrix3::operator*( Float rhs ) const
00144 {
00145     GeMatrix3 temp( *this );
00146     temp *= rhs;
00147     return temp;
00148 }
00149 
00150 //------------------------------------------------------------------------------
00151 
00152 inline GeVector GeMatrix3::operator*( const GeVector& rhs ) const
00153 {
00154     // _data[ r+c*3 ]
00155     return GeVector(
00156         _data[ 0+0*3 ]*rhs._x + _data[ 0+1*3 ]*rhs._y + _data[ 0+2*3 ]*rhs._z,
00157         _data[ 1+0*3 ]*rhs._x + _data[ 1+1*3 ]*rhs._y + _data[ 1+2*3 ]*rhs._z,
00158         _data[ 2+0*3 ]*rhs._x + _data[ 2+1*3 ]*rhs._y + _data[ 2+2*3 ]*rhs._z
00159     );
00160 }
00161 
00162 //------------------------------------------------------------------------------
00163 
00164 inline GePoint GeMatrix3::operator*( const GePoint& rhs ) const
00165 {
00166     // _data[ r+c*3 ]
00167     return GePoint(
00168         _data[ 0+0*3 ]*rhs._x + _data[ 0+1*3 ]*rhs._y + _data[ 0+2*3 ]*rhs._z,
00169         _data[ 1+0*3 ]*rhs._x + _data[ 1+1*3 ]*rhs._y + _data[ 1+2*3 ]*rhs._z,
00170         _data[ 2+0*3 ]*rhs._x + _data[ 2+1*3 ]*rhs._y + _data[ 2+2*3 ]*rhs._z
00171     );
00172 }
00173 
00174 //------------------------------------------------------------------------------
00175 
00176 inline GeMatrix3 GeMatrix3::operator+( const GeMatrix3& rhs ) const
00177 {
00178     GeMatrix3 temp( *this );
00179     temp += rhs;
00180     return temp;
00181 }
00182 
00183 //------------------------------------------------------------------------------
00184 
00185 inline GeMatrix3 GeMatrix3::operator-( const GeMatrix3& rhs ) const
00186 {
00187     GeMatrix3 temp( *this );
00188     temp -= rhs;
00189     return temp;
00190 }
00191 
00192 //------------------------------------------------------------------------------
00193 
00194 inline Float GeMatrix3::getTrace() const
00195 {
00196     return _data[ 0 ] + _data[ 4 ] + _data[ 8 ];
00197 }
00198 
00199 //------------------------------------------------------------------------------
00200 
00201 inline Float GeMatrix3::infinityNorm() const
00202 {
00203     return std::max(
00204         std::max(
00205             std::max(
00206                 std::max( _data[ 0 ], _data[ 1 ] ),
00207                 std::max( _data[ 2 ], _data[ 3 ] )
00208             ),
00209             std::max(
00210                 std::max( _data[ 4 ], _data[ 5 ] ),
00211                 std::max( _data[ 6 ], _data[ 7 ] )
00212             )
00213         ),
00214         _data[ 8 ]
00215     );
00216 }
00217 
00218 //------------------------------------------------------------------------------
00219 
00220 inline GeMatrix3 GeMatrix3::getTranspose() const
00221 {
00222     return GeMatrix3::rowMajor( _data );
00223 }
00224 
00225 //------------------------------------------------------------------------------
00226 
00227 inline const Float* GeMatrix3::asColMajor() const
00228 {
00229     return _data;
00230 }
00231 
00232 ////////////////////////////////////////////////////////////////////////////////
00233 // GLOBAL FUNCTIONS
00234 //
00235 
00236 //------------------------------------------------------------------------------
00237 
00238 inline GeMatrix3 operator*( Float lhs, const GeMatrix3& rhs )
00239 {
00240     return rhs * lhs;
00241 }
00242 
00243 //------------------------------------------------------------------------------
00244 
00245 inline GeVector operator*( const GeVector& lhs, const GeMatrix3& rhs )
00246 {
00247     return GeVector(
00248         lhs._x * rhs(0,0) + lhs._y * rhs(1,0) + lhs._z * rhs(2,0),
00249         lhs._x * rhs(0,1) + lhs._y * rhs(1,1) + lhs._z * rhs(2,1),
00250         lhs._x * rhs(0,2) + lhs._y * rhs(1,2) + lhs._z * rhs(2,2)
00251     );
00252 }
00253 
00254 FREECLOTH_NAMESPACE_END
00255 
00256 #endif

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