Trigonometry.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  2. // SPDX-License-Identifier: MIT
  3. #pragma once
  4. JPH_NAMESPACE_BEGIN
  5. // Note that this file exists because std::sin etc. are not platform independent and will lead to non-deterministic simulation
  6. /// Sine of x (input in radians)
  7. JPH_INLINE float Sin(float inX)
  8. {
  9. Vec4 s, c;
  10. Vec4::sReplicate(inX).SinCos(s, c);
  11. return s.GetX();
  12. }
  13. /// Cosine of x (input in radians)
  14. JPH_INLINE float Cos(float inX)
  15. {
  16. Vec4 s, c;
  17. Vec4::sReplicate(inX).SinCos(s, c);
  18. return c.GetX();
  19. }
  20. /// Tangent of x (input in radians)
  21. JPH_INLINE float Tan(float inX)
  22. {
  23. return Vec4::sReplicate(inX).Tan().GetX();
  24. }
  25. /// Arc sine of x (returns value in the range [-PI / 2, PI / 2])
  26. /// Note that all input values will be clamped to the range [-1, 1] and this function will not return NaNs like std::asin
  27. JPH_INLINE float ASin(float inX)
  28. {
  29. return Vec4::sReplicate(inX).ASin().GetX();
  30. }
  31. /// Arc cosine of x (returns value in the range [0, PI])
  32. /// Note that all input values will be clamped to the range [-1, 1] and this function will not return NaNs like std::acos
  33. JPH_INLINE float ACos(float inX)
  34. {
  35. return Vec4::sReplicate(inX).ACos().GetX();
  36. }
  37. /// Arc tangent of x (returns value in the range [-PI / 2, PI / 2])
  38. JPH_INLINE float ATan(float inX)
  39. {
  40. return Vec4::sReplicate(inX).ATan().GetX();
  41. }
  42. /// Arc tangent of y / x using the signs of the arguments to determine the correct quadrant (returns value in the range [-PI, PI])
  43. JPH_INLINE float ATan2(float inY, float inX)
  44. {
  45. return Vec4::sATan2(Vec4::sReplicate(inY), Vec4::sReplicate(inX)).GetX();
  46. }
  47. JPH_NAMESPACE_END