My Project: dynamics.mod/NewtonDynamics/packages/dMath/dMatrix.h Source File

My Project

dMatrix.h
Go to the documentation of this file.
1 /* Copyright (c) <2009> <Newton Game Dynamics>
2 *
3 * This software is provided 'as-is', without any express or implied
4 * warranty. In no event will the authors be held liable for any damages
5 * arising from the use of this software.
6 *
7 * Permission is granted to anyone to use this software for any purpose,
8 * including commercial applications, and to alter it and redistribute it
9 * freely
10 */
11
12
13 #ifndef __dMatrix__
14 #define __dMatrix__
15
16 #include "dVector.h"
17
18 class dMatrix ;
19 class dQuaternion;
20
21 // small but fully operational 4x4 matrix class
22 class dQuaternion;
23
24 dMatrix dGetZeroMatrix ();
25 dMatrix dGetIdentityMatrix();
26
27 D_MSC_VECTOR_ALIGMENT
28 class dMatrix
29 {
30 public:
31 dMatrix ();
32 dMatrix (const dFloat* const array);
33 #ifndef _NEWTON_USE_DOUBLE
34 dMatrix (const dFloat64* const array);
35 #endif
36 dMatrix (const dVector &front, const dVector &up, const dVector &right, const dVector &posit);
37 dMatrix (const dQuaternion &rotation, const dVector &position);
38 dMatrix (dFloat pitch, dFloat yaw, dFloat roll, const dVector& location);
39
40 dVector& operator[] (int i);
41 const dVector& operator[] (int i) const;
42
43 dMatrix Inverse () const;
44 dMatrix Transpose () const;
45 dMatrix Transpose4X4 () const;
46
47 dVector RotateVector (const dVector &v) const;
48 dVector UnrotateVector (const dVector &v) const;
49 dVector TransformVector (const dVector &v) const;
50 dVector UntransformVector (const dVector &v) const;
51 dVector TransformPlane (const dVector &localPlane) const;
52 dVector UntransformPlane (const dVector &globalPlane) const;
53 //dVector GetEulerAngles(dEulerAngleOrder order = m_pitchYawRoll) const;
54 void GetEulerAngles(dVector& euler1, dVector& euler2, dEulerAngleOrder order = m_pitchYawRoll) const;
55
56 bool TestIdentity() const;
57 bool TestOrthogonal() const;
58 dMatrix Inverse4x4 () const;
59 dVector RotateVector4x4 (const dVector &v) const;
60 dMatrix JacobiDiagonalization (dVector& eigenValues, const dMatrix& initialMatrix = dGetIdentityMatrix()) const;
61
62 // decompose this matrix into [this = transpose(stretchAxis) * matrix(scale) * stretchAxis * transformMatrix];
63 void PolarDecomposition (dMatrix& transformMatrix, dVector& scale, dMatrix& stretchAxis, const dMatrix& initialStretchAxis = dGetIdentityMatrix()) const;
64
65 // constructor for polar composition
66 dMatrix (const dMatrix& transformMatrix, const dVector& scale, const dMatrix& stretchAxis);
67
68 void TransformTriplex (dFloat* const dst, int dstStrideInBytes, const dFloat* const src, int srcStrideInBytes, int count) const;
69 #ifndef _NEWTON_USE_DOUBLE
70 void TransformTriplex (dFloat64* const dst, int dstStrideInBytes, const dFloat64* const src, int srcStrideInBytes, int count) const;
71 #endif
72
73 dMatrix operator* (const dMatrix & B) const;
74
75
76 bool SanityCheck() const;
77
78 dVector m_front;
79 dVector m_up;
80 dVector m_right;
81 dVector m_posit;
82 };
83
84
85
86 inline dMatrix::dMatrix ()
87 {
88 }
89
90 inline dMatrix::dMatrix (
91 const dVector &front,
92 const dVector &up,
93 const dVector &right,
94 const dVector &posit)
95 :m_front (front), m_up(up), m_right(right), m_posit(posit)
96 {
97 }
98
99 inline dMatrix::dMatrix (const dFloat* const array)
100 {
101 memcpy (&(*this)[0][0], array, sizeof (dMatrix));
102 }
103
104 #ifndef _NEWTON_USE_DOUBLE
105 inline dMatrix::dMatrix (const dFloat64* const array)
106 {
107 dFloat* const ptr = &(*this)[0][0];
108 for (int i = 0; i < 16; i ++) {
109 ptr[i] = dFloat (array[i]);
110 }
111 }
112 #endif
113
114 inline dVector& dMatrix::operator[] (int i)
115 {
116 return (&m_front)[i];
117 }
118
119 inline const dVector& dMatrix::operator[] (int i) const
120 {
121 return (&m_front)[i];
122 }
123
124
125 dMatrix dRollMatrix(dFloat ang);
126 dMatrix dYawMatrix(dFloat ang);
127 dMatrix dPitchMatrix(dFloat ang);
128 dMatrix dGrammSchmidt(const dVector& dir);
129 #endif
130
dMatrix::operator[]
dVector & operator[](int i)
Definition: dMatrix.h:114
dMatrix::UntransformPlane
dVector UntransformPlane(const dVector &globalPlane) const
Definition: dMatrix.cpp:375
dMatrix::TestIdentity
bool TestIdentity() const
Definition: dMatrix.cpp:138
dMatrix::m_right
dVector m_right
Definition: dMatrix.h:80
dMatrix::m_posit
dVector m_posit
Definition: dMatrix.h:81
dMatrix::RotateVector4x4
dVector RotateVector4x4(const dVector &v) const
Definition: dMatrix.cpp:291
dMatrix
Definition: dMatrix.h:28
dMatrix::m_front
dVector m_front
Definition: dMatrix.h:78
dMatrix::TransformTriplex
void TransformTriplex(dFloat *const dst, int dstStrideInBytes, const dFloat *const src, int srcStrideInBytes, int count) const
Definition: dMatrix.cpp:313
dMatrix::JacobiDiagonalization
dMatrix JacobiDiagonalization(dVector &eigenValues, const dMatrix &initialMatrix=dGetIdentityMatrix()) const
Definition: dMatrix.cpp:507
dMatrix::UnrotateVector
dVector UnrotateVector(const dVector &v) const
Definition: dMatrix.cpp:286
dFloat
float dFloat
Definition: dMathDefines.h:27
dEulerAngleOrder
dEulerAngleOrder
Definition: dMathDefines.h:54
dMatrix::operator*
dMatrix operator*(const dMatrix &B) const
Definition: dMatrix.cpp:343
dMatrix::m_up
dVector m_up
Definition: dMatrix.h:79
dMatrix::Inverse4x4
dMatrix Inverse4x4() const
Definition: dMatrix.cpp:406
dMatrix::dMatrix
dMatrix()
Definition: dMatrix.h:86
dMatrix::TransformVector
dVector TransformVector(const dVector &v) const
Definition: dMatrix.cpp:302
dMatrix::PolarDecomposition
void PolarDecomposition(dMatrix &transformMatrix, dVector &scale, dMatrix &stretchAxis, const dMatrix &initialStretchAxis=dGetIdentityMatrix()) const
Definition: dMatrix.cpp:661
dFloat64
double dFloat64
Definition: dMathDefines.h:32
dMatrix::GetEulerAngles
void GetEulerAngles(dVector &euler1, dVector &euler2, dEulerAngleOrder order=m_pitchYawRoll) const
Definition: dMatrix.cpp:174
dYawMatrix
dMatrix dYawMatrix(dFloat ang)
Definition: dMatrix.cpp:75
dGrammSchmidt
dMatrix dGrammSchmidt(const dVector &dir)
Definition: dMatrix.cpp:40
m_pitchYawRoll
Definition: dMathDefines.h:56
D_MSC_VECTOR_ALIGMENT
#define D_MSC_VECTOR_ALIGMENT
Definition: dMathDefines.h:52
dMatrix::RotateVector
dVector RotateVector(const dVector &v) const
Definition: dMatrix.cpp:279
dMatrix::Inverse
dMatrix Inverse() const
Definition: dMatrix.cpp:254
dQuaternion
Definition: dQuaternion.h:21
dPitchMatrix
dMatrix dPitchMatrix(dFloat ang)
Definition: dMatrix.cpp:62
dMatrix::SanityCheck
bool SanityCheck() const
Definition: dMatrix.cpp:382
dGetIdentityMatrix
dMatrix dGetIdentityMatrix()
Definition: dMatrix.cpp:22
dMatrix::Transpose4X4
dMatrix Transpose4X4() const
Definition: dMatrix.cpp:270
dVector.h
dRollMatrix
dMatrix dRollMatrix(dFloat ang)
Definition: dMatrix.cpp:87
dMatrix::TestOrthogonal
bool TestOrthogonal() const
Definition: dMatrix.cpp:154
dMatrix::UntransformVector
dVector UntransformVector(const dVector &v) const
Definition: dMatrix.cpp:307
dVector
Definition: dVector.h:54
dMatrix::Transpose
dMatrix Transpose() const
Definition: dMatrix.cpp:262
dGetZeroMatrix
dMatrix dGetZeroMatrix()
Definition: dMatrix.cpp:30
dMatrix::TransformPlane
dVector TransformPlane(const dVector &localPlane) const
Definition: dMatrix.cpp:368