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_MATRIX_H 00024 #define SHEEP_MATH_MATRIX_H 00025 00026 #include "common/misc/htmlstream.h" 00027 #include "real.h" 00028 #include "vector.h" 00029 00030 #include <cassert> 00031 00032 namespace sheep { 00033 00034 class Matrix { 00035 public: 00036 // Constructors. 00037 Matrix(int rows, int columns); 00038 Matrix(int rows, int columns, Real r); 00039 Matrix(const Matrix &m); 00040 00041 // Destructor. 00042 virtual ~Matrix(); 00043 00044 // Nth-order identity matrix. 00045 static Matrix Identity(int n); 00046 00047 // Assignment operators. 00048 Matrix &operator=(Real r); 00049 Matrix &operator=(const Matrix &m); 00050 00051 // Matrix dimensions. 00052 int GetRows() const; 00053 int GetColumns() const; 00054 bool IsSquare() const; 00055 00056 // Basic operations. 00057 Matrix operator+(const Matrix &m) const; 00058 Matrix operator-(const Matrix &m) const; 00059 Matrix operator-() const; 00060 Matrix operator*(Real r) const; 00061 Matrix operator/(Real r) const; 00062 Matrix &operator+=(const Matrix &m); 00063 Matrix &operator-=(const Matrix &m); 00064 Matrix &operator*=(Real r); 00065 Matrix &operator/=(Real r); 00066 00067 // Matrix product (no *= operator). 00068 Matrix operator*(const Matrix &m) const; 00069 00070 // Product of a matrix and a vector. 00071 Vector operator*(const Vector &v) const; 00072 00073 // Array subscripting. 00074 Real &operator[](int i); 00075 const Real &operator[](int i) const; 00076 00077 // Fortran-style subscripting (still 0-based). 00078 Real &operator()(int row, int column); 00079 const Real &operator()(int row, int column) const; 00080 00081 // Direct access to matrix coefficients. 00082 Real *GetData(); 00083 00084 // Transpose. 00085 Matrix Transpose() const; 00086 00087 // Inverse. 00088 Matrix Inverse() const; 00089 00090 // Determinant. 00091 Real Determinant() const; 00092 00093 // Trace . 00094 inline Real Trace() const; 00095 00096 private: 00097 int m_r, m_c; // rows and columns 00098 Real *m_v; // matrix values (row-major) 00099 }; 00100 00101 // Product of a real by a matrix. 00102 Matrix operator*(Real r, const Matrix &m); 00103 00104 //! Deprecated. 00105 htmlstream& operator<<(htmlstream& s, const Matrix &m); 00106 00107 #include "matrix.inl" 00108 00109 } 00110 00111 #endif // !SHEEP_MATH_MATRIX_H
1.3.6