Viewport.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. x(0),y(0),width(0),height(0),camera(){};
  13. Viewport(
  14. const int x,
  15. const int y,
  16. const int width,
  17. const int height,
  18. const igl::Camera & camera):
  19. x(x),
  20. y(y),
  21. width(width),
  22. height(height),
  23. camera(camera)
  24. {
  25. };
  26. void reshape(
  27. const int x,
  28. const int y,
  29. const int width,
  30. const int height)
  31. {
  32. this->x = x;
  33. this->y = y;
  34. this->width = width;
  35. this->height = height;
  36. };
  37. // Given mouse_x,mouse_y on the entire window return mouse_x, mouse_y in
  38. // this viewport.
  39. //
  40. // Inputs:
  41. // my mouse y-coordinate
  42. // wh window weight
  43. // Returns y-coordinate in viewport
  44. int mouse_y(const int my,const int wh)
  45. {
  46. return my - (wh - height - y);
  47. }
  48. // Inputs:
  49. // mx mouse x-coordinate
  50. // Returns x-coordinate in viewport
  51. int mouse_x(const int mx)
  52. {
  53. return mx - x;
  54. }
  55. };
  56. }
  57. #endif