RotateWidget.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include <Eigen/Core>
  2. #include <Eigen/Geometry>
  3. #include <vector>
  4. // 3D Rotate tool widget
  5. class RotateWidget
  6. {
  7. public:
  8. static Eigen::Quaterniond axis_q[3];
  9. static Eigen::Vector3d view_direction(const int x, const int y);
  10. static Eigen::Vector3d view_direction(const Eigen::Vector3d & pos);
  11. Eigen::Vector3d pos;
  12. Eigen::Quaterniond rot,down_rot;
  13. Eigen::Vector2d down_xy,drag_xy,down_dir;
  14. Eigen::Vector3d udown,udrag;
  15. double outer_radius_on_screen;
  16. double outer_over_inner;
  17. enum DownType
  18. {
  19. DOWN_TYPE_X = 0,
  20. DOWN_TYPE_Y = 1,
  21. DOWN_TYPE_Z = 2,
  22. DOWN_TYPE_OUTLINE = 3,
  23. DOWN_TYPE_TRACKBALL = 4,
  24. DOWN_TYPE_NONE = 5,
  25. NUM_DOWN_TYPES = 6
  26. } down_type, selected_type;
  27. std::vector<Eigen::Vector3d> debug_points;
  28. RotateWidget();
  29. // Vector from origin to mouse click "Unprojected" onto plane with depth of
  30. // origin and scale to so that outer radius is 1
  31. //
  32. // Inputs:
  33. // x mouse x position
  34. // y mouse y position
  35. // Returns vector
  36. Eigen::Vector3d unproject_onto(const int x, const int y);
  37. // Shoot ray from mouse click to sphere
  38. //
  39. // Inputs:
  40. // x mouse x position
  41. // y mouse y position
  42. // Outputs:
  43. // hit position of hit
  44. // Returns true only if there was a hit
  45. bool intersect(const int x, const int y, Eigen::Vector3d & hit);
  46. double unprojected_inner_radius();
  47. bool down(const int x, const int y);
  48. bool drag(const int x, const int y);
  49. bool up(const int x, const int y);
  50. bool is_down();
  51. void draw();
  52. void draw_guide();
  53. };