quat_to_mat.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #include "quat_to_mat.h"
  9. template <typename Q_type>
  10. IGL_INLINE void igl::quat_to_mat(const Q_type * quat, Q_type * mat)
  11. {
  12. Q_type yy2 = 2.0f * quat[1] * quat[1];
  13. Q_type xy2 = 2.0f * quat[0] * quat[1];
  14. Q_type xz2 = 2.0f * quat[0] * quat[2];
  15. Q_type yz2 = 2.0f * quat[1] * quat[2];
  16. Q_type zz2 = 2.0f * quat[2] * quat[2];
  17. Q_type wz2 = 2.0f * quat[3] * quat[2];
  18. Q_type wy2 = 2.0f * quat[3] * quat[1];
  19. Q_type wx2 = 2.0f * quat[3] * quat[0];
  20. Q_type xx2 = 2.0f * quat[0] * quat[0];
  21. mat[0*4+0] = - yy2 - zz2 + 1.0f;
  22. mat[0*4+1] = xy2 + wz2;
  23. mat[0*4+2] = xz2 - wy2;
  24. mat[0*4+3] = 0;
  25. mat[1*4+0] = xy2 - wz2;
  26. mat[1*4+1] = - xx2 - zz2 + 1.0f;
  27. mat[1*4+2] = yz2 + wx2;
  28. mat[1*4+3] = 0;
  29. mat[2*4+0] = xz2 + wy2;
  30. mat[2*4+1] = yz2 - wx2;
  31. mat[2*4+2] = - xx2 - yy2 + 1.0f;
  32. mat[2*4+3] = 0;
  33. mat[3*4+0] = mat[3*4+1] = mat[3*4+2] = 0;
  34. mat[3*4+3] = 1;
  35. }
  36. #ifdef IGL_STATIC_LIBRARY
  37. // Explicit template specialization
  38. // generated by autoexplicit.sh
  39. template void igl::quat_to_mat<double>(double const*, double*);
  40. // generated by autoexplicit.sh
  41. template void igl::quat_to_mat<float>(float const*, float*);
  42. #endif