trackball.h 2.0 KB

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