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_MATRIX3_H 00024 #define SHEEP_MATH_MATRIX3_H 00025 00026 #include "common/misc/htmlstream.h" 00027 #include "quaternion.h" 00028 #include "real.h" 00029 #include "vector3.h" 00030 00031 #include <cassert> 00032 00033 namespace sheep { 00034 00035 class Matrix3 { 00036 public: 00037 // Constructors. 00038 Matrix3(); 00039 Matrix3(Real r); 00040 Matrix3(const Matrix3 &m); 00041 00042 // Identity matrix. 00043 static Matrix3 Identity(); 00044 00045 // Transformations. 00046 static Matrix3 Rotation(const Quaternion &q); // q must be normalized 00047 static Matrix3 Rotation(Real angle, const Vector3 &axis); 00048 static Matrix3 Rotation(Real rotx, Real roty, Real rotz); //!< Order of rotations: X, then Y, then Z. 00049 static Matrix3 Scale(const Vector3 &s); 00050 00051 void GetEulerAngles(Real *rotx, Real *roty, Real *rotz) const; 00052 00053 // Assignment operators. 00054 Matrix3 &operator=(Real r); 00055 Matrix3 &operator=(const Matrix3 &m); 00056 00057 // Basic operations. 00058 Matrix3 operator+(const Matrix3 &m) const; 00059 Matrix3 operator-(const Matrix3 &m) const; 00060 Matrix3 operator-() const; 00061 Matrix3 operator*(Real r) const; 00062 Matrix3 operator/(Real r) const; 00063 Matrix3 &operator+=(const Matrix3 &m); 00064 Matrix3 &operator-=(const Matrix3 &m); 00065 Matrix3 &operator*=(Real r); 00066 Matrix3 &operator/=(Real r); 00067 00068 // Matrix products. 00069 Matrix3 operator*(const Matrix3 &m) const; 00070 Matrix3 &operator*=(const Matrix3 &m); 00071 00072 // Product of a matrix and a vector. 00073 Vector3 operator*(const Vector3 &v) const; 00074 00075 // Array subscripting. 00076 Real &operator[](int i); 00077 const Real &operator[](int i) const; 00078 00079 // Fortran-style subscripting (still 0-based). 00080 Real &operator()(int row, int column); 00081 const Real &operator()(int row, int column) const; 00082 00083 // Transpose. 00084 Matrix3 Transpose() const; 00085 00086 // Inverse. 00087 Matrix3 Inverse() const; 00088 00089 // Determinant. 00090 Real Determinant() const; 00091 00092 // Trace. 00093 Real Trace() const; 00094 00095 private: 00096 Real m_v[9]; // matrix values (row-major) 00097 }; 00098 00099 // Product of a real by a matrix. 00100 Matrix3 operator*(Real r, const Matrix3 &m); 00101 00102 //! Deprecated. 00103 htmlstream& operator<<(htmlstream& s, const Matrix3 &m); 00104 00105 #include "matrix3.inl" 00106 00107 } 00108 00109 #endif // !SHEEP_MATH_MATRIX3_H
1.3.6