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.

47 lines
1.5 KiB

  1. /*
  2. * trackball.h
  3. * A virtual trackball implementation
  4. * Written by Gavin Bell for Silicon Graphics, November 1988.
  5. */
  6. /*
  7. * Pass the x and y coordinates of the last and current positions of
  8. * the mouse, scaled so they are from (-1.0 ... 1.0).
  9. *
  10. * if ox,oy is the window's center and sizex,sizey is its size, then
  11. * the proper transformation from screen coordinates (sc) to world
  12. * coordinates (wc) is:
  13. * wcx = (2.0 * (scx-ox)) / (float)sizex - 1.0
  14. * wcy = (2.0 * (scy-oy)) / (float)sizey - 1.0
  15. *
  16. * The resulting rotation is returned as a quaternion rotation in the
  17. * first paramater.
  18. */
  19. void
  20. trackball(float q[4], float p1x, float p1y, float p2x, float p2y);
  21. /*
  22. * Given two quaternions, add them together to get a third quaternion.
  23. * Adding quaternions to get a compound rotation is analagous to adding
  24. * translations to get a compound translation. When incrementally
  25. * adding rotations, the first argument here should be the new
  26. * rotation, the second and third the total rotation (which will be
  27. * over-written with the resulting new total rotation).
  28. */
  29. void
  30. add_quats(float *q1, float *q2, float *dest);
  31. /*
  32. * A useful function, builds a rotation matrix in Matrix based on
  33. * given quaternion.
  34. */
  35. void
  36. build_rotmatrix(float m[4][4], float q[4]);
  37. /*
  38. * This function computes a quaternion based on an axis (defined by
  39. * the given vector) and an angle about which to rotate. The angle is
  40. * expressed in radians. The result is put into the third argument.
  41. */
  42. void
  43. axis_to_quat(float a[3], float phi, float q[4]);