Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
2.5 KiB

  1. /*
  2. * trackball.h
  3. * A virtual trackball implementation
  4. * Written by Gavin Bell for Silicon Graphics, November 1988.
  5. */
  6. /*
  7. * Initialize trackball in win32 environment
  8. */
  9. extern void
  10. trackball_Init( GLint width, GLint height );
  11. extern void
  12. trackball_Resize( GLint width, GLint height );
  13. extern GLenum
  14. trackball_MouseDown( int mouseX, int mouseY, GLenum button );
  15. extern GLenum
  16. trackball_MouseUp( int mouseX, int mouseY, GLenum button );
  17. /* These next Mouse fns are required if both the trackbal and user
  18. * need mouse events. Otherwise, can just supply above two functions
  19. * to tk to call
  20. */
  21. /*
  22. * Mouse functions called directly on events
  23. */
  24. extern void
  25. trackball_MouseDownEvent( int mouseX, int mouseY, GLenum button );
  26. extern void
  27. trackball_MouseUpEvent( int mouseX, int mouseY, GLenum button );
  28. /*
  29. * Functions to register mouse event callbacks
  30. */
  31. extern void
  32. trackball_MouseDownFunc(GLenum (*)(int, int, GLenum));
  33. extern void
  34. trackball_MouseUpFunc(GLenum (*)(int, int, GLenum));
  35. /*
  36. * Calculate rotation matrix based on mouse movement
  37. */
  38. void
  39. trackball_CalcRotMatrix( GLfloat matRot[4][4] );
  40. /*
  41. * Pass the x and y coordinates of the last and current positions of
  42. * the mouse, scaled so they are from (-1.0 ... 1.0).
  43. *
  44. * if ox,oy is the window's center and sizex,sizey is its size, then
  45. * the proper transformation from screen coordinates (sc) to world
  46. * coordinates (wc) is:
  47. * wcx = (2.0 * (scx-ox)) / (float)sizex - 1.0
  48. * wcy = (2.0 * (scy-oy)) / (float)sizey - 1.0
  49. *
  50. * The resulting rotation is returned as a quaternion rotation in the
  51. * first paramater.
  52. */
  53. void
  54. trackball_calc_quat(float q[4], float p1x, float p1y, float p2x, float p2y);
  55. /*
  56. * Given two quaternions, add them together to get a third quaternion.
  57. * Adding quaternions to get a compound rotation is analagous to adding
  58. * translations to get a compound translation. When incrementally
  59. * adding rotations, the first argument here should be the new
  60. * rotation, the second and third the total rotation (which will be
  61. * over-written with the resulting new total rotation).
  62. */
  63. void
  64. trackball_add_quats(float *q1, float *q2, float *dest);
  65. /*
  66. * A useful function, builds a rotation matrix in Matrix based on
  67. * given quaternion.
  68. */
  69. void
  70. trackball_build_rotmatrix(float m[4][4], float q[4]);
  71. /*
  72. * This function computes a quaternion based on an axis (defined by
  73. * the given vector) and an angle about which to rotate. The angle is
  74. * expressed in radians. The result is put into the third argument.
  75. */
  76. void
  77. trackball_axis_to_quat(float a[3], float phi, float q[4]);