snap_to_fixed_up.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <[email protected]>
  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 "snap_to_fixed_up.h"
  9. template <typename Qtype>
  10. IGL_INLINE void igl::snap_to_fixed_up(
  11. const Eigen::Quaternion<Qtype> & q,
  12. Eigen::Quaternion<Qtype> & s)
  13. {
  14. typedef Eigen::Matrix<Qtype,3,1> Vector3Q;
  15. const Vector3Q up = q.matrix() * Vector3Q(0,1,0);
  16. Vector3Q proj_up(0,up(1),up(2));
  17. if(proj_up.norm() == 0)
  18. {
  19. proj_up = Vector3Q(0,1,0);
  20. }
  21. proj_up.normalize();
  22. Eigen::Quaternion<Qtype> dq;
  23. dq = Eigen::Quaternion<Qtype>::FromTwoVectors(up,proj_up);
  24. s = dq * q;
  25. }
  26. #ifdef IGL_STATIC_LIBRARY
  27. // Explicit template instantiations
  28. template void igl::snap_to_fixed_up<float>(Eigen::Quaternion<float, 0> const&, Eigen::Quaternion<float, 0>&);
  29. template void igl::snap_to_fixed_up<double>(Eigen::Quaternion<double, 0> const&, Eigen::Quaternion<double, 0>&);
  30. #endif