You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.3 KiB

4 years ago
  1. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2. // OpenGL Mathematics Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net)
  3. ///////////////////////////////////////////////////////////////////////////////////////////////////
  4. // Created : 2006-01-08
  5. // Updated : 2011-10-14
  6. // Licence : This source is under MIT License
  7. // File : glm/gtx/fast_trigonometry.inl
  8. ///////////////////////////////////////////////////////////////////////////////////////////////////
  9. namespace glm
  10. {
  11. // sin
  12. template <typename T>
  13. GLM_FUNC_QUALIFIER T fastSin(T const & x)
  14. {
  15. return x - ((x * x * x) / T(6)) + ((x * x * x * x * x) / T(120)) - ((x * x * x * x * x * x * x) / T(5040));
  16. }
  17. VECTORIZE_VEC(fastSin)
  18. // cos
  19. template <typename T>
  20. GLM_FUNC_QUALIFIER T fastCos(T const & x)
  21. {
  22. return T(1) - (x * x * T(0.5)) + (x * x * x * x * T(0.041666666666)) - (x * x * x * x * x * x * T(0.00138888888888));
  23. }
  24. VECTORIZE_VEC(fastCos)
  25. // tan
  26. template <typename T>
  27. GLM_FUNC_QUALIFIER T fastTan(T const & x)
  28. {
  29. return x + (x * x * x * T(0.3333333333)) + (x * x * x * x * x * T(0.1333333333333)) + (x * x * x * x * x * x * x * T(0.0539682539));
  30. }
  31. VECTORIZE_VEC(fastTan)
  32. // asin
  33. template <typename T>
  34. GLM_FUNC_QUALIFIER T fastAsin(T const & x)
  35. {
  36. return x + (x * x * x * T(0.166666667)) + (x * x * x * x * x * T(0.075)) + (x * x * x * x * x * x * x * T(0.0446428571)) + (x * x * x * x * x * x * x * x * x * T(0.0303819444));// + (x * x * x * x * x * x * x * x * x * x * x * T(0.022372159));
  37. }
  38. VECTORIZE_VEC(fastAsin)
  39. // acos
  40. template <typename T>
  41. GLM_FUNC_QUALIFIER T fastAcos(T const & x)
  42. {
  43. return T(1.5707963267948966192313216916398) - fastAsin(x); //(PI / 2)
  44. }
  45. VECTORIZE_VEC(fastAcos)
  46. // atan
  47. template <typename T>
  48. GLM_FUNC_QUALIFIER T fastAtan(T const & y, T const & x)
  49. {
  50. T sgn = sign(y) * sign(x);
  51. return abs(fastAtan(y / x)) * sgn;
  52. }
  53. VECTORIZE_VEC_VEC(fastAtan)
  54. template <typename T>
  55. GLM_FUNC_QUALIFIER T fastAtan(T const & x)
  56. {
  57. return x - (x * x * x * T(0.333333333333)) + (x * x * x * x * x * T(0.2)) - (x * x * x * x * x * x * x * T(0.1428571429)) + (x * x * x * x * x * x * x * x * x * T(0.111111111111)) - (x * x * x * x * x * x * x * x * x * x * x * T(0.0909090909));
  58. }
  59. VECTORIZE_VEC(fastAtan)
  60. }//namespace glm