Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

matrix4.h

Go to the documentation of this file.
00001 /*
00002     Sheep - A Rigid Body Dynamics Engine
00003     Copyright (C) 2001-2004 Francois Beaune
00004     Contact: http://toxicengine.sourceforge.net/
00005 
00006     This file is part of Sheep.
00007 
00008     Sheep is free software; you can redistribute it and/or modify
00009     it under the terms of the GNU General Public License as published by
00010     the Free Software Foundation; either version 2 of the License, or
00011     (at your option) any later version.
00012 
00013     Sheep is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016     GNU General Public License for more details.
00017 
00018     You should have received a copy of the GNU General Public License
00019     along with Sheep; if not, write to the Free Software
00020     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021 */
00022 
00023 #ifndef SHEEP_MATH_MATRIX4_H
00024 #define SHEEP_MATH_MATRIX4_H
00025 
00026 #include "common/misc/htmlstream.h"
00027 #include "quaternion.h"
00028 #include "point3.h"
00029 #include "real.h"
00030 #include "vector3.h"
00031 #include "vector4.h"
00032 
00033 #include <cassert>
00034 
00035 namespace sheep {
00036 
00037     class Matrix4 {
00038     public:
00039         // Constructors.
00040         Matrix4();
00041         Matrix4(Real r);
00042         Matrix4(const Matrix4 &m);
00043 
00044         // Identity matrix.
00045         static Matrix4 Identity();
00046 
00047         // Transformations.
00048         static Matrix4 Rotation(const Quaternion &q);   // q must be normalized
00049         static Matrix4 Rotation(Real angle, const Vector3 &axis);
00050         static Matrix4 Rotation(Real rotx, Real roty, Real rotz);   //!< Order of rotations: X, then Y, then Z.
00051         static Matrix4 Scale(const Vector3 &s);
00052         static Matrix4 Translation(const Vector3 &t);
00053 
00054         // Assignment operators.
00055         Matrix4 &operator=(Real r);
00056         Matrix4 &operator=(const Matrix4 &m);
00057 
00058         // Basic operations.
00059         Matrix4 operator+(const Matrix4 &m) const;
00060         Matrix4 operator-(const Matrix4 &m) const;
00061         Matrix4 operator-() const;
00062         Matrix4 operator*(Real r) const;
00063         Matrix4 operator/(Real r) const;
00064         Matrix4 &operator+=(const Matrix4 &m);
00065         Matrix4 &operator-=(const Matrix4 &m);
00066         Matrix4 &operator*=(Real r);
00067         Matrix4 &operator/=(Real r);
00068 
00069         // Matrix products.
00070         Matrix4 operator*(const Matrix4 &m) const;
00071         Matrix4 &operator*=(const Matrix4 &m);
00072 
00073         // Product of a matrix and a vector.
00074         Vector4 operator*(const Vector4 &v) const;
00075 
00076         //! Product of a matrix and a 3-vector or a 3-point. Treat the matrix
00077         //! as a 4x3 matrix (does not take into account the last row).
00078         Vector3 operator*(const Vector3 &v) const;
00079         Point3 operator*(const Point3 &v) const;    
00080 
00081         // Array subscripting.
00082         Real &operator[](int i);
00083         const Real &operator[](int i) const;
00084 
00085         // Fortran-style subscripting (still 0-based).
00086         Real &operator()(int row, int column);
00087         const Real &operator()(int row, int column) const;
00088 
00089         // Transpose.
00090         Matrix4 Transpose() const;
00091 
00092         // Inverse.
00093         Matrix4 Inverse() const;
00094 
00095         // Determinant.
00096         Real Determinant() const;
00097 
00098         // Trace.
00099         Real Trace() const;
00100 
00101     private:
00102         Real m_v[16];   // matrix values (row-major)
00103     };
00104 
00105     // Product of a real by a matrix.
00106     Matrix4 operator*(Real r, const Matrix4 &m);
00107 
00108     //! Deprecated.
00109     htmlstream& operator<<(htmlstream& s, const Matrix4 &m);
00110 
00111 #include "matrix4.inl"
00112 
00113 }
00114 
00115 #endif  // !SHEEP_MATH_MATRIX4_H

Generated on Tue May 11 01:31:50 2004 for toxic by doxygen 1.3.6