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( const GeMatrix3& );
00052     //! Named constructor: construct a rotation matrix, representing a
00053     //! rotation of theta about the given axis.
00054     static GeMatrix4 rotation( const GeVector& axis, Float theta );
00055     //! Named constructor: construct a translation matrix: an identity matrix,
00056     //! plus the given vector in the fourth column.
00057     static GeMatrix4 translation( const GeVector& );
00058     //! Named constructor: construct a scaling matrix, with [sx sy sz 1] along
00059     //! the main diagonal
00060     static GeMatrix4 scaling( Float sx, Float sy, Float sz );
00061     //! Named constructor: create matrix M = a * b^T
00062     static GeMatrix4 outerProduct( const GeVector& a, const GeVector& b );
00063     //! Named constructor: embeds 3x3 matrix in the top-left of an identity
00064     //! matrix
00065     static GeMatrix4 from3x3( const GeMatrix3& );
00066 
00067     // ----- member functions -----
00068     
00069     GeMatrix4();
00070     GeMatrix4(
00071         Float entry00, Float entry01, Float entry02, Float entry03,
00072         Float entry10, Float entry11, Float entry12, Float entry13,
00073         Float entry20, Float entry21, Float entry22, Float entry23,
00074         Float entry30, Float entry31, Float entry32, Float entry33
00075     );
00076 
00077     // Default copy constructor is fine.
00078 
00079     // Default assignment operator is fine.
00080     Float operator()( UInt32 row, UInt32 col ) const;
00081     Float& operator()( UInt32 row, UInt32 col );
00082     GeMatrix4& operator*=( const GeMatrix4& );
00083     GeMatrix4& operator*=( Float );
00084     GeMatrix4& operator+=( const GeMatrix4& );
00085     GeMatrix4& operator-=( const GeMatrix4& );
00086     GeMatrix4 operator*( const GeMatrix4& ) const;
00087     //! Matrix-vector multiplication. Treats vector as 4x1, with last element
00088     //! zero.
00089     GeVector operator*( const GeVector& ) const;
00090     //! Matrix-vector multiplication. Treats point as 4x1, with last element
00091     //! one.
00092     GePoint operator*( const GePoint& ) const;
00093     GeMatrix4 operator*( Float ) const;
00094     GeMatrix4 operator+( const GeMatrix4& ) const;
00095     GeMatrix4 operator-( const GeMatrix4& ) const;
00096     bool operator==( const GeMatrix4& ) const;
00097     bool operator!=( const GeMatrix4& ) const;
00098 
00099     //! Sum of diagonal elements.
00100     Float getTrace() const;
00101     const Float* asColMajor() const;
00102     GeMatrix4 getTranspose() const;
00103 
00104     // ----- static data members -----
00105     static const GeMatrix4 ZERO;
00106     static const GeMatrix4 IDENTITY;
00107 
00108 private:
00109     // ----- data members -----
00110 
00111     // Stored in column-major format.
00112     Float _data[ 16 ];
00113 };
00114 
00115 
00116 ////////////////////////////////////////////////////////////////////////////////
00117 // GLOBAL FUNCTIONS
00118 //
00119 
00120 std::ostream& operator<<( std::ostream&, const GeMatrix4& );
00121 //! Scalar-matrix multiplication.
00122 GeMatrix4 operator*( Float, const GeMatrix4& );
00123 
00124 FREECLOTH_NAMESPACE_END
00125 
00126 #include <freecloth/geom/geMatrix4.inline.h>
00127 
00128 #endif

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