hx3d  1
2D/3D Simple Game Framework
viewport.hpp
1 /*
2  Viewport.
3  Inspired by LibGDX viewport.
4 
5  Copyright (C) 2015 Denis BOURGE
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Lesser General Public
9  License as published by the Free Software Foundation; either
10  version 2.1 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public
18  License along with this library; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
20  USA
21 
22 
23  TODO
24  > Add more viewport types.
25 */
26 
27 #ifndef HX3D_GRAPHICS_VIEWPORTS_VIEWPORT
28 #define HX3D_GRAPHICS_VIEWPORTS_VIEWPORT
29 
30 #include <glm/vec2.hpp>
31 
32 #include "hx3d/graphics/cameras/camera.hpp"
33 #include "hx3d/utils/ptr.hpp"
34 
35 namespace hx3d {
36 namespace graphics {
37 
41 namespace viewports {
42 
46 class Viewport {
47 
48 public:
49  Viewport();
50  virtual ~Viewport();
51 
58  void setScreenPosition(const float x, const float y);
59 
65  void apply(Camera& camera);
66 
75  void update(Camera& camera, const int screenWidth, const int screenHeight);
76 
84  glm::vec2 screenToWorld(const glm::vec2 screenPoint);
85 
89  glm::vec2 getWorldSize();
90 
91 protected:
93  float _worldWidth;
95  float _worldHeight;
96 
98  int _screenX;
100  int _screenY;
105 
109  virtual void internalUpdate(Camera& camera) = 0;
110 };
111 
112 } /* viewports */
113 } /* graphics */
114 } /* hx3d */
115 
116 #endif
2D/3D camera.
Definition: camera.hpp:41
hx3d framework namespace
Definition: audio.hpp:26
void apply(Camera &camera)
Apply the viewport on the screen, centering the camera.
Definition: viewport.cpp:42
float _worldHeight
World height.
Definition: viewport.hpp:95
virtual void internalUpdate(Camera &camera)=0
Update the viewport, centering the camera (internal).
int _screenHeight
Screen height.
Definition: viewport.hpp:104
void setScreenPosition(const float x, const float y)
Set the viewport position.
Definition: viewport.cpp:37
void update(Camera &camera, const int screenWidth, const int screenHeight)
Update the viewport with a new screen width and height, centering the camera.
Definition: viewport.cpp:54
glm::vec2 screenToWorld(const glm::vec2 screenPoint)
Convert a screen point to a world point.
Definition: viewport.cpp:61
float _worldWidth
World width.
Definition: viewport.hpp:93
glm::vec2 getWorldSize()
Get the world size.
Definition: viewport.cpp:71