1/****************************************************************************************
2
3 Copyright (C) 2015 Autodesk, Inc.
4 All rights reserved.
5
6 Use of this software is subject to the terms of the Autodesk license agreement
7 provided at the time of installation or download, or which otherwise accompanies
8 this software in either electronic or hard copy form.
9
10****************************************************************************************/
11
12//! \file fbxmatrix.h
13#ifndef _FBXSDK_CORE_MATH_MATRIX_H_
14#define _FBXSDK_CORE_MATH_MATRIX_H_
15
16#include <fbxsdk/fbxsdk_def.h>
17
18#include <fbxsdk/core/math/fbxvector4.h>
19
20#include <fbxsdk/fbxsdk_nsbegin.h>
21
22class FbxAMatrix;
23
24/** FBX SDK basic 4x4 double matrix class.
25 * \nosubgrouping
26 */
27class FBXSDK_DLL FbxMatrix : public FbxDouble4x4
28{
29public:
30 //! \name Constructors and Destructor
31 //@{
32 //! Constructor (initialize to an identity matrix)
33 FbxMatrix();
34
35 /** Copy constructor.
36 * \param pM Another FbxMatrix object copied to this one. */
37 FbxMatrix(const FbxMatrix& pM);
38
39 /** Copy constructor for affine matrix.
40 * \param pM Affine matrix */
41 FbxMatrix(const FbxAMatrix& pM);
42
43 /** TRS Constructor.
44 * \param pT Translation vector.
45 * \param pR Euler rotation vector.
46 * \param pS Scale vector. */
47 FbxMatrix(const FbxVector4& pT, const FbxVector4& pR, const FbxVector4& pS);
48
49 /** TQS Constructor.
50 * \param pT Translation vector.
51 * \param pQ Quaternion.
52 * \param pS Scale vector. */
53 FbxMatrix(const FbxVector4& pT, const FbxQuaternion& pQ, const FbxVector4& pS);
54
55 /** 16 double constructor.
56 * \param p00 Value at column 0 row 0.
57 * \param p10 Value at column 1 row 0.
58 * \param p20 Value at column 2 row 0.
59 * \param p30 Value at column 3 row 0.
60 * \param p01 Value at column 0 row 1.
61 * \param p11 Value at column 1 row 1.
62 * \param p21 Value at column 2 row 1.
63 * \param p31 Value at column 3 row 1.
64 * \param p02 Value at column 0 row 2.
65 * \param p12 Value at column 1 row 2.
66 * \param p22 Value at column 2 row 2.
67 * \param p32 Value at column 3 row 2.
68 * \param p03 Value at column 0 row 3.
69 * \param p13 Value at column 1 row 3.
70 * \param p23 Value at column 2 row 3.
71 * \param p33 Value at column 3 row 3. */
72 FbxMatrix( const double p00, const double p10, const double p20, const double p30,
73 const double p01, const double p11, const double p21, const double p31,
74 const double p02, const double p12, const double p22, const double p32,
75 const double p03, const double p13, const double p23, const double p33);
76
77 //! Destructor.
78 ~FbxMatrix();
79 //@}
80
81 //! \name Access
82 //@{
83 /** Retrieve matrix element.
84 * \param pY Row index.
85 * \param pX Column index.
86 * \return Value at element [ pX, pY ] of the matrix. */
87 double Get(int pY, int pX) const;
88
89 /** Extract a row vector.
90 * \param pY Row index.
91 * \return The row vector. */
92 FbxVector4 GetRow(int pY) const;
93
94 /** Extract a column vector.
95 * \param pX Column index.
96 * \return The column vector. */
97 FbxVector4 GetColumn(int pX) const;
98
99 /** Set matrix element.
100 * \param pY Row index.
101 * \param pX Column index.
102 * \param pValue New component value. */
103 void Set(int pY, int pX, double pValue);
104
105 /** Set matrix.
106 * \param pT Translation vector.
107 * \param pR Euler rotation vector.
108 * \param pS Scale vector. */
109 void SetTRS(const FbxVector4& pT, const FbxVector4& pR, const FbxVector4& pS);
110
111 /** Set matrix.
112 * \param pT Translation vector.
113 * \param pQ Quaternion.
114 * \param pS Scale vector. */
115 void SetTQS(const FbxVector4& pT, const FbxQuaternion& pQ, const FbxVector4& pS);
116
117 /** Set a matrix row.
118 * \param pY Row index.
119 * \param pRow Row vector. */
120 void SetRow(int pY, const FbxVector4& pRow);
121
122 /** Set a matrix column.
123 * \param pX Column index.
124 * \param pColumn Column vector. */
125 void SetColumn(int pX, const FbxVector4& pColumn);
126
127 /** Decompose the affine matrix into elements of translation, rotation, shearing, scaling and sign of determinant.
128 * \param pTranslation Translation element.
129 * \param pRotation Rotation element.
130 * \param pShearing Shearing element.
131 * \param pScaling Scaling element.
132 * \param pSign Sign of determinant. */
133 void GetElements(FbxVector4& pTranslation, FbxQuaternion& pRotation, FbxVector4& pShearing, FbxVector4& pScaling, double& pSign) const;
134
135 /** Decompose the affine matrix into elements of translation, rotation, shearing, scaling and sign of determinant.
136 * \param pTranslation Translation element.
137 * \param pRotation Rotation element.
138 * \param pShearing Shearing element.
139 * \param pScaling Scaling element.
140 * \param pSign Sign of determinant. */
141 void GetElements(FbxVector4& pTranslation, FbxVector4& pRotation, FbxVector4& pShearing, FbxVector4& pScaling, double& pSign) const;
142 //@}
143
144 //! \name Operators
145 //@{
146 /** Assignment operator.
147 * \param pMatrix Source matrix. */
148 FbxMatrix& operator=(const FbxMatrix& pMatrix);
149
150 /** Unary minus operator.
151 * \return A matrix where each element is multiplied by -1. */
152 FbxMatrix operator-() const;
153
154 /** Add two matrices together.
155 * \param pMatrix A matrix.
156 * \return The result of this matrix + pMatrix. */
157 FbxMatrix operator+(const FbxMatrix& pMatrix) const;
158
159 /** Subtract a matrix from another matrix.
160 * \param pMatrix A matrix.
161 * \return The result of this matrix - pMatrix. */
162 FbxMatrix operator-(const FbxMatrix& pMatrix) const;
163
164 /** Multiply two matrices.
165 * \param pMatrix A matrix.
166 * \return The result of this matrix * pMatrix. */
167 FbxMatrix operator*(const FbxMatrix& pMatrix) const;
168
169 /** Add two matrices together.
170 * \param pMatrix A matrix.
171 * \return The result of this matrix + pMatrix, replacing this matrix. */
172 FbxMatrix& operator+=(const FbxMatrix& pMatrix);
173
174 /** Subtract a matrix from another matrix.
175 * \param pMatrix A matrix.
176 * \return The result of this matrix - pMatrix, replacing this matrix. */
177 FbxMatrix& operator-=(const FbxMatrix& pMatrix);
178
179 /** Multiply two matrices.
180 * \param pMatrix A matrix.
181 * \return The result of this matrix * pMatrix, replacing this matrix. */
182 FbxMatrix& operator*=(const FbxMatrix& pMatrix);
183
184 /** Equivalence operator.
185 * \param pM The matrix to be compared against this matrix.
186 * \return \c true if the two matrices are equal (each element is within a FBXSDK_TOLERANCE tolerance), \c false otherwise. */
187 bool operator==(const FbxMatrix& pM) const;
188
189 /** Equivalence operator.
190 * \param pM The affine matrix to be compared against this matrix.
191 * \return \c true if the two matrices are equal (each element is within a FBXSDK_TOLERANCE tolerance), \c false otherwise. */
192 bool operator==(const FbxAMatrix& pM) const;
193
194 /** Non-equivalence operator.
195 * \param pM The matrix to be compared against this matrix.
196 * \return \c false if the two matrices are equal (each element is within a FBXSDK_TOLERANCE tolerance), \c true otherwise. */
197 bool operator!=(const FbxMatrix& pM) const;
198
199 /** Non-equivalence operator.
200 * \param pM The affine matrix to be compared against this matrix.
201 * \return \c false if the two matrices are equal (each element is within a FBXSDK_TOLERANCE tolerance), \c true otherwise. */
202 bool operator!=(const FbxAMatrix& pM) const;
203 //@}
204
205 //! \name Casting
206 //@{
207 //! Cast the vector in a double pointer.
208 operator double* ();
209
210 //! Cast the vector in a const double pointer.
211 operator const double* () const;
212
213 //! Define 4*4 array as a new type.
214 typedef const double(kDouble44)[4][4] ;
215
216 //! Cast the matrix in a reference to a 4*4 array.
217 inline kDouble44 & Double44() const { return *((kDouble44 *)&mData[0][0]); }
218 //@}
219
220 //! \name Math Operations
221 //@{
222 /** Calculate the matrix inverse.
223 * \return The inverse matrix. */
224 FbxMatrix Inverse() const;
225
226 /** Calculate the matrix transpose.
227 * \return This matrix transposed. */
228 FbxMatrix Transpose() const;
229
230 //! Set matrix to identity.
231 void SetIdentity();
232
233 /** Set the matrix to a "Look To" left handed.
234 * \param pEyePosition The position of the eye.
235 * \param pEyeDirection The direction of the eye.
236 * \param pUpDirection The up direction of the eye. */
237 void SetLookToLH(const FbxVector4& pEyePosition, const FbxVector4& pEyeDirection, const FbxVector4& pUpDirection);
238
239 /** Set the matrix to a "Look To" right handed.
240 * \param pEyePosition The position of the eye.
241 * \param pEyeDirection The direction of the eye.
242 * \param pUpDirection The up direction of the eye. */
243 void SetLookToRH(const FbxVector4& pEyePosition, const FbxVector4& pEyeDirection, const FbxVector4& pUpDirection);
244
245 /** Set the matrix to a "Look At" left handed.
246 * \param pEyePosition The position of the eye.
247 * \param pLookAt The look at position of the eye focus.
248 * \param pUpDirection The up direction of the eye. */
249 void SetLookAtLH(const FbxVector4& pEyePosition, const FbxVector4& pLookAt, const FbxVector4& pUpDirection);
250
251 /** Set the matrix values as a "Look At" right handed.
252 * \param pEyePosition The position of the eye.
253 * \param pLookAt The look at position of the eye focus.
254 * \param pUpDirection The up direction of the eye. */
255 void SetLookAtRH(const FbxVector4& pEyePosition, const FbxVector4& pLookAt, const FbxVector4& pUpDirection);
256
257 /** Multiply this matrix by pVector, the w component is normalized to 1.
258 * \param pVector A vector.
259 * \return The result of this matrix * pVector. */
260 FbxVector4 MultNormalize(const FbxVector4& pVector) const;
261 //@}
262
263/*****************************************************************************************************************************
264** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! **
265*****************************************************************************************************************************/
266#ifndef DOXYGEN_SHOULD_SKIP_THIS
267 int Compare(const FbxMatrix pM, const double pThreshold = FBXSDK_TOLERANCE) const;
268 int Compare(const FbxAMatrix pM, const double pThreshold = FBXSDK_TOLERANCE) const;
269
270 FbxMatrix operator*(double pValue) const;
271 FbxMatrix& operator*=(double pValue);
272
273 double LUDecomposition(FbxVector4& pVector);
274 FbxMatrix LUMult(FbxMatrix pM, const FbxVector4& pVector) const;
275 double Determinant() const;
276#endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/
277};
278
279#include <fbxsdk/fbxsdk_nsend.h>
280
281#endif /* _FBXSDK_CORE_MATH_MATRIX_H_ */
282