hx3d  1
2D/3D Simple Game Framework
orthographic_camera.cpp
1 /*
2  Orthographic camera.
3  Inspired by LibGDX orthographic camera.
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 #include "hx3d/graphics/cameras/orthographic_camera.hpp"
24 
25 #include "hx3d/core/core.hpp"
26 #include "hx3d/window/application.hpp"
27 
28 namespace hx3d {
29 namespace graphics {
30 
32  OrthographicCamera(Core::App()->getWidth(), Core::App()->getHeight())
33 {}
34 
35 OrthographicCamera::OrthographicCamera(const float width, const float height):
36  Camera(width, height, -1, 1), zoom(1.f)
37  {
38  position = glm::vec3(zoom * viewportWidth / 2.f, zoom * viewportHeight / 2.f, 0);
39 
40  update();
41 }
42 
44  projection = glm::ortho(zoom * (-viewportWidth / 2.f), zoom * (viewportWidth / 2.f), zoom * (-viewportHeight / 2.f), zoom * (viewportHeight / 2.f), near, far);
45  view = glm::lookAt(position, position + direction, up);
46 }
47 
48 void OrthographicCamera::setToOrtho(const float width, const float height) {
49  position = glm::vec3(zoom * viewportWidth / 2.f, zoom * viewportHeight / 2.f, 0);
50 
51  viewportWidth = width;
52  viewportHeight = height;
53  update();
54 }
55 
56 } /* graphics */
57 } /* hx3d */
float near
Near pane.
Definition: camera.hpp:104
float viewportHeight
Viewport height.
Definition: camera.hpp:111
glm::vec3 up
Camera up vector.
Definition: camera.hpp:96
2D/3D camera.
Definition: camera.hpp:41
glm::mat4 view
View matrix.
Definition: camera.hpp:101
virtual void update() override
Update the camera.
glm::mat4 projection
Projection matrix.
Definition: camera.hpp:99
hx3d framework namespace
Definition: audio.hpp:26
2D orthographic camera w/ Z-buffer.
float far
Far pane.
Definition: camera.hpp:106
float viewportWidth
Viewport width.
Definition: camera.hpp:109
glm::vec3 position
Camera position.
Definition: camera.hpp:92
void setToOrtho(const float width, const float height)
Set the orthographic size.
Centralized framework management.
Definition: core.hpp:50
OrthographicCamera()
Create an orthographic camera with the screen size.
glm::vec3 direction
Camera direction.
Definition: camera.hpp:94