Viewport.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. virtual ~Viewport(){}
  25. void reshape(
  26. const int x,
  27. const int y,
  28. const int width,
  29. const int height)
  30. {
  31. this->x = x;
  32. this->y = y;
  33. this->width = width;
  34. this->height = height;
  35. };
  36. // Given mouse_x,mouse_y on the entire window return mouse_x, mouse_y in
  37. // this viewport.
  38. //
  39. // Inputs:
  40. // my mouse y-coordinate
  41. // wh window weight
  42. // Returns y-coordinate in viewport
  43. int mouse_y(const int my,const int wh)
  44. {
  45. return my - (wh - height - y);
  46. }
  47. // Inputs:
  48. // mx mouse x-coordinate
  49. // Returns x-coordinate in viewport
  50. int mouse_x(const int mx)
  51. {
  52. return mx - x;
  53. }
  54. };
  55. }
  56. #endif