MathUtil.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #ifndef MATHUTIL_H_
  2. #define MATHUTIL_H_
  3. namespace gameplay
  4. {
  5. /**
  6. * Defines a math utility class.
  7. *
  8. * This is primarily used for optimized internal math operations.
  9. */
  10. class MathUtil
  11. {
  12. friend class Matrix;
  13. friend class Vector3;
  14. public:
  15. /**
  16. * Updates the given scalar towards the given target using a smoothing function.
  17. * The given response time determines the amount of smoothing (lag). A longer
  18. * response time yields a smoother result and more lag. To force the scalar to
  19. * follow the target closely, provide a response time that is very small relative
  20. * to the given elapsed time.
  21. *
  22. * @param x the scalar to update.
  23. * @param target target value.
  24. * @param elapsedTime elapsed time between calls.
  25. * @param responseTime response time (in the same units as elapsedTime).
  26. */
  27. static void smooth(float* x, float target, float elapsedTime, float responseTime);
  28. /**
  29. * Updates the given scalar towards the given target using a smoothing function.
  30. * The given rise and fall times determine the amount of smoothing (lag). Longer
  31. * rise and fall times yield a smoother result and more lag. To force the scalar to
  32. * follow the target closely, provide rise and fall times that are very small relative
  33. * to the given elapsed time.
  34. *
  35. * @param x the scalar to update.
  36. * @param target target value.
  37. * @param elapsedTime elapsed time between calls.
  38. * @param riseTime response time for rising slope (in the same units as elapsedTime).
  39. * @param fallTime response time for falling slope (in the same units as elapsedTime).
  40. */
  41. static void smooth(float* x, float target, float elapsedTime, float riseTime, float fallTime);
  42. private:
  43. inline static void addMatrix(const float* m, float scalar, float* dst);
  44. inline static void addMatrix(const float* m1, const float* m2, float* dst);
  45. inline static void subtractMatrix(const float* m1, const float* m2, float* dst);
  46. inline static void multiplyMatrix(const float* m, float scalar, float* dst);
  47. inline static void multiplyMatrix(const float* m1, const float* m2, float* dst);
  48. inline static void negateMatrix(const float* m, float* dst);
  49. inline static void transposeMatrix(const float* m, float* dst);
  50. inline static void transformVector4(const float* m, float x, float y, float z, float w, float* dst);
  51. inline static void transformVector4(const float* m, const float* v, float* dst);
  52. inline static void crossVector3(const float* v1, const float* v2, float* dst);
  53. MathUtil();
  54. };
  55. }
  56. #define MATRIX_SIZE ( sizeof(float) * 16)
  57. #ifdef GP_USE_NEON
  58. #include "MathUtilNeon.inl"
  59. #else
  60. #include "MathUtil.inl"
  61. #endif
  62. #endif