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.

57 lines
1.6 KiB

  1. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2. // OpenGL Mathematics Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net)
  3. ///////////////////////////////////////////////////////////////////////////////////////////////////
  4. // Created : 2005-12-30
  5. // Updated : 2008-09-29
  6. // Licence : This source is under MIT License
  7. // File : glm/gtx/vector_angle.inl
  8. ///////////////////////////////////////////////////////////////////////////////////////////////////
  9. namespace glm
  10. {
  11. template <typename genType>
  12. GLM_FUNC_QUALIFIER typename genType::value_type angle
  13. (
  14. genType const & x,
  15. genType const & y
  16. )
  17. {
  18. return degrees(acos(dot(x, y)));
  19. }
  20. //! \todo epsilon is hard coded to 0.01
  21. template <typename valType>
  22. GLM_FUNC_QUALIFIER valType orientedAngle
  23. (
  24. detail::tvec2<valType> const & x,
  25. detail::tvec2<valType> const & y
  26. )
  27. {
  28. #ifdef GLM_FORCE_RADIANS
  29. valType const Angle(acos(dot(x, y)));
  30. #else
  31. valType const Angle(glm::degrees(acos(dot(x, y))));
  32. #endif
  33. detail::tvec2<valType> const TransformedVector(glm::rotate(x, Angle));
  34. if(all(epsilonEqual(y, TransformedVector, valType(0.01))))
  35. return Angle;
  36. else
  37. return -Angle;
  38. }
  39. template <typename valType>
  40. GLM_FUNC_QUALIFIER valType orientedAngle
  41. (
  42. detail::tvec3<valType> const & x,
  43. detail::tvec3<valType> const & y,
  44. detail::tvec3<valType> const & ref
  45. )
  46. {
  47. valType const Angle(glm::degrees(glm::acos(glm::dot(x, y))));
  48. if(glm::dot(ref, glm::cross(x, y)) < valType(0))
  49. return -Angle;
  50. else
  51. return Angle;
  52. }
  53. }//namespace glm