Viewport.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #ifndef IGL_VIEWPORT_H
  2. #define IGL_VIEWPORT_H
  3. #include "Camera.h"
  4. namespace igl
  5. {
  6. struct Viewport
  7. {
  8. int x,y,width,height;
  9. igl::Camera camera;
  10. // Constructors
  11. Viewport(
  12. const int x=0,
  13. const int y=0,
  14. const int width=0,
  15. const int height=0,
  16. const igl::Camera & camera = igl::Camera()):
  17. x(x),
  18. y(y),
  19. width(width),
  20. height(height),
  21. camera(camera)
  22. {
  23. };
  24. void reshape(
  25. const int x,
  26. const int y,
  27. const int width,
  28. const int height)
  29. {
  30. this->x = x;
  31. this->y = y;
  32. this->width = width;
  33. this->height = height;
  34. };
  35. // Given mouse_x,mouse_y on the entire window return mouse_x, mouse_y in
  36. // this viewport.
  37. //
  38. // Inputs:
  39. // my mouse y-coordinate
  40. // wh window weight
  41. // Returns y-coordinate in viewport
  42. int mouse_y(const int my,const int wh)
  43. {
  44. return my - (wh - height - y);
  45. }
  46. // Inputs:
  47. // mx mouse x-coordinate
  48. // Returns x-coordinate in viewport
  49. int mouse_x(const int mx)
  50. {
  51. return mx - x;
  52. }
  53. };
  54. }
  55. #endif