snap_to_fixed_up.cpp 758 B

12345678910111213141516171819202122232425
  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 "snap_to_fixed_up.h"
  9. IGL_INLINE void igl::snap_to_fixed_up(
  10. const Eigen::Quaterniond & q,
  11. Eigen::Quaterniond & s)
  12. {
  13. using namespace Eigen;
  14. const Vector3d up = q.matrix() * Vector3d(0,1,0);
  15. Vector3d proj_up(0,up(1),up(2));
  16. if(proj_up.norm() == 0)
  17. {
  18. proj_up = Vector3d(0,1,0);
  19. }
  20. proj_up.normalize();
  21. Quaterniond dq;
  22. dq = Quaterniond::FromTwoVectors(up,proj_up);
  23. s = dq * q;
  24. }