1 | /*
|
---|
2 | -----------------------------------------------------------------------------
|
---|
3 | This source file is part of OGRE
|
---|
4 | (Object-oriented Graphics Rendering Engine)
|
---|
5 | For the latest info, see http://www.ogre3d.org/
|
---|
6 |
|
---|
7 | Copyright (c) 2000-2005 The OGRE Team
|
---|
8 | Also see acknowledgements in Readme.html
|
---|
9 |
|
---|
10 | This program is free software; you can redistribute it and/or modify it under
|
---|
11 | the terms of the GNU Lesser General Public License as published by the Free Software
|
---|
12 | Foundation; either version 2 of the License, or (at your option) any later
|
---|
13 | version.
|
---|
14 |
|
---|
15 | This program is distributed in the hope that it will be useful, but WITHOUT
|
---|
16 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
---|
17 | FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
---|
18 |
|
---|
19 | You should have received a copy of the GNU Lesser General Public License along with
|
---|
20 | this program; if not, write to the Free Software Foundation, Inc., 59 Temple
|
---|
21 | Place - Suite 330, Boston, MA 02111-1307, USA, or go to
|
---|
22 | http://www.gnu.org/copyleft/lesser.txt.
|
---|
23 | -----------------------------------------------------------------------------
|
---|
24 | */
|
---|
25 | #include "OgreStableHeaders.h"
|
---|
26 | #include "OgreMatrix4.h"
|
---|
27 |
|
---|
28 | #include "OgreVector3.h"
|
---|
29 | #include "OgreMatrix3.h"
|
---|
30 |
|
---|
31 | namespace Ogre
|
---|
32 | {
|
---|
33 |
|
---|
34 | const Matrix4 Matrix4::ZERO(
|
---|
35 | 0, 0, 0, 0,
|
---|
36 | 0, 0, 0, 0,
|
---|
37 | 0, 0, 0, 0,
|
---|
38 | 0, 0, 0, 0 );
|
---|
39 |
|
---|
40 | const Matrix4 Matrix4::IDENTITY(
|
---|
41 | 1, 0, 0, 0,
|
---|
42 | 0, 1, 0, 0,
|
---|
43 | 0, 0, 1, 0,
|
---|
44 | 0, 0, 0, 1 );
|
---|
45 |
|
---|
46 | const Matrix4 Matrix4::CLIPSPACE2DTOIMAGESPACE(
|
---|
47 | 0.5, 0, 0, 0.5,
|
---|
48 | 0, -0.5, 0, 0.5,
|
---|
49 | 0, 0, 1, 0,
|
---|
50 | 0, 0, 0, 1);
|
---|
51 |
|
---|
52 | inline Real
|
---|
53 | MINOR(const Matrix4& m, const size_t r0, const size_t r1, const size_t r2,
|
---|
54 | const size_t c0, const size_t c1, const size_t c2)
|
---|
55 | {
|
---|
56 | return m[r0][c0] * (m[r1][c1] * m[r2][c2] - m[r2][c1] * m[r1][c2]) -
|
---|
57 | m[r0][c1] * (m[r1][c0] * m[r2][c2] - m[r2][c0] * m[r1][c2]) +
|
---|
58 | m[r0][c2] * (m[r1][c0] * m[r2][c1] - m[r2][c0] * m[r1][c1]);
|
---|
59 | }
|
---|
60 |
|
---|
61 |
|
---|
62 | Matrix4 Matrix4::adjoint() const
|
---|
63 | {
|
---|
64 | return Matrix4( MINOR(*this, 1, 2, 3, 1, 2, 3),
|
---|
65 | -MINOR(*this, 0, 2, 3, 1, 2, 3),
|
---|
66 | MINOR(*this, 0, 1, 3, 1, 2, 3),
|
---|
67 | -MINOR(*this, 0, 1, 2, 1, 2, 3),
|
---|
68 |
|
---|
69 | -MINOR(*this, 1, 2, 3, 0, 2, 3),
|
---|
70 | MINOR(*this, 0, 2, 3, 0, 2, 3),
|
---|
71 | -MINOR(*this, 0, 1, 3, 0, 2, 3),
|
---|
72 | MINOR(*this, 0, 1, 2, 0, 2, 3),
|
---|
73 |
|
---|
74 | MINOR(*this, 1, 2, 3, 0, 1, 3),
|
---|
75 | -MINOR(*this, 0, 2, 3, 0, 1, 3),
|
---|
76 | MINOR(*this, 0, 1, 3, 0, 1, 3),
|
---|
77 | -MINOR(*this, 0, 1, 2, 0, 1, 3),
|
---|
78 |
|
---|
79 | -MINOR(*this, 1, 2, 3, 0, 1, 2),
|
---|
80 | MINOR(*this, 0, 2, 3, 0, 1, 2),
|
---|
81 | -MINOR(*this, 0, 1, 3, 0, 1, 2),
|
---|
82 | MINOR(*this, 0, 1, 2, 0, 1, 2));
|
---|
83 | }
|
---|
84 |
|
---|
85 |
|
---|
86 | Real Matrix4::determinant() const
|
---|
87 | {
|
---|
88 | return m[0][0] * MINOR(*this, 1, 2, 3, 1, 2, 3) -
|
---|
89 | m[0][1] * MINOR(*this, 1, 2, 3, 0, 2, 3) +
|
---|
90 | m[0][2] * MINOR(*this, 1, 2, 3, 0, 1, 3) -
|
---|
91 | m[0][3] * MINOR(*this, 1, 2, 3, 0, 1, 2);
|
---|
92 | }
|
---|
93 |
|
---|
94 | Matrix4 Matrix4::inverse() const
|
---|
95 | {
|
---|
96 | return adjoint() * (1.0f / determinant());
|
---|
97 | }
|
---|
98 |
|
---|
99 | }
|
---|