two_axis_valuator_fixed_up.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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 "two_axis_valuator_fixed_up.h"
  9. #include "PI.h"
  10. template <typename Scalardown_quat, typename Scalarquat>
  11. IGL_INLINE void igl::two_axis_valuator_fixed_up(
  12. const int w,
  13. const int h,
  14. const double speed,
  15. const Eigen::Quaternion<Scalardown_quat> & down_quat,
  16. const int down_x,
  17. const int down_y,
  18. const int mouse_x,
  19. const int mouse_y,
  20. Eigen::Quaternion<Scalarquat> & quat)
  21. {
  22. using namespace Eigen;
  23. Matrix<Scalarquat,3,1> axis(0,1,0);
  24. quat = down_quat *
  25. Quaternion<Scalarquat>(
  26. AngleAxis<Scalarquat>(
  27. PI*((Scalarquat)(mouse_x-down_x))/(Scalarquat)w*speed/2.0,
  28. axis.normalized()));
  29. quat.normalize();
  30. {
  31. Matrix<Scalarquat,3,1> axis(1,0,0);
  32. if(axis.norm() != 0)
  33. {
  34. quat =
  35. Quaternion<Scalarquat>(
  36. AngleAxis<Scalarquat>(
  37. PI*(mouse_y-down_y)/(Scalarquat)h*speed/2.0,
  38. axis.normalized())) * quat;
  39. quat.normalize();
  40. }
  41. }
  42. }
  43. #ifdef IGL_STATIC_LIBRARY
  44. // Explicit template specialization
  45. template void igl::two_axis_valuator_fixed_up<float, float>(int, int, double, Eigen::Quaternion<float, 0> const&, int, int, int, int, Eigen::Quaternion<float, 0>&);
  46. template void igl::two_axis_valuator_fixed_up<double, double>(int, int, double, Eigen::Quaternion<double, 0> const&, int, int, int, int, Eigen::Quaternion<double, 0>&);
  47. #endif