9
3

quaternion_trigonometric.inl 895 B

12345678910111213141516171819202122232425262728293031323334
  1. #include "scalar_constants.hpp"
  2. namespace glm
  3. {
  4. template<typename T, qualifier Q>
  5. GLM_FUNC_QUALIFIER T angle(qua<T, Q> const& x)
  6. {
  7. if (abs(x.w) > cos_one_over_two<T>())
  8. {
  9. return asin(sqrt(x.x * x.x + x.y * x.y + x.z * x.z)) * static_cast<T>(2);
  10. }
  11. return acos(x.w) * static_cast<T>(2);
  12. }
  13. template<typename T, qualifier Q>
  14. GLM_FUNC_QUALIFIER vec<3, T, Q> axis(qua<T, Q> const& x)
  15. {
  16. T const tmp1 = static_cast<T>(1) - x.w * x.w;
  17. if(tmp1 <= static_cast<T>(0))
  18. return vec<3, T, Q>(0, 0, 1);
  19. T const tmp2 = static_cast<T>(1) / sqrt(tmp1);
  20. return vec<3, T, Q>(x.x * tmp2, x.y * tmp2, x.z * tmp2);
  21. }
  22. template<typename T, qualifier Q>
  23. GLM_FUNC_QUALIFIER qua<T, Q> angleAxis(T const& angle, vec<3, T, Q> const& v)
  24. {
  25. T const a(angle);
  26. T const s = glm::sin(a * static_cast<T>(0.5));
  27. return qua<T, Q>(glm::cos(a * static_cast<T>(0.5)), v * s);
  28. }
  29. }//namespace glm