quaternion_trigonometric.inl 763 B

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