Main Page   Class Hierarchy   Compound List   File List   Compound Members  

geMatrix4.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_h
00020 #define freecloth_geom_geMatrix4_h
00021 
00022 #ifndef freecloth_geom_package_h
00023 #include <freecloth/geom/package.h>
00024 #endif
00025 
00026 FREECLOTH_NAMESPACE_START
00027 
00028 ////////////////////////////////////////////////////////////////////////////////
00029 // FORWARD DECLARATIONS
00030 
00031 class GeVector;
00032 class GePoint;
00033 class GeMatrix3;
00034 
00035 ////////////////////////////////////////////////////////////////////////////////
00036 /*!
00037  * \class GeMatrix4 freecloth/geom/geMatrix4.h
00038  * \brief A simple 4x4 matrix class.
00039  */
00040 class GeMatrix4
00041 {
00042 public:
00043     // ----- static member functions -----
00044     
00045     //! Named constructor: construct from float array, column-major storage
00046     static GeMatrix4 colMajor( const Float data[ 16 ] );
00047     //! Named constructor: construct from float array, row-major storage
00048     static GeMatrix4 rowMajor( const Float data[ 16 ] );
00049     //! Named constructor: construct a rotation matrix: the top-left 3x3 block
00050     //! filled with the given data.
00051     static GeMatrix4 rotation(
00052         Float entry00, Float entry01, Float entry02,
00053         Float entry10, Float entry11, Float entry12,
00054         Float entry20, Float entry21, Float entry22
00055     );
00056     //! Named constructor: construct a translation matrix: an identity matrix,
00057     //! plus the given vector in the fourth column.
00058     static GeMatrix4 translation( const GeVector& );
00059     //! Named constructor: construct a scaling matrix, with [sx sy sz 1] along
00060     //! the main diagonal
00061     static GeMatrix4 scaling( Float sx, Float sy, Float sz );
00062     //! Named constructor: create matrix M = a * b^T
00063     static GeMatrix4 outerProduct( const GeVector& a, const GeVector& b );
00064     //! Named constructor: embeds 3x3 matrix in the top-left of an identity
00065     //! matrix
00066     static GeMatrix4 from3x3( const GeMatrix3& );
00067 
00068     // ----- member functions -----
00069     
00070     GeMatrix4();
00071     GeMatrix4(
00072         Float entry00, Float entry01, Float entry02, Float entry03,
00073         Float entry10, Float entry11, Float entry12, Float entry13,
00074         Float entry20, Float entry21, Float entry22, Float entry23,
00075         Float entry30, Float entry31, Float entry32, Float entry33
00076     );
00077 
00078     // Default copy constructor is fine.
00079 
00080     // Default assignment operator is fine.
00081     Float operator()( UInt32 row, UInt32 col ) const;
00082     Float& operator()( UInt32 row, UInt32 col );
00083     GeMatrix4& operator*=( const GeMatrix4& );
00084     GeMatrix4& operator*=( Float );
00085     GeMatrix4& operator+=( const GeMatrix4& );
00086     GeMatrix4& operator-=( const GeMatrix4& );
00087     GeMatrix4 operator*( const GeMatrix4& ) const;
00088     //! Matrix-vector multiplication. Treats vector as 4x1, with last element
00089     //! zero.
00090     GeVector operator*( const GeVector& ) const;
00091     //! Matrix-vector multiplication. Treats point as 4x1, with last element
00092     //! one.
00093     GePoint operator*( const GePoint& ) const;
00094     GeMatrix4 operator*( Float ) const;
00095     GeMatrix4 operator+( const GeMatrix4& ) const;
00096     GeMatrix4 operator-( const GeMatrix4& ) const;
00097     bool operator==( const GeMatrix4& ) const;
00098     bool operator!=( const GeMatrix4& ) const;
00099 
00100     //! Sum of diagonal elements.
00101     Float getTrace() const;
00102     const Float* asColMajor() const;
00103     GeMatrix4 getTranspose() const;
00104 
00105     // ----- static data members -----
00106     static const GeMatrix4 ZERO;
00107     static const GeMatrix4 IDENTITY;
00108 
00109 private:
00110     // ----- data members -----
00111 
00112     // Stored in column-major format.
00113     Float _data[ 16 ];
00114 };
00115 
00116 
00117 ////////////////////////////////////////////////////////////////////////////////
00118 // GLOBAL FUNCTIONS
00119 //
00120 
00121 std::ostream& operator<<( std::ostream&, const GeMatrix4& );
00122 //! Scalar-matrix multiplication.
00123 GeMatrix4 operator*( Float, const GeMatrix4& );
00124 
00125 FREECLOTH_NAMESPACE_END
00126 
00127 #include <freecloth/geom/geMatrix4.inline.h>
00128 
00129 #endif

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