Main Page   Class Hierarchy   Compound List   File List   Compound Members  

geMatrix4.cpp

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 #include <freecloth/geom/geMatrix4.h>
00020 
00021 ////////////////////////////////////////////////////////////////////////////////
00022 // LOCAL DECLARATIONS
00023 
00024 FREECLOTH_NAMESPACE_START
00025 
00026 ////////////////////////////////////////////////////////////////////////////////
00027 // CLASS GeMatrix4
00028 
00029 const GeMatrix4 GeMatrix4::IDENTITY(1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1);
00030 const GeMatrix4 GeMatrix4::ZERO(0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0);
00031 
00032 
00033 //------------------------------------------------------------------------------
00034 
00035 GeMatrix4 GeMatrix4::colMajor ( const Float data[ 16 ] )
00036 {
00037     GeMatrix4 result;
00038     ::memcpy( result._data, data, sizeof( result._data ) );
00039     return result;
00040 }
00041 
00042 //------------------------------------------------------------------------------
00043 
00044 GeMatrix4 GeMatrix4::rowMajor ( const Float data[ 16 ] )
00045 {
00046     GeMatrix4 result;
00047     for( UInt32 r = 0; r < 4; ++r ) {
00048         for( UInt32 c = 0; c < 4; ++c ) {
00049             result._data[ c*4 + r ] = data[ r*4 + c ];
00050         }
00051     }
00052     return result;
00053 }
00054 
00055 //------------------------------------------------------------------------------
00056 
00057 GeMatrix4 GeMatrix4::operator*( const GeMatrix4& rhs ) const
00058 {
00059     GeMatrix4 result;
00060     for ( UInt32 r = 0; r < 4; ++r ) {
00061         for ( UInt32 c = 0; c < 4; ++c ) {
00062             Float val = 0;
00063             for ( UInt32 i = 0; i < 4; ++i ) {
00064                 val += operator()( r, i ) * rhs( i, c );
00065             }
00066             result( r, c ) = val;
00067         }
00068     }
00069     return result;
00070 }
00071 
00072 
00073 ////////////////////////////////////////////////////////////////////////////////
00074 // GLOBAL FUNCTIONS
00075 //
00076 
00077 //------------------------------------------------------------------------------
00078 
00079 std::ostream& operator<<( std::ostream& out, const GeMatrix4& m )
00080 {
00081     out << "M4(" << std::endl;
00082     out << "  " << m(0,0) << " " << m(0,1) << " "
00083                 << m(0,2) << " " << m(0,3) << std::endl;
00084     out << "  " << m(1,0) << " " << m(1,1) << " "
00085                 << m(1,2) << " " << m(1,3) << std::endl;
00086     out << "  " << m(2,0) << " " << m(2,1) << " "
00087                 << m(2,2) << " " << m(2,3) << std::endl;
00088     out << "  " << m(3,0) << " " << m(3,1) << " "
00089                 << m(3,2) << " " << m(3,3) << std::endl;
00090     out << ")";
00091     return out;
00092 }
00093 
00094 FREECLOTH_NAMESPACE_END

Generated on Fri May 2 13:04:25 2003 for Freecloth by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002