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.

55 lines
1.6 KiB

  1. ///////////////////////////////////////////////////////////////////////////////////////////////////
  2. // OpenGL Mathematics Copyright (c) 2005 - 2013 G-Truc Creation (www.g-truc.net)
  3. ///////////////////////////////////////////////////////////////////////////////////////////////////
  4. // Created : 2007-03-06
  5. // Updated : 2009-05-01
  6. // Licence : This source is under MIT License
  7. // File : glm/gtx/polar_coordinates.inl
  8. ///////////////////////////////////////////////////////////////////////////////////////////////////
  9. namespace glm
  10. {
  11. template <typename T>
  12. GLM_FUNC_QUALIFIER detail::tvec3<T> polar
  13. (
  14. detail::tvec3<T> const & euclidean
  15. )
  16. {
  17. T const Length(length(euclidean));
  18. detail::tvec3<T> const tmp(euclidean / Length);
  19. T const xz_dist(sqrt(tmp.x * tmp.x + tmp.z * tmp.z));
  20. #ifdef GLM_FORCE_RADIANS
  21. return detail::tvec3<T>(
  22. atan(xz_dist, tmp.y), // latitude
  23. atan(tmp.x, tmp.z), // longitude
  24. xz_dist); // xz distance
  25. #else
  26. return detail::tvec3<T>(
  27. degrees(atan(xz_dist, tmp.y)), // latitude
  28. degrees(atan(tmp.x, tmp.z)), // longitude
  29. xz_dist); // xz distance
  30. #endif
  31. }
  32. template <typename T>
  33. GLM_FUNC_QUALIFIER detail::tvec3<T> euclidean
  34. (
  35. detail::tvec2<T> const & polar
  36. )
  37. {
  38. #ifdef GLM_FORCE_RADIANS
  39. T const latitude(polar.x);
  40. T const longitude(polar.y);
  41. #else
  42. T const latitude(radians(polar.x));
  43. T const longitude(radians(polar.y));
  44. #endif
  45. return detail::tvec3<T>(
  46. cos(latitude) * sin(longitude),
  47. sin(latitude),
  48. cos(latitude) * cos(longitude));
  49. }
  50. }//namespace glm