Open Reality Reference Guide
 
Loading...
Searching...
No Matches
fbmath.h
Go to the documentation of this file.
1#ifndef __FBMATH_H__
2#define __FBMATH_H__
3/**************************************************************************
4 Copyright (c) 1994 - 2009 Autodesk, Inc. and/or its licensors.
5 All Rights Reserved.
6
7 The coded instructions, statements, computer programs, and/or related
8 material (collectively the "Data") in these files contain unpublished
9 information proprietary to Autodesk, Inc. and/or its licensors, which is
10 protected by Canada and United States of America federal copyright law
11 and by international treaties.
12
13 The Data may not be disclosed or distributed to third parties, in whole
14 or in part, without the prior written consent of Autodesk, Inc.
15 ("Autodesk").
16
17 THE DATA IS PROVIDED "AS IS" AND WITHOUT WARRANTY.
18 ALL WARRANTIES ARE EXPRESSLY EXCLUDED AND DISCLAIMED. AUTODESK MAKES NO
19 WARRANTY OF ANY KIND WITH RESPECT TO THE DATA, EXPRESS, IMPLIED OR
20 ARISING BY CUSTOM OR TRADE USAGE, AND DISCLAIMS ANY IMPLIED WARRANTIES
21 OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR
22 PURPOSE OR USE. WITHOUT LIMITING THE FOREGOING, AUTODESK DOES NOT
23 WARRANT THAT THE OPERATION OF THE DATA WILL BE UNINTERRUPTED OR ERROR
24 FREE.
25
26 IN NO EVENT SHALL AUTODESK, ITS AFFILIATES, PARENT COMPANIES, LICENSORS
27 OR SUPPLIERS ("AUTODESK GROUP") BE LIABLE FOR ANY LOSSES, DAMAGES OR
28 EXPENSES OF ANY KIND (INCLUDING WITHOUT LIMITATION PUNITIVE OR MULTIPLE
29 DAMAGES OR OTHER SPECIAL, DIRECT, INDIRECT, EXEMPLARY, INCIDENTAL, LOSS
30 OF PROFITS, REVENUE OR DATA, COST OF COVER OR CONSEQUENTIAL LOSSES OR
31 DAMAGES OF ANY KIND), HOWEVER CAUSED, AND REGARDLESS OF THE THEORY OF
32 LIABILITY, WHETHER DERIVED FROM CONTRACT, TORT (INCLUDING, BUT NOT
33 LIMITED TO, NEGLIGENCE), OR OTHERWISE, ARISING OUT OF OR RELATING TO THE
34 DATA OR ITS USE OR ANY OTHER PERFORMANCE, WHETHER OR NOT AUTODESK HAS
35 BEEN ADVISED OF THE POSSIBILITY OF SUCH LOSS OR DAMAGE.
36
37**************************************************************************/
38
43#include <kaydaradef.h>
44#ifndef FBSDK_DLL
48 #define FBSDK_DLL K_DLLIMPORT
49#endif
50
51#include <fbsdk/fbtypes.h>
52
53#ifdef FBSDKUseNamespace
54 namespace FBSDKNamespace {
55#endif
56
57const double FBMat2EulerDegenerateForPrecision10 = 16.0e-10; //Default precision since Mobu 2016 for converting rotation matrix to Euler vector
58
67};
68
69FB_DEFINE_ENUM( FBSDK_DLL, RotationOrder );
70
72// Matrix
74
78FBSDK_DLL void FBMatrixInverse (FBMatrix &pMatrix, const FBMatrix &pSrc);
79
84FBSDK_DLL void FBMatrixTranspose (FBMatrix &pMatrix, const FBMatrix &pSrc);
85
91FBSDK_DLL void FBMatrixMult (FBMatrix &pMatrix, const FBMatrix &pA, const FBMatrix &pB);
92
98FBSDK_DLL void FBVertexMatrixMult( FBVertex &pOutVertex, const FBMatrix &pMatrix, const FBVertex &pVertex );
99
105FBSDK_DLL void FBVectorMatrixMult( FBVector4d &pOutVector, const FBMatrix &pMatrix, const FBVector4d &pVector );
106
108// T,R/Q,S to Matrix
110// N.B. Rotation is in EulerXYZ
115FBSDK_DLL void FBTranslationToMatrix (FBMatrix &pMatrix, const FBTVector& pVector);
116
122FBSDK_DLL void FBRotationToMatrix (FBMatrix &pMatrix, const FBRVector& pVector, FBRotationOrder pRotationOrder = kFBXYZ);
123
128FBSDK_DLL void FBScalingToMatrix (FBMatrix &pMatrix, const FBSVector& pVector);
129
137FBSDK_DLL void FBTRSToMatrix (FBMatrix &pMatrix, const FBTVector& pTVector, const FBRVector& pRVector, const FBSVector& pSVector);
138
145FBSDK_DLL void FBTQSToMatrix (FBMatrix &pMatrix, const FBTVector& pTVector, const FBQuaternion& pQuaternion, const FBSVector& pSVector);
146
148// Matrix to T,R/Q,S
150// Rotation is in EulerXYZ
155FBSDK_DLL void FBMatrixToTranslation (FBTVector &pVector, const FBMatrix& pMatrix);
156
162FBSDK_DLL void FBMatrixToRotation (FBRVector &pVector, const FBMatrix& pMatrix, FBRotationOrder pRotationOrder = kFBXYZ);
163
168FBSDK_DLL void FBMatrixToScaling (FBSVector &pVector, const FBMatrix& pMatrix);
169
177FBSDK_DLL void FBMatrixToTRS (FBTVector &pTVector, FBRVector &pRVector, FBSVector &pSVector, const FBMatrix& pMatrix);
178
185FBSDK_DLL void FBMatrixToTQS (FBTVector &pTVector, FBQuaternion &pQuaternion, FBSVector &pSVector, const FBMatrix& pMatrix);
186
188// Quaternion
190
195FBSDK_DLL void FBRotationToQuaternion (FBQuaternion &pQuaternion, const FBRVector& pVector, FBRotationOrder pRotationOrder = kFBXYZ);
196
203FBSDK_DLL void FBQuaternionToRotation (FBRVector &pVector, const FBQuaternion& pQuaternion, FBRotationOrder pRotationOrder = kFBXYZ);
204
210FBSDK_DLL void FBMatrixToQuaternion(FBQuaternion &pQuaternion, const FBMatrix& pMatrix);
211
216FBSDK_DLL void FBQuaternionToMatrix(FBMatrix &pMatrix, const FBQuaternion& pQuaternion);
217
218
220// Local/Global conversions
222
229FBSDK_DLL void FBGetLocalMatrix (FBMatrix &pMatrix, const FBMatrix& pMatrixParent, const FBMatrix& pMatrixChild);
230
238FBSDK_DLL void FBGetGlobalMatrix (FBMatrix &pMatrix, const FBMatrix& pMatrixParent, const FBMatrix& pLocalMatrix);
239
240
246
248// Vector operations
250
255FBSDK_DLL void FBAdd (FBTVector &pResult, const FBTVector &pV1, const FBTVector &pV2);
256
262FBSDK_DLL void FBSub (FBTVector &pResult, const FBTVector &pV1, const FBTVector &pV2);
263
269FBSDK_DLL void FBMult (FBTVector &pResult, const FBTVector &pV1, double pV2);
270
276FBSDK_DLL void FBMult (FBTVector &pResult, const FBTVector &pV1, const FBTVector &pV2);
277
283FBSDK_DLL void FBMult (FBMatrix &pResult, const FBMatrix &pM, const FBSVector &pV);
284
290FBSDK_DLL double FBDot (const FBTVector &pV1, const FBTVector &pV2);
291
296FBSDK_DLL double FBLength (const FBTVector &pV);
297
299// Quaternion operations
301
306FBSDK_DLL void FBQAdd (FBQuaternion &pResult, const FBQuaternion &pQ1, const FBQuaternion &pQ2);
307
313FBSDK_DLL void FBQSub (FBQuaternion &pResult, const FBQuaternion &pQ1, const FBQuaternion &pQ2);
314
320FBSDK_DLL void FBQMult (FBQuaternion &pResult, const FBQuaternion &pQ1, double pQ2);
321
327FBSDK_DLL void FBQMult (FBQuaternion &pResult, const FBQuaternion &pQ1, const FBQuaternion &pQ2);
328
334FBSDK_DLL double FBQDot (const FBQuaternion &pQ1, const FBQuaternion &pQ2);
335
341
343// Vertex operations
345
349FBSDK_DLL double FBLength (const FBVertex &pV);
350
352// Rotation utilities
354
360FBSDK_DLL void FBInterpolateRotation( FBRVector &pROut, const FBRVector &pR0, const FBRVector &pR1, double pU );
361
368FBSDK_DLL void FBInterpolateRotation( FBQuaternion &pQOut, const FBQuaternion &pQ0, const FBQuaternion &pQ1, double pU );
369
376FBSDK_DLL void FBGetContinuousRotation ( FBRVector &pROut, const FBRVector &pR0, const FBRVector &pR1 );
377
379// Miscellaneous utilities
381
387FBSDK_DLL double FBClamp (double pV, double pL, double pH);
388
392FBSDK_DLL void FBBigEndianToNative (unsigned short &pV);
393
397FBSDK_DLL void FBLittleEndianToNative (unsigned short &pV);
398
406FBSDK_DLL void FBMatrixToRotationWithPrecision (FBRVector &pVector, const FBMatrix& pMatrix, FBRotationOrder pRotationOrder, double pPrecision = FBMat2EulerDegenerateForPrecision10);
407
415FBSDK_DLL void FBQuaternionToRotationWithPrecision (FBRVector &pVector, const FBQuaternion& pQuaternion, FBRotationOrder pRotationOrder, double pPrecision = FBMat2EulerDegenerateForPrecision10);
416
417#ifdef FBSDKUseNamespace
418 }
419#endif
420#endif
Four x Four (double) Matrix.
Definition fbtypes.h:290
Three dimensional scaling vector.
Definition fbtypes.h:566
#define FBSDK_DLL
Be sure that FBSDK_DLL is defined only once...
K_DLLIMPORT void FBRotationToQuaternion(FBQuaternion &pQuaternion, const FBRVector &pVector, FBRotationOrder pRotationOrder=kFBXYZ)
Get a quaternion from a rotation vector.
K_DLLIMPORT void FBAdd(FBTVector &pResult, const FBTVector &pV1, const FBTVector &pV2)
Add two vectors together (pResult = pV1 + pV2)
K_DLLIMPORT void FBMatrixToTranslation(FBTVector &pVector, const FBMatrix &pMatrix)
Obtain translation vector from a matrix.
K_DLLIMPORT void FBBigEndianToNative(unsigned short &pV)
Change from big endian to native format.
K_DLLIMPORT void FBQuaternionToMatrix(FBMatrix &pMatrix, const FBQuaternion &pQuaternion)
Get a rotation matrix from a quaternion vector.
K_DLLIMPORT void FBMatrixToTRS(FBTVector &pTVector, FBRVector &pRVector, FBSVector &pSVector, const FBMatrix &pMatrix)
Obtain translation, rotation, and scaling vectors from a matrix.
K_DLLIMPORT double FBClamp(double pV, double pL, double pH)
Clamp value.
K_DLLIMPORT void FBInterpolateRotation(FBRVector &pROut, const FBRVector &pR0, const FBRVector &pR1, double pU)
Interpolate a rotation in Euler space.
K_DLLIMPORT void FBTranslationToMatrix(FBMatrix &pMatrix, const FBTVector &pVector)
Convert a translation vector to a matrix.
K_DLLIMPORT void FBMatrixToQuaternion(FBQuaternion &pQuaternion, const FBMatrix &pMatrix)
Get a quaternion from a matrix (potential ).
K_DLLIMPORT void FBMatrixTranspose(FBMatrix &pMatrix, const FBMatrix &pSrc)
Transpose a matrix.
K_DLLIMPORT void FBGetLocalMatrix(FBMatrix &pMatrix, const FBMatrix &pMatrixParent, const FBMatrix &pMatrixChild)
Get local matrix from parent and child matrices.
K_DLLIMPORT double FBQDot(const FBQuaternion &pQ1, const FBQuaternion &pQ2)
Calculate the dot product of two quaternions.
K_DLLIMPORT void FBQSub(FBQuaternion &pResult, const FBQuaternion &pQ1, const FBQuaternion &pQ2)
Subtract pQ2 from pQ1 (pResult = pQ1 - pQ2)
K_DLLIMPORT void FBMatrixToRotationWithPrecision(FBRVector &pVector, const FBMatrix &pMatrix, FBRotationOrder pRotationOrder, double pPrecision=FBMat2EulerDegenerateForPrecision10)
Obtain rotation vector from a matrix.
K_DLLIMPORT void FBQuaternionToRotationWithPrecision(FBRVector &pVector, const FBQuaternion &pQuaternion, FBRotationOrder pRotationOrder, double pPrecision=FBMat2EulerDegenerateForPrecision10)
Get a rotation vector from a quaternion vector.
K_DLLIMPORT void FBGetContinuousRotation(FBRVector &pROut, const FBRVector &pR0, const FBRVector &pR1)
Get a continuous rotation in Euler space.
K_DLLIMPORT void FBScalingToMatrix(FBMatrix &pMatrix, const FBSVector &pVector)
Convert a scaling vector to a matrix.
K_DLLIMPORT void FBTRSToMatrix(FBMatrix &pMatrix, const FBTVector &pTVector, const FBRVector &pRVector, const FBSVector &pSVector)
Convert translation, rotation, and scaling vectors to a matrix.
K_DLLIMPORT void FBVertexMatrixMult(FBVertex &pOutVertex, const FBMatrix &pMatrix, const FBVertex &pVertex)
Multiply a vertex by a matrix.
K_DLLIMPORT void FBMatrixToTQS(FBTVector &pTVector, FBQuaternion &pQuaternion, FBSVector &pSVector, const FBMatrix &pMatrix)
Obtain translation vector, rotation quaternion, and scaling vector from a matrix.
K_DLLIMPORT void FBTQSToMatrix(FBMatrix &pMatrix, const FBTVector &pTVector, const FBQuaternion &pQuaternion, const FBSVector &pSVector)
Convert translation vector, rotation quaternion, and scaling vector to a matrix.
K_DLLIMPORT void FBMatrixToRotation(FBRVector &pVector, const FBMatrix &pMatrix, FBRotationOrder pRotationOrder=kFBXYZ)
Obtain rotation vector from a matrix.
K_DLLIMPORT double FBDot(const FBTVector &pV1, const FBTVector &pV2)
Calculate the dot product of two vectors.
K_DLLIMPORT void FBMatrixInverse(FBMatrix &pMatrix, const FBMatrix &pSrc)
Invert a matrix.
K_DLLIMPORT void FBMult(FBTVector &pResult, const FBTVector &pV1, double pV2)
Multiply pV2 from pV1 (pResult = pV1 * pV2)
K_DLLIMPORT void FBLittleEndianToNative(unsigned short &pV)
Change from little endian to native format.
K_DLLIMPORT void FBMatrixToScaling(FBSVector &pVector, const FBMatrix &pMatrix)
Obtain scaling vector from a matrix.
K_DLLIMPORT void FBQuaternionToRotation(FBRVector &pVector, const FBQuaternion &pQuaternion, FBRotationOrder pRotationOrder=kFBXYZ)
Get a rotation vector from a quaternion vector.
K_DLLIMPORT void FBSub(FBTVector &pResult, const FBTVector &pV1, const FBTVector &pV2)
Subtract pV2 from pV1 (pResult = pV1 - pV2)
K_DLLIMPORT void FBGetGlobalMatrix(FBMatrix &pMatrix, const FBMatrix &pMatrixParent, const FBMatrix &pLocalMatrix)
Get global matrix from parent and child matrices.
K_DLLIMPORT void FBMatrixMult(FBMatrix &pMatrix, const FBMatrix &pA, const FBMatrix &pB)
Multiply two matrices.
K_DLLIMPORT double FBLength(const FBTVector &pV)
Get the length of a vector.
K_DLLIMPORT void FBQAdd(FBQuaternion &pResult, const FBQuaternion &pQ1, const FBQuaternion &pQ2)
Add two quaternions together (pResult = pQ1 + pQ2)
K_DLLIMPORT void FBQMult(FBQuaternion &pResult, const FBQuaternion &pQ1, double pQ2)
Multiply pQ2 from pQ1 (pResult = pQ1 * pQ2)
K_DLLIMPORT void FBVectorMatrixMult(FBVector4d &pOutVector, const FBMatrix &pMatrix, const FBVector4d &pVector)
Multiply a vector by a matrix.
K_DLLIMPORT double FBQLength(const FBQuaternion &pQ)
Get the length of a quaternion.
FBRotationOrder
Specify the Euler rotation order.
Definition fbmath.h:60
@ kFBYZX
YZX
Definition fbmath.h:64
@ kFBZYX
ZYX.
Definition fbmath.h:66
@ kFBZXY
ZXY
Definition fbmath.h:65
@ kFBYXZ
YXZ.
Definition fbmath.h:63
@ kFBXYZ
XYZ
Definition fbmath.h:61
@ kFBXZY
XZY.
Definition fbmath.h:62
K_DLLIMPORT void FBMatrixOrthogonalize(FBMatrix &pMatrix)
Make sure that rotation vectors are orthogonal and normalized (fast way for removing scaling from mat...
K_DLLIMPORT void FBRotationToMatrix(FBMatrix &pMatrix, const FBRVector &pVector, FBRotationOrder pRotationOrder=kFBXYZ)
Convert a rotation vector to a matrix.
#define FB_DEFINE_ENUM(DllTag, Type)
Define an enum and give it the ability to be a property.
Types & macros.
class K_DLLIMPORT FBVector4< float > FBVertex
Vertex.
Definition fbtypes.h:597
class K_DLLIMPORT FBVector4< double > FBQuaternion
Quaternion.
Definition fbtypes.h:593
class K_DLLIMPORT FBVector4< double > FBVector4d
4D vector
Definition fbtypes.h:441