vector_angle.inl 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /// @ref gtx_vector_angle
  2. namespace glm
  3. {
  4. template<typename genType>
  5. GLM_FUNC_QUALIFIER genType angle
  6. (
  7. genType const& x,
  8. genType const& y
  9. )
  10. {
  11. GLM_STATIC_ASSERT(std::numeric_limits<genType>::is_iec559, "'angle' only accept floating-point inputs");
  12. return acos(clamp(dot(x, y), genType(-1), genType(1)));
  13. }
  14. template<length_t L, typename T, qualifier Q>
  15. GLM_FUNC_QUALIFIER T angle(vec<L, T, Q> const& x, vec<L, T, Q> const& y)
  16. {
  17. GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'angle' only accept floating-point inputs");
  18. return acos(clamp(dot(x, y), T(-1), T(1)));
  19. }
  20. //! \todo epsilon is hard coded to 0.01
  21. template<typename T, qualifier Q>
  22. GLM_FUNC_QUALIFIER T orientedAngle(vec<2, T, Q> const& x, vec<2, T, Q> const& y)
  23. {
  24. GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'orientedAngle' only accept floating-point inputs");
  25. T const Angle(acos(clamp(dot(x, y), T(-1), T(1))));
  26. if(all(epsilonEqual(y, glm::rotate(x, Angle), T(0.0001))))
  27. return Angle;
  28. else
  29. return -Angle;
  30. }
  31. template<typename T, qualifier Q>
  32. GLM_FUNC_QUALIFIER T orientedAngle(vec<3, T, Q> const& x, vec<3, T, Q> const& y, vec<3, T, Q> const& ref)
  33. {
  34. GLM_STATIC_ASSERT(std::numeric_limits<T>::is_iec559, "'orientedAngle' only accept floating-point inputs");
  35. T const Angle(acos(clamp(dot(x, y), T(-1), T(1))));
  36. return mix(Angle, -Angle, dot(ref, cross(x, y)) < T(0));
  37. }
  38. }//namespace glm