quat_to_mat.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. #include "quat_to_mat.h"
  2. template <typename Q_type>
  3. IGL_INLINE void igl::quat_to_mat(const Q_type * quat, Q_type * mat)
  4. {
  5. Q_type yy2 = 2.0f * quat[1] * quat[1];
  6. Q_type xy2 = 2.0f * quat[0] * quat[1];
  7. Q_type xz2 = 2.0f * quat[0] * quat[2];
  8. Q_type yz2 = 2.0f * quat[1] * quat[2];
  9. Q_type zz2 = 2.0f * quat[2] * quat[2];
  10. Q_type wz2 = 2.0f * quat[3] * quat[2];
  11. Q_type wy2 = 2.0f * quat[3] * quat[1];
  12. Q_type wx2 = 2.0f * quat[3] * quat[0];
  13. Q_type xx2 = 2.0f * quat[0] * quat[0];
  14. mat[0*4+0] = - yy2 - zz2 + 1.0f;
  15. mat[0*4+1] = xy2 + wz2;
  16. mat[0*4+2] = xz2 - wy2;
  17. mat[0*4+3] = 0;
  18. mat[1*4+0] = xy2 - wz2;
  19. mat[1*4+1] = - xx2 - zz2 + 1.0f;
  20. mat[1*4+2] = yz2 + wx2;
  21. mat[1*4+3] = 0;
  22. mat[2*4+0] = xz2 + wy2;
  23. mat[2*4+1] = yz2 - wx2;
  24. mat[2*4+2] = - xx2 - yy2 + 1.0f;
  25. mat[2*4+3] = 0;
  26. mat[3*4+0] = mat[3*4+1] = mat[3*4+2] = 0;
  27. mat[3*4+3] = 1;
  28. }
  29. #ifndef IGL_HEADER_ONLY
  30. // Explicit template specialization
  31. // generated by autoexplicit.sh
  32. template void igl::quat_to_mat<double>(double const*, double*);
  33. // generated by autoexplicit.sh
  34. template void igl::quat_to_mat<float>(float const*, float*);
  35. #endif