trackball.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. template <typename Scalardown_quat, typename Scalarquat>
  62. IGL_INLINE void trackball(
  63. const double w,
  64. const double h,
  65. const double speed_factor,
  66. const Eigen::Quaternion<Scalardown_quat> & down_quat,
  67. const double down_mouse_x,
  68. const double down_mouse_y,
  69. const double mouse_x,
  70. const double mouse_y,
  71. Eigen::Quaternion<Scalarquat> & quat);
  72. }
  73. #ifndef IGL_STATIC_LIBRARY
  74. # include "trackball.cpp"
  75. #endif
  76. #endif