Viewport.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #ifndef IGL_VIEWPORT_H
  9. #define IGL_VIEWPORT_H
  10. #include "Camera.h"
  11. namespace igl
  12. {
  13. struct Viewport
  14. {
  15. int x,y,width,height;
  16. igl::Camera camera;
  17. // Constructors
  18. Viewport(
  19. const int x=0,
  20. const int y=0,
  21. const int width=0,
  22. const int height=0,
  23. const igl::Camera & camera = igl::Camera()):
  24. x(x),
  25. y(y),
  26. width(width),
  27. height(height),
  28. camera(camera)
  29. {
  30. };
  31. virtual ~Viewport(){}
  32. void reshape(
  33. const int x,
  34. const int y,
  35. const int width,
  36. const int height)
  37. {
  38. this->x = x;
  39. this->y = y;
  40. this->width = width;
  41. this->height = height;
  42. };
  43. // Given mouse_x,mouse_y on the entire window return mouse_x, mouse_y in
  44. // this viewport.
  45. //
  46. // Inputs:
  47. // my mouse y-coordinate
  48. // wh window weight
  49. // Returns y-coordinate in viewport
  50. int mouse_y(const int my,const int wh)
  51. {
  52. return my - (wh - height - y);
  53. }
  54. // Inputs:
  55. // mx mouse x-coordinate
  56. // Returns x-coordinate in viewport
  57. int mouse_x(const int mx)
  58. {
  59. return mx - x;
  60. }
  61. };
  62. }
  63. #endif