00001 /* 00002 ----------------------------------------------------------------------------- 00003 This source file is part of OGRE 00004 (Object-oriented Graphics Rendering Engine) 00005 For the latest info, see http://www.ogre3d.org/ 00006 00007 Copyright © 2000-2002 The OGRE Team 00008 Also see acknowledgements in Readme.html 00009 00010 This program is free software; you can redistribute it and/or modify it under 00011 the terms of the GNU Lesser General Public License as published by the Free Software 00012 Foundation; either version 2 of the License, or (at your option) any later 00013 version. 00014 00015 This program is distributed in the hope that it will be useful, but WITHOUT 00016 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00017 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 00018 00019 You should have received a copy of the GNU Lesser General Public License along with 00020 this program; if not, write to the Free Software Foundation, Inc., 59 Temple 00021 Place - Suite 330, Boston, MA 02111-1307, USA, or go to 00022 http://www.gnu.org/copyleft/lesser.txt. 00023 ----------------------------------------------------------------------------- 00024 */ 00025 #include "OgreStableHeaders.h" 00026 #include "OgreMatrix4.h" 00027 00028 #include "OgreVector3.h" 00029 #include "OgreMatrix3.h" 00030 00031 namespace Ogre 00032 { 00033 00034 const Matrix4 Matrix4::ZERO( 00035 0, 0, 0, 0, 00036 0, 0, 0, 0, 00037 0, 0, 0, 0, 00038 0, 0, 0, 0 ); 00039 00040 const Matrix4 Matrix4::IDENTITY( 00041 1, 0, 0, 0, 00042 0, 1, 0, 0, 00043 0, 0, 1, 0, 00044 0, 0, 0, 1 ); 00045 00046 const Matrix4 Matrix4::CLIPSPACE2DTOIMAGESPACE( 00047 0.5, 0, 0, 0.5, 00048 0, -0.5, 0, 0.5, 00049 0, 0, 1, 0, 00050 0, 0, 0, 1); 00051 00052 inline Real 00053 MINOR(const Matrix4& m, const size_t r0, const size_t r1, const size_t r2, 00054 const size_t c0, const size_t c1, const size_t c2) 00055 { 00056 return m[r0][c0] * (m[r1][c1] * m[r2][c2] - m[r2][c1] * m[r1][c2]) - 00057 m[r0][c1] * (m[r1][c0] * m[r2][c2] - m[r2][c0] * m[r1][c2]) + 00058 m[r0][c2] * (m[r1][c0] * m[r2][c1] - m[r2][c0] * m[r1][c1]); 00059 } 00060 00061 00062 Matrix4 Matrix4::adjoint() const 00063 { 00064 return Matrix4( MINOR(*this, 1, 2, 3, 1, 2, 3), 00065 -MINOR(*this, 0, 2, 3, 1, 2, 3), 00066 MINOR(*this, 0, 1, 3, 1, 2, 3), 00067 -MINOR(*this, 0, 1, 2, 1, 2, 3), 00068 00069 -MINOR(*this, 1, 2, 3, 0, 2, 3), 00070 MINOR(*this, 0, 2, 3, 0, 2, 3), 00071 -MINOR(*this, 0, 1, 3, 0, 2, 3), 00072 MINOR(*this, 0, 1, 2, 0, 2, 3), 00073 00074 MINOR(*this, 1, 2, 3, 0, 1, 3), 00075 -MINOR(*this, 0, 2, 3, 0, 1, 3), 00076 MINOR(*this, 0, 1, 3, 0, 1, 3), 00077 -MINOR(*this, 0, 1, 2, 0, 1, 3), 00078 00079 -MINOR(*this, 1, 2, 3, 0, 1, 2), 00080 MINOR(*this, 0, 2, 3, 0, 1, 2), 00081 -MINOR(*this, 0, 1, 3, 0, 1, 2), 00082 MINOR(*this, 0, 1, 2, 0, 1, 2)); 00083 } 00084 00085 00086 Real Matrix4::determinant() const 00087 { 00088 return m[0][0] * MINOR(*this, 1, 2, 3, 1, 2, 3) - 00089 m[0][1] * MINOR(*this, 1, 2, 3, 0, 2, 3) + 00090 m[0][2] * MINOR(*this, 1, 2, 3, 0, 1, 3) - 00091 m[0][3] * MINOR(*this, 1, 2, 3, 0, 1, 2); 00092 } 00093 00094 Matrix4 Matrix4::inverse() const 00095 { 00096 return adjoint() * (1.0f / determinant()); 00097 } 00098 00099 }
Copyright © 2002-2003 by The OGRE Team
Last modified Sun Nov 28 19:48:33 2004