FBX C++ API Reference
fbxmath.h
Go to the documentation of this file.
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 
13 #ifndef _FBXSDK_CORE_MATH_H_
14 #define _FBXSDK_CORE_MATH_H_
15 
16 #include <fbxsdk/fbxsdk_def.h>
17 
22 
23 #include <fbxsdk/fbxsdk_nsbegin.h>
24 
25 //---------------------------------------------------------------------------------------
26 //Common Constants
27 #define FBXSDK_PI 3.1415926535897932384626433832795028841971693993751
28 #define FBXSDK_PI_DIV_2 1.5707963267948966192313216916397514420985846996875
29 #define FBXSDK_PI_DIV_180 0.017453292519943295769236907684886127134428718885417
30 #define FBXSDK_180_DIV_PI 57.295779513082320876798154814105170332405472466565
31 #define FBXSDK_1_DIV_LN2 1.4426950408889634073599246810018921374266459541530
32 
33 //---------------------------------------------------------------------------------------
34 //Unit Convertion Ratio
35 #define FBXSDK_DEG_TO_RAD FBXSDK_PI_DIV_180
36 #define FBXSDK_RAD_TO_DEG FBXSDK_180_DIV_PI
37 #define FBXSDK_IN_TO_CM 2.54
38 #define FBXSDK_MM_TO_CM 0.1
39 #define FBXSDK_CM_TO_IN 0.393700787
40 #define FBXSDK_IN_TO_MM 25.4
41 #define FBXSDK_MM_TO_IN 0.0393700787
42 #define FBXSDK_FT_TO_M 0.3048
43 #define FBXSDK_M_TO_FT 3.2808399
44 #define FBXSDK_YD_TO_FT 3
45 #define FBXSDK_FT_TO_YD 0.333333333
46 #define FBXSDK_KM_TO_MILE 0.621371192
47 #define FBXSDK_MILE_TO_KM 1.609344
48 #define FBXSDK_YD_TO_M 0.9144
49 #define FBXSDK_M_TO_YD 1.0936133
50 
51 //---------------------------------------------------------------------------------------
52 //Euler Definition
53 #define FBXSDK_EULER_DEGENERATE FbxEuler::DegenerateThreshold()
54 
56 {
57 public:
58  enum EAxis {eAxisX=0, eAxisY=1, eAxisZ=2};
59 
60  enum EOrder
61  {
68  eOrderSphericXYZ
69  };
70 
71  static bool IsParityOdd(EOrder pOrder);
72  static bool IsRepeat(EOrder pOrder);
73 
74  static const int AxisTableSize;
75  static const int AxisTable[][3];
76 
77  // Used to detect Euler gimbal locks when extracting the rotation vector from
78  // the FbxAMatrix. This value should only be changed when the user system stores
79  // single floating point values into the FbxAMatrix with a very low precision.
80  // In this case, the default threshold value would be too small for a proper detection
81  // and the extracted values can quickly become off target by a huge amount.
82  static void SetDegenerateThreshold(double pThreshold=16.0*FBXSDK_FLOAT_EPSILON);
83  static inline double DegenerateThreshold() { return FbxEuler::mDegenerateThreshold; }
84 
85 private:
86  static double mDegenerateThreshold;
87 };
88 
94 #define EFbxRotationOrder FbxEuler::EOrder
95 #define eEulerXYZ FbxEuler::eOrderXYZ
96 #define eEulerXZY FbxEuler::eOrderXZY
97 #define eEulerYZX FbxEuler::eOrderYZX
98 #define eEulerYXZ FbxEuler::eOrderYXZ
99 #define eEulerZXY FbxEuler::eOrderZXY
100 #define eEulerZYX FbxEuler::eOrderZYX
101 #define eSphericXYZ FbxEuler::eOrderSphericXYZ
102 
103 
104 
107 {
114 };
115 
116 extern FBXSDK_DLL const FbxDouble FbxIdentityMatrix[4][4];
118 
119 inline float FbxFloor(const float x)
120 {
121  return float(floor(x));
122 }
123 
124 inline double FbxFloor(const double x)
125 {
126  return floor(x);
127 }
128 
129 inline float FbxCeil(const float x)
130 {
131  return float(ceil(x));
132 }
133 
134 inline double FbxCeil(const double x)
135 {
136  return ceil(x);
137 }
138 
139 template<class T> inline T FbxSign(const T x)
140 {
141  return (x < 0) ? T(-1) : T(1);
142 }
143 
144 template<class T> inline T FbxRound(const T x)
145 {
146  T y = FbxFloor(x);
147  return (x - y < T(0.5)) ? y : y + T(1);
148 }
149 
150 inline FbxUChar FbxAbs(const FbxUChar x)
151 {
152  return x;
153 }
154 
155 inline FbxUShort FbxAbs(const FbxUShort x)
156 {
157  return x;
158 }
159 
160 inline FbxUInt FbxAbs(const FbxUInt x)
161 {
162  return x;
163 }
164 
165 #ifndef FBXSDK_SYSTEM_IS_LP64
166  inline FbxULong FbxAbs(const FbxULong x)
167  {
168  return x;
169  }
170 #endif
171 
173 {
174  return x;
175 }
176 
177 inline FbxFloat FbxAbs(const FbxFloat x)
178 {
179  return (FbxFloat)fabs(x);
180 }
181 
182 inline FbxDouble FbxAbs(const FbxDouble x)
183 {
184  return fabs(x);
185 }
186 
187 template<class T> inline T FbxAbs(const T x)
188 {
189  return (x >= 0) ? x : ((x > FbxMin(x)) ? -x : FbxMax(x));
190 }
191 
192 template<class T> inline T FbxClamp(const T value, const T min, const T max)
193 {
194  return (value < min) ? min : ((value > max) ? max : value);
195 }
196 
197 template<class T> inline bool FbxEqual(const T x, const T y, const T e=(T)FBXSDK_TOLERANCE)
198 {
199  return FbxAbs(x - y) <= e;
200 }
201 
202 inline bool FbxEqual(const FbxDouble2& x, const FbxDouble2& y, const double e=FBXSDK_TOLERANCE)
203 {
204  return ( FbxEqual(x.mData[0], y.mData[0], e) && FbxEqual(x.mData[1], y.mData[1], e) );
205 }
206 
207 inline bool FbxEqual(const FbxDouble3& x, const FbxDouble3& y, const double e=FBXSDK_TOLERANCE)
208 {
209  return ( FbxEqual(x.mData[0], y.mData[0], e) && FbxEqual(x.mData[1], y.mData[1], e) && FbxEqual(x.mData[2], y.mData[2], e) );
210 }
211 
212 inline bool FbxEqual(const FbxDouble4& x, const FbxDouble4& y, const double e=FBXSDK_TOLERANCE)
213 {
214  return ( FbxEqual(x.mData[0], y.mData[0], e) && FbxEqual(x.mData[1], y.mData[1], e) && FbxEqual(x.mData[2], y.mData[2], e) && FbxEqual(x.mData[3], y.mData[3], e) );
215 }
216 
217 inline bool FbxEqual(const FbxDouble4x4& x, const FbxDouble4x4& y, const double e=FBXSDK_TOLERANCE)
218 {
219  return ( FbxEqual(x[0], y[0], e) && FbxEqual(x[1], y[1], e) && FbxEqual(x[2], y[2], e) && FbxEqual(x[3], y[3], e) );
220 }
221 
222 inline bool FbxEqual(const FbxVector2& x, const FbxVector2& y, const double e=FBXSDK_TOLERANCE)
223 {
224  return ( FbxEqual(x.mData[0], y.mData[0], e) && FbxEqual(x.mData[1], y.mData[1], e) );
225 }
226 
227 inline bool FbxEqual(const FbxVector4& x, const FbxVector4& y, const double e=FBXSDK_TOLERANCE)
228 {
229  return ( FbxEqual(x.mData[0], y.mData[0], e) && FbxEqual(x.mData[1], y.mData[1], e) && FbxEqual(x.mData[2], y.mData[2], e) && FbxEqual(x.mData[3], y.mData[3], e) );
230 }
231 
232 inline bool FbxEqual(const FbxMatrix& x, const FbxMatrix& y, const double e=FBXSDK_TOLERANCE)
233 {
234  return ( FbxEqual(x[0], y[0], e) && FbxEqual(x[1], y[1], e) && FbxEqual(x[2], y[2], e) && FbxEqual(x[3], y[3], e) );
235 }
236 
237 inline bool FbxEqual(const FbxAMatrix& x, const FbxAMatrix& y, const double e=FBXSDK_TOLERANCE)
238 {
239  return ( FbxEqual(x[0], y[0], e) && FbxEqual(x[1], y[1], e) && FbxEqual(x[2], y[2], e) && FbxEqual(x[3], y[3], e) );
240 }
241 
242 inline FbxDouble FbxMod(const FbxFloat x, FbxFloat& i)
243 {
244  return modff(x, &i);
245 }
246 
247 inline FbxDouble FbxMod(const FbxDouble x, FbxDouble& i)
248 {
249  return modf(x, &i);
250 }
251 
252 inline FbxDouble FbxMod(const FbxFloat x)
253 {
254  FbxFloat i;
255  return modff(x, &i);
256 }
257 
258 inline FbxDouble FbxMod(const FbxDouble x)
259 {
260  FbxDouble i;
261  return modf(x, &i);
262 }
263 
264 template<class T> inline T FbxReciprocal(const T x)
265 {
266  return T(1) / x;
267 }
268 
269 inline double FbxSqrt(const double x)
270 {
271  return sqrt(x);
272 }
273 
274 inline float FbxSqrt(const float x)
275 {
276  return sqrtf(x);
277 }
278 
279 template<class T> inline T FbxSqrt(const T x)
280 {
281  if( x > 1 )
282  {
283  T z, y = x >> 1;
284  do
285  {
286  z = y;
287  y = (y + (x / y)) >> 1;
288  }
289  while(y < z);
290 
291  return z;
292  }
293  else
294  {
295  return x;
296  }
297 }
298 
299 inline float FbxExp(const float x)
300 {
301  return expf(x);
302 }
303 
304 inline double FbxExp(const double x)
305 {
306  return exp(x);
307 }
308 
309 inline float FbxLog(const float x)
310 {
311  return float(log(x));
312 }
313 
314 inline double FbxLog(const double x)
315 {
316  return log(x);
317 }
318 
319 template<class T> inline T FbxPow(const T x, const T y)
320 {
321  return (T)FbxExp(y * FbxLog((double)x));
322 }
323 
324 template<class T> inline T FbxLog2(const T x)
325 {
326  return (T)(FbxLog(x) * FBXSDK_1_DIV_LN2);
327 }
328 
329 inline float FbxSin(const float x)
330 {
331  return sinf(x);
332 }
333 
334 inline double FbxSin(const double x)
335 {
336  return sin(x);
337 }
338 
339 inline float FbxCos(const float x)
340 {
341  return cosf(x);
342 }
343 
344 inline double FbxCos(const double x)
345 {
346  return cos(x);
347 }
348 
349 inline float FbxTan(const float x)
350 {
351  return tanf(x);
352 }
353 
354 inline double FbxTan(const double x)
355 {
356  return tan(x);
357 }
358 
359 // *y = cos(x), sin(x)
360 template<class T> inline T FbxSinCos(const T x, T* y)
361 {
362  return *y = FbxCos(x), FbxSin(x);
363 }
364 
365 // *y = cos(x * pi/180), sin(x * pi/180)
366 template<class T> inline T FbxSinCosd(const T x, T* y)
367 {
368  return FbxSinCos(T(x * FBXSDK_PI_DIV_180), y);
369 }
370 
371 inline float FbxASin(const float x)
372 {
373  return asinf(x);
374 }
375 
376 inline double FbxASin(const double x)
377 {
378  return asin(x);
379 }
380 
381 template<class T> inline T FbxASind(const T x)
382 {
383  return (T)(FbxASin((double)x) * FBXSDK_180_DIV_PI);
384 }
385 
386 inline float FbxACos(const float x)
387 {
388  return acosf(x);
389 }
390 
391 inline double FbxACos(const double x)
392 {
393  return acos(x);
394 }
395 
396 template<class T> inline T FbxACosd(const T x)
397 {
398  return (T)(FbxACos(x) * FBXSDK_180_DIV_PI);
399 }
400 
401 inline float FbxATan(const float x)
402 {
403  return atanf(x);
404 }
405 
406 inline double FbxATan(const double x)
407 {
408  return atan(x);
409 }
410 
411 template<class T> inline T FbxATand(const T x)
412 {
413  return (T)(FbxATan(x) * FBXSDK_180_DIV_PI);
414 }
415 
416 inline float FbxATan(const float y, const float x)
417 {
418  return atan2f(y, x);
419 }
420 
421 inline double FbxATan(const double y, const double x)
422 {
423  return atan2(y, x);
424 }
425 
426 template<class T> inline T FbxATand(const T y, const T x)
427 {
428  return (T)(FbxATan(y, x) * FBXSDK_180_DIV_PI);
429 }
430 
431 template<class T> inline T FbxNorm(const T x, const T y)
432 {
433  return FbxSqrt(x * x + y * y);
434 }
435 
436 template<class T> inline T FbxNorm(const T x, const T y, const T z)
437 {
438  return FbxSqrt(x * x + y * y + z * z);
439 }
440 
441 template<class T> inline T FbxNorm(const T w, const T x, const T y, const T z)
442 {
443  return FbxSqrt(w * w + x * x + y * y + z * z);
444 }
445 
446 template<class T> inline T FbxHypot(const T x, const T y)
447 {
448  return FbxSqrt(x * x + y * y);
449 }
450 
451 template<class T> inline T FbxHypot(const T x, const T y, const T z)
452 {
453  return FbxSqrt(x * x + y * y + z * z);
454 }
455 
456 template<class T> inline T FbxHypot(const T w, const T x, const T y, const T z)
457 {
458  return FbxSqrt(w * w + x * x + y * y + z * z);
459 }
460 
461 inline FbxVector4 FbxRejection(const FbxVector4& a, const FbxVector4& b)
462 {
463  return a - b * (a.DotProduct(b) / b.DotProduct(b));
464 }
465 
466 template<class T> inline int FbxBitCount(const T x)
467 {
468  int n = 0;
469  T c = x;
470  while( c )
471  {
472  n += int(c & 1);
473  c = (c >> 1);
474  }
475  return n;
476 }
477 
478 template<class T> inline void FbxFixInfinite(T& x)
479 {
480  if( x != x || x > FbxMax(x) || x < -FbxMax(x) )
481  {
482  x = T(0);
483  }
484 }
485 
486 template<class T> inline T FbxExp(const T x);
487 template<class T> inline T FbxLog(const T x);
488 template<class T> inline T FbxSin(const T x);
489 template<class T> inline T FbxCos(const T x);
490 template<class T> inline T FbxASin(const T x);
491 template<class T> inline T FbxACos(const T x);
492 template<class T> inline T FbxATan(const T x);
493 template<class T> inline T FbxATan(const T y, const T x);
494 
495 #include <fbxsdk/fbxsdk_nsend.h>
496 
497 #endif /* _FBXSDK_CORE_MATH_H_ */
FbxUInt64 FbxULongLong
Definition: fbxtypes.h:93
unsigned int FbxUInt
Definition: fbxtypes.h:40
float FbxCos(const float x)
Definition: fbxmath.h:339
#define FBXSDK_1_DIV_LN2
1 divided by LogN2
Definition: fbxmath.h:31
FBX SDK environment definition.
float FbxLog(const float x)
Definition: fbxmath.h:309
#define FBXSDK_TOLERANCE
Definition: fbxtypes.h:136
Mix between Slerp and cubic interpolation, depending on the specified tangents for each key...
Definition: fbxmath.h:112
FbxDouble FbxMod(const FbxFloat x, FbxFloat &i)
Definition: fbxmath.h:242
int FbxBitCount(const T x)
Definition: fbxmath.h:466
#define FBXSDK_180_DIV_PI
180 divided by PI
Definition: fbxmath.h:30
EFbxQuatInterpMode
Quaternion interpolation modes.
Definition: fbxmath.h:106
const FbxDouble FbxIdentityMatrix[4][4]
T FbxClamp(const T value, const T min, const T max)
Definition: fbxmath.h:192
float FbxExp(const float x)
Definition: fbxmath.h:299
FbxVector4 FbxRejection(const FbxVector4 &a, const FbxVector4 &b)
Definition: fbxmath.h:461
void FbxFixInfinite(T &x)
Definition: fbxmath.h:478
Spherical linear interpolation.
Definition: fbxmath.h:110
double DotProduct(const FbxVector4 &pVector) const
Calculate the dot product of two vectors.
T FbxRound(const T x)
Definition: fbxmath.h:144
unsigned short FbxUShort
Definition: fbxtypes.h:38
Do not evaluate using quaternion interpolation.
Definition: fbxmath.h:108
unsigned char FbxUChar
Definition: fbxtypes.h:36
T FbxReciprocal(const T x)
Definition: fbxmath.h:264
T FbxPow(const T x, const T y)
Definition: fbxmath.h:319
float FbxFloor(const float x)
Definition: fbxmath.h:119
double FbxDouble
Definition: fbxtypes.h:42
FbxUChar FbxAbs(const FbxUChar x)
Definition: fbxmath.h:150
T FbxSinCos(const T x, T *y)
Definition: fbxmath.h:360
double FbxSqrt(const double x)
Definition: fbxmath.h:269
float FbxATan(const float x)
Definition: fbxmath.h:401
Cubic interpolation.
Definition: fbxmath.h:111
T FbxSign(const T x)
Definition: fbxmath.h:139
T FbxACosd(const T x)
Definition: fbxmath.h:396
Legacy quaternion interpolation mode.
Definition: fbxmath.h:109
float FbxFloat
Definition: fbxtypes.h:41
float FbxACos(const float x)
Definition: fbxmath.h:386
T FbxSinCosd(const T x, T *y)
Definition: fbxmath.h:366
T FbxHypot(const T x, const T y)
Definition: fbxmath.h:446
FbxChar FbxMax(const FbxChar)
Definition: fbxtypes.h:173
T FbxASind(const T x)
Definition: fbxmath.h:381
float FbxCeil(const float x)
Definition: fbxmath.h:129
Number of quaternion interpolation modes.
Definition: fbxmath.h:113
float FbxTan(const float x)
Definition: fbxmath.h:349
A four double mathematic vector class.
Definition: fbxvector4.h:25
FBX SDK affine matrix class.
#define FBXSDK_FLOAT_EPSILON
Definition: fbxtypes.h:132
const FbxVector4 FbxZeroVector4
static double DegenerateThreshold()
Definition: fbxmath.h:83
T FbxNorm(const T x, const T y)
Definition: fbxmath.h:431
FbxChar FbxMin(const FbxChar)
Definition: fbxtypes.h:162
#define FBXSDK_DLL
Definition: fbxarch.h:176
bool FbxEqual(const T x, const T y, const T e=(T)(1.0e-6))
Definition: fbxmath.h:197
float FbxSin(const float x)
Definition: fbxmath.h:329
A two double mathematic vector class.
Definition: fbxvector2.h:23
T FbxLog2(const T x)
Definition: fbxmath.h:324
static const int AxisTableSize
Definition: fbxmath.h:74
FBX SDK basic 4x4 double matrix class.
Definition: fbxmatrix.h:27
float FbxASin(const float x)
Definition: fbxmath.h:371
#define FBXSDK_PI_DIV_180
PI divived by 180.
Definition: fbxmath.h:29
unsigned long FbxULong
Definition: fbxtypes.h:90
T FbxATand(const T x)
Definition: fbxmath.h:411