trackball.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. #ifndef IGL_TRACKBALL_H
  9. #define IGL_TRACKBALL_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Core>
  12. #include <Eigen/Geometry>
  13. namespace igl
  14. {
  15. /// Applies a trackball drag to identity
  16. ///
  17. /// @param[in] w width of the trackball context
  18. /// @param[in] h height of the trackball context
  19. /// @param[in] speed_factor controls how fast the trackball feels, 1 is normal
  20. /// @param[in] down_mouse_x x position of mouse down
  21. /// @param[in] down_mouse_y y position of mouse down
  22. /// @param[in] mouse_x current x position of mouse
  23. /// @param[in] mouse_y current y position of mouse
  24. /// @param[out] quat the resulting rotation (as quaternion)
  25. template <typename Q_type>
  26. IGL_INLINE void trackball(
  27. const double w,
  28. const double h,
  29. const Q_type speed_factor,
  30. const double down_mouse_x,
  31. const double down_mouse_y,
  32. const double mouse_x,
  33. const double mouse_y,
  34. Q_type * quat);
  35. /// Applies a trackball drag to a given rotation
  36. ///
  37. /// @param[in] w width of the trackball context
  38. /// @param[in] h height of the trackball context
  39. /// @param[in] speed_factor controls how fast the trackball feels, 1 is normal
  40. /// @param[in] down_quat rotation at mouse down, i.e. the rotation we're applying the
  41. /// trackball motion to (as quaternion)
  42. /// @param[in] down_mouse_x x position of mouse down
  43. /// @param[in] down_mouse_y y position of mouse down
  44. /// @param[in] mouse_x current x position of mouse
  45. /// @param[in] mouse_y current y position of mouse
  46. /// @param[out] quat the resulting rotation (as quaternion)
  47. template <typename Q_type>
  48. IGL_INLINE void trackball(
  49. const double w,
  50. const double h,
  51. const Q_type speed_factor,
  52. const Q_type * down_quat,
  53. const double down_mouse_x,
  54. const double down_mouse_y,
  55. const double mouse_x,
  56. const double mouse_y,
  57. Q_type * quat);
  58. /// \overload
  59. template <typename Scalardown_quat, typename Scalarquat>
  60. IGL_INLINE void trackball(
  61. const double w,
  62. const double h,
  63. const double speed_factor,
  64. const Eigen::Quaternion<Scalardown_quat> & down_quat,
  65. const double down_mouse_x,
  66. const double down_mouse_y,
  67. const double mouse_x,
  68. const double mouse_y,
  69. Eigen::Quaternion<Scalarquat> & quat);
  70. }
  71. #ifndef IGL_STATIC_LIBRARY
  72. # include "trackball.cpp"
  73. #endif
  74. #endif