/usr/include/OGRE/OgreMatrix3.h is in libogre-1.9-dev 1.9.0+dfsg1-7+b4.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | /*
-----------------------------------------------------------------------------
This source file is part of OGRE
(Object-oriented Graphics Rendering Engine)
For the latest info, see http://www.ogre3d.org/
Copyright (c) 2000-2013 Torus Knot Software Ltd
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/
#ifndef __Matrix3_H__
#define __Matrix3_H__
#include "OgrePrerequisites.h"
#include "OgreVector3.h"
// NB All code adapted from Wild Magic 0.2 Matrix math (free source code)
// http://www.geometrictools.com/
// NOTE. The (x,y,z) coordinate system is assumed to be right-handed.
// Coordinate axis rotation matrices are of the form
// RX = 1 0 0
// 0 cos(t) -sin(t)
// 0 sin(t) cos(t)
// where t > 0 indicates a counterclockwise rotation in the yz-plane
// RY = cos(t) 0 sin(t)
// 0 1 0
// -sin(t) 0 cos(t)
// where t > 0 indicates a counterclockwise rotation in the zx-plane
// RZ = cos(t) -sin(t) 0
// sin(t) cos(t) 0
// 0 0 1
// where t > 0 indicates a counterclockwise rotation in the xy-plane.
namespace Ogre
{
/** \addtogroup Core
* @{
*/
/** \addtogroup Math
* @{
*/
/** A 3x3 matrix which can represent rotations around axes.
@note
<b>All the code is adapted from the Wild Magic 0.2 Matrix
library (http://www.geometrictools.com/).</b>
@par
The coordinate system is assumed to be <b>right-handed</b>.
*/
class _OgreExport Matrix3
{
public:
/** Default constructor.
@note
It does <b>NOT</b> initialize the matrix for efficiency.
*/
inline Matrix3 () {}
inline explicit Matrix3 (const Real arr[3][3])
{
memcpy(m,arr,9*sizeof(Real));
}
inline Matrix3 (const Matrix3& rkMatrix)
{
memcpy(m,rkMatrix.m,9*sizeof(Real));
}
Matrix3 (Real fEntry00, Real fEntry01, Real fEntry02,
Real fEntry10, Real fEntry11, Real fEntry12,
Real fEntry20, Real fEntry21, Real fEntry22)
{
m[0][0] = fEntry00;
m[0][1] = fEntry01;
m[0][2] = fEntry02;
m[1][0] = fEntry10;
m[1][1] = fEntry11;
m[1][2] = fEntry12;
m[2][0] = fEntry20;
m[2][1] = fEntry21;
m[2][2] = fEntry22;
}
/** Exchange the contents of this matrix with another.
*/
inline void swap(Matrix3& other)
{
std::swap(m[0][0], other.m[0][0]);
std::swap(m[0][1], other.m[0][1]);
std::swap(m[0][2], other.m[0][2]);
std::swap(m[1][0], other.m[1][0]);
std::swap(m[1][1], other.m[1][1]);
std::swap(m[1][2], other.m[1][2]);
std::swap(m[2][0], other.m[2][0]);
std::swap(m[2][1], other.m[2][1]);
std::swap(m[2][2], other.m[2][2]);
}
/// Member access, allows use of construct mat[r][c]
inline const Real* operator[] (size_t iRow) const
{
return m[iRow];
}
inline Real* operator[] (size_t iRow)
{
return m[iRow];
}
/*inline operator Real* ()
{
return (Real*)m[0];
}*/
Vector3 GetColumn (size_t iCol) const;
void SetColumn(size_t iCol, const Vector3& vec);
void FromAxes(const Vector3& xAxis, const Vector3& yAxis, const Vector3& zAxis);
/// Assignment and comparison
inline Matrix3& operator= (const Matrix3& rkMatrix)
{
memcpy(m,rkMatrix.m,9*sizeof(Real));
return *this;
}
/** Tests 2 matrices for equality.
*/
bool operator== (const Matrix3& rkMatrix) const;
/** Tests 2 matrices for inequality.
*/
inline bool operator!= (const Matrix3& rkMatrix) const
{
return !operator==(rkMatrix);
}
// arithmetic operations
/** Matrix addition.
*/
Matrix3 operator+ (const Matrix3& rkMatrix) const;
/** Matrix subtraction.
*/
Matrix3 operator- (const Matrix3& rkMatrix) const;
/** Matrix concatenation using '*'.
*/
Matrix3 operator* (const Matrix3& rkMatrix) const;
Matrix3 operator- () const;
/// Matrix * vector [3x3 * 3x1 = 3x1]
Vector3 operator* (const Vector3& rkVector) const;
/// Vector * matrix [1x3 * 3x3 = 1x3]
_OgreExport friend Vector3 operator* (const Vector3& rkVector,
const Matrix3& rkMatrix);
/// Matrix * scalar
Matrix3 operator* (Real fScalar) const;
/// Scalar * matrix
_OgreExport friend Matrix3 operator* (Real fScalar, const Matrix3& rkMatrix);
// utilities
Matrix3 Transpose () const;
bool Inverse (Matrix3& rkInverse, Real fTolerance = 1e-06) const;
Matrix3 Inverse (Real fTolerance = 1e-06) const;
Real Determinant () const;
/// Singular value decomposition
void SingularValueDecomposition (Matrix3& rkL, Vector3& rkS,
Matrix3& rkR) const;
void SingularValueComposition (const Matrix3& rkL,
const Vector3& rkS, const Matrix3& rkR);
/// Gram-Schmidt orthonormalization (applied to columns of rotation matrix)
void Orthonormalize ();
/// Orthogonal Q, diagonal D, upper triangular U stored as (u01,u02,u12)
void QDUDecomposition (Matrix3& rkQ, Vector3& rkD,
Vector3& rkU) const;
Real SpectralNorm () const;
/// Note: Matrix must be orthonormal
void ToAngleAxis (Vector3& rkAxis, Radian& rfAngle) const;
inline void ToAngleAxis (Vector3& rkAxis, Degree& rfAngle) const {
Radian r;
ToAngleAxis ( rkAxis, r );
rfAngle = r;
}
void FromAngleAxis (const Vector3& rkAxis, const Radian& fRadians);
/** The matrix must be orthonormal. The decomposition is yaw*pitch*roll
where yaw is rotation about the Up vector, pitch is rotation about the
Right axis, and roll is rotation about the Direction axis. */
bool ToEulerAnglesXYZ (Radian& rfYAngle, Radian& rfPAngle,
Radian& rfRAngle) const;
bool ToEulerAnglesXZY (Radian& rfYAngle, Radian& rfPAngle,
Radian& rfRAngle) const;
bool ToEulerAnglesYXZ (Radian& rfYAngle, Radian& rfPAngle,
Radian& rfRAngle) const;
bool ToEulerAnglesYZX (Radian& rfYAngle, Radian& rfPAngle,
Radian& rfRAngle) const;
bool ToEulerAnglesZXY (Radian& rfYAngle, Radian& rfPAngle,
Radian& rfRAngle) const;
bool ToEulerAnglesZYX (Radian& rfYAngle, Radian& rfPAngle,
Radian& rfRAngle) const;
void FromEulerAnglesXYZ (const Radian& fYAngle, const Radian& fPAngle, const Radian& fRAngle);
void FromEulerAnglesXZY (const Radian& fYAngle, const Radian& fPAngle, const Radian& fRAngle);
void FromEulerAnglesYXZ (const Radian& fYAngle, const Radian& fPAngle, const Radian& fRAngle);
void FromEulerAnglesYZX (const Radian& fYAngle, const Radian& fPAngle, const Radian& fRAngle);
void FromEulerAnglesZXY (const Radian& fYAngle, const Radian& fPAngle, const Radian& fRAngle);
void FromEulerAnglesZYX (const Radian& fYAngle, const Radian& fPAngle, const Radian& fRAngle);
/// Eigensolver, matrix must be symmetric
void EigenSolveSymmetric (Real afEigenvalue[3],
Vector3 akEigenvector[3]) const;
static void TensorProduct (const Vector3& rkU, const Vector3& rkV,
Matrix3& rkProduct);
/** Determines if this matrix involves a scaling. */
inline bool hasScale() const
{
// check magnitude of column vectors (==local axes)
Real t = m[0][0] * m[0][0] + m[1][0] * m[1][0] + m[2][0] * m[2][0];
if (!Math::RealEqual(t, 1.0, (Real)1e-04))
return true;
t = m[0][1] * m[0][1] + m[1][1] * m[1][1] + m[2][1] * m[2][1];
if (!Math::RealEqual(t, 1.0, (Real)1e-04))
return true;
t = m[0][2] * m[0][2] + m[1][2] * m[1][2] + m[2][2] * m[2][2];
if (!Math::RealEqual(t, 1.0, (Real)1e-04))
return true;
return false;
}
/** Function for writing to a stream.
*/
inline _OgreExport friend std::ostream& operator <<
( std::ostream& o, const Matrix3& mat )
{
o << "Matrix3(" << mat[0][0] << ", " << mat[0][1] << ", " << mat[0][2] << ", "
<< mat[1][0] << ", " << mat[1][1] << ", " << mat[1][2] << ", "
<< mat[2][0] << ", " << mat[2][1] << ", " << mat[2][2] << ")";
return o;
}
static const Real EPSILON;
static const Matrix3 ZERO;
static const Matrix3 IDENTITY;
protected:
// support for eigensolver
void Tridiagonal (Real afDiag[3], Real afSubDiag[3]);
bool QLAlgorithm (Real afDiag[3], Real afSubDiag[3]);
// support for singular value decomposition
static const Real msSvdEpsilon;
static const unsigned int msSvdMaxIterations;
static void Bidiagonalize (Matrix3& kA, Matrix3& kL,
Matrix3& kR);
static void GolubKahanStep (Matrix3& kA, Matrix3& kL,
Matrix3& kR);
// support for spectral norm
static Real MaxCubicRoot (Real afCoeff[3]);
Real m[3][3];
// for faster access
friend class Matrix4;
};
/** @} */
/** @} */
}
#endif
|