Trigonometry.h 1.6 KB

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