trackball.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. #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. // Inputs:
  17. // w width of the trackball context
  18. // h height of the trackball context
  19. // speed_factor controls how fast the trackball feels, 1 is normal
  20. // down_mouse_x x position of mouse down
  21. // down_mouse_y y position of mouse down
  22. // mouse_x current x position of mouse
  23. // mouse_y current y position of mouse
  24. // Outputs:
  25. // quat the resulting rotation (as quaternion)
  26. template <typename Q_type>
  27. IGL_INLINE void trackball(
  28. const double w,
  29. const double h,
  30. const Q_type speed_factor,
  31. const double down_mouse_x,
  32. const double down_mouse_y,
  33. const double mouse_x,
  34. const double mouse_y,
  35. Q_type * quat);
  36. // Applies a trackball drag to a given rotation
  37. // Inputs:
  38. // w width of the trackball context
  39. // h height of the trackball context
  40. // speed_factor controls how fast the trackball feels, 1 is normal
  41. // down_quat rotation at mouse down, i.e. the rotation we're applying the
  42. // trackball motion to (as quaternion)
  43. // down_mouse_x x position of mouse down
  44. // down_mouse_y y position of mouse down
  45. // mouse_x current x position of mouse
  46. // mouse_y current y position of mouse
  47. // Outputs:
  48. // quat the resulting rotation (as quaternion)
  49. template <typename Q_type>
  50. IGL_INLINE void trackball(
  51. const double w,
  52. const double h,
  53. const Q_type speed_factor,
  54. const Q_type * down_quat,
  55. const double down_mouse_x,
  56. const double down_mouse_y,
  57. const double mouse_x,
  58. const double mouse_y,
  59. Q_type * quat);
  60. // Eigen wrapper.
  61. IGL_INLINE void trackball(
  62. const double w,
  63. const double h,
  64. const double speed_factor,
  65. const Eigen::Quaterniond & down_quat,
  66. const double down_mouse_x,
  67. const double down_mouse_y,
  68. const double mouse_x,
  69. const double mouse_y,
  70. Eigen::Quaterniond & quat);
  71. }
  72. #ifdef IGL_HEADER_ONLY
  73. # include "trackball.cpp"
  74. #endif
  75. #endif