hx3d  1
2D/3D Simple Game Framework
camera.hpp
1 /*
2  Base camera class.
3  Inspired by LibGDX 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 #ifndef HX3D_GRAPHICS_CAMERAS_CAMERA
24 #define HX3D_GRAPHICS_CAMERAS_CAMERA
25 
26 #include <glm/vec3.hpp>
27 #include <glm/mat2x2.hpp>
28 #include <glm/gtc/matrix_transform.hpp>
29 
30 #include "hx3d/graphics/color.hpp"
31 
32 namespace hx3d {
33 namespace graphics {
34 
41 class Camera {
42 public:
51  Camera(const float width, const float height, const float near, const float far);
52 
58  void lookAt(glm::vec3 target);
59 
65  void translate(const glm::vec3 vec);
66 
73  void rotate(const float angle, const glm::vec3 axis);
74 
82  void rotateAround(const glm::vec3 center, const float angle, const glm::vec3 axis);
83 
87  virtual void update() = 0;
88 
90 
92  glm::vec3 position;
94  glm::vec3 direction;
96  glm::vec3 up;
97 
99  glm::mat4 projection;
101  glm::mat4 view;
102 
104  float near;
106  float far;
107 
112 };
113 
114 } /* graphics */
115 } /* hx3d */
116 
117 #endif
void rotate(const float angle, const glm::vec3 axis)
Rotate the camera on one/multiple axes.
Definition: camera.cpp:71
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
Camera(const float width, const float height, const float near, const float far)
Create a camera with a viewport width and height.
Definition: camera.cpp:31
void translate(const glm::vec3 vec)
Translate the camera.
Definition: camera.cpp:67
2D/3D camera.
Definition: camera.hpp:41
glm::mat4 view
View matrix.
Definition: camera.hpp:101
glm::mat4 projection
Projection matrix.
Definition: camera.hpp:99
hx3d framework namespace
Definition: audio.hpp:26
float far
Far pane.
Definition: camera.hpp:106
virtual void update()=0
Update the camera.
float viewportWidth
Viewport width.
Definition: camera.hpp:109
void lookAt(glm::vec3 target)
Look at target.
Definition: camera.cpp:41
glm::vec3 position
Camera position.
Definition: camera.hpp:92
void rotateAround(const glm::vec3 center, const float angle, const glm::vec3 axis)
Rotate the camera around one point, on one/multiple axes.
Definition: camera.cpp:76
glm::vec3 direction
Camera direction.
Definition: camera.hpp:94