Samples/Math/MathUtilities.py

Samples/Math/MathUtilities.py
1 # Copyright 2009 Autodesk, Inc. All rights reserved.
2 # Use of this software is subject to the terms of the Autodesk license agreement
3 # provided at the time of installation or download, or which otherwise accompanies
4 # this software in either electronic or hard copy form.
5 #
6 # Script description:
7 # Show the global functions for math
8 #
9 # Topic: Matrix, T,R,S to Matrix, Matrix to T,R,S, Local/Global conversions, Vector operations,
10 # Quaternion operations, Vertex operations, Rotation utilities, Miscellaneous utilities
11 #
12 
13 from pyfbsdk import *
14 
15 lMatrix = FBMatrix()
16 lMatrixResult = FBMatrix()
17 
18 lVertex = FBVertex()
19 lVertexResult = FBVertex()
20 
21 lVector4d = FBVector4d()
22 lVector4dResult = FBVector4d()
23 
24 lVector3d = FBVector3d()
25 lVector3dResult = FBVector3d()
26 
27 lSVector = FBSVector()
28 lSVectorResult = FBSVector()
29 
30 lDouble = 1.0
31 lDoubleResult = 1.0
32 
33 # Matrix
34 FBMatrixInverse(lMatrixResult,lMatrix)
35 FBMatrixInverse(lMatrixResult,lMatrix)
36 FBMatrixTranspose(lMatrixResult,lMatrix)
37 
38 FBMatrixMult(lMatrixResult,lMatrix,lMatrix)
39 FBVertexMatrixMult(lVertexResult, lMatrix, lVertex)
40 FBVectorMatrixMult(lVector4d, lMatrix, lVector4d)
41 
42 # T,R,S to Matrix
43 FBTranslationToMatrix(lMatrixResult, lVector4d)
44 FBRotationToMatrix(lMatrixResult, lVector3d, FBRotationOrder.kFBXYZ)
45 FBScalingToMatrix(lMatrixResult, lSVector)
46 FBTRSToMatrix(lMatrixResult, lVector4d, lVector3d, lSVector)
47 
48 # Matrix to T,R,S
49 FBMatrixToTranslation(lVector4d, lMatrix)
50 FBMatrixToRotation(lVector3d, lMatrix, FBRotationOrder.kFBXYZ)
51 FBMatrixToScaling(lSVector, lMatrix)
52 FBMatrixToTRS(lVector4d, lVector3d, lSVector, lMatrix)
53 
54 # Quaternion
55 FBRotationToQuaternion(lVector4d, lVector3d, FBRotationOrder.kFBXYZ)
56 FBQuaternionToRotation(lVector3d, lVector4d, FBRotationOrder.kFBXYZ)
57 
58 # Local/Global conversions
59 FBGetLocalMatrix(lMatrixResult, lMatrix, lMatrix)
60 FBGetGlobalMatrix(lMatrixResult, lMatrix, lMatrix)
61 FBMatrixOrthogonalize(lMatrix)
62 
63 # Vector operations
64 FBAdd(lVector4dResult, lVector4d, lVector4d)
65 FBSub(lVector4dResult, lVector4d, lVector4d)
66 FBMult(lVector4dResult, lVector4d, lDouble)
67 FBMult(lVector4dResult, lVector4d, lVector4d)
68 FBMult(lMatrixResult, lMatrix, lSVector)
69 lDoubleResult = FBDot(lVector4d, lVector4d)
70 lDoubleResult = FBLength(lVector4d)
71 
72 # Quaternion operations
73 FBQAdd(lVector4dResult, lVector4d, lVector4d)
74 FBQSub(lVector4dResult, lVector4d, lVector4d)
75 FBQMult(lVector4dResult, lVector4d, lDouble)
76 FBQMult(lVector4dResult, lVector4d, lVector4d)
77 lDoubleResult = FBQDot(lVector4d, lVector4d)
78 lDoubleResult = FBQLength(lVector4d)
79 
80 # Vertex operations
81 lDoubleResult = FBLength(lVertex)
82 
83 # Rotation utilities
84 FBInterpolateRotation(lVector3dResult, lVector3d, lVector3d, lDouble)
85 FBInterpolateRotation(lVector4dResult, lVector4d, lVector4d, lDouble)
86 FBGetContinuousRotation(lVector3dResult, lVector3d, lVector3d)
87 
88 # Miscellaneous utilities
89 FBClamp(lDoubleResult, lDouble, lDouble)
90 
91 print lMatrix
92 print lMatrixResult
93 print lVertex
94 print lVertexResult
95 print lVector4d
96 print lVector4dResult
97 print lVector3d
98 print lVector3dResult
99 print lSVector
100 print lSVectorResult
101 print lDouble
102 print lSVectorResult