sgltk 0.6
Simple OpenGL Tool Kit
Loading...
Searching...
No Matches
camera.h
1#ifndef __CAMERA_H__
2#define __CAMERA_H__
3
4#include "app.h"
5
6namespace sgltk {
7
12class Camera {
13public:
17 glm::mat4 view_matrix;
25 float width;
29 float height;
33 float fovy;
37 float far_plane;
45 glm::vec3 position;
49 glm::vec3 direction;
53 glm::vec3 up;
57 glm::vec3 right;
58
64 EXPORT Camera(glm::vec3 position,
65 glm::vec3 direction,
66 glm::vec3 up);
67 EXPORT ~Camera();
68
72 EXPORT void update_view_matrix();
73
77 EXPORT virtual void update_projection_matrix() = 0;
78
83 EXPORT void move_up(float delta);
88 EXPORT void move_right(float delta);
93 EXPORT void move_forward(float delta);
100 EXPORT void move_by(float x, float y, float z);
105 EXPORT void move_by(glm::vec3 vector);
110 EXPORT void yaw(float angle);
115 EXPORT void roll(float angle);
120 EXPORT void pitch(float angle);
121};
122
127class P_Camera : public Camera {
128 public:
129 EXPORT P_Camera();
133 EXPORT P_Camera(const sgltk::P_Camera& camera);
139 EXPORT P_Camera(glm::vec3 position,
140 glm::vec3 direction,
141 glm::vec3 up);
152 EXPORT P_Camera(glm::vec3 position,
153 glm::vec3 direction,
154 glm::vec3 up,
155 float fovy,
156 float width,
157 float height,
158 float near_plane,
159 float far_plane);
160 EXPORT ~P_Camera();
164 EXPORT void update_projection_matrix();
178 EXPORT std::vector<glm::vec3> calculate_frustum_points();
193 EXPORT std::vector<float> calculate_frustum_distance(glm::vec3 point);
194};
195
200class O_Camera : public Camera {
201 public:
202 EXPORT O_Camera();
206 EXPORT O_Camera(const O_Camera& camera);
212 EXPORT O_Camera(glm::vec3 position,
213 glm::vec3 direction,
214 glm::vec3 up);
224 EXPORT O_Camera(glm::vec3 position,
225 glm::vec3 direction,
226 glm::vec3 up,
227 float width,
228 float height,
229 float near_plane,
230 float far_plane);
231 EXPORT ~O_Camera();
235 EXPORT void update_projection_matrix();
249 EXPORT std::vector<glm::vec3> calculate_frustum_points();
264 EXPORT std::vector<float> calculate_frustum_distance(glm::vec3 point);
274 EXPORT void calculate_bounding_frustum(O_Camera& camera, glm::vec3 direction, float offset);
284 EXPORT void calculate_bounding_frustum(P_Camera& camera, glm::vec3 direction, float offset);
285};
286
291class IP_Camera : public Camera {
292 public:
293 EXPORT IP_Camera();
297 EXPORT IP_Camera(const IP_Camera& camera);
303 EXPORT IP_Camera(glm::vec3 position,
304 glm::vec3 direction,
305 glm::vec3 up);
315 EXPORT IP_Camera(glm::vec3 position,
316 glm::vec3 direction,
317 glm::vec3 up,
318 float fovy,
319 float width,
320 float height,
321 float near_plane);
322 EXPORT ~IP_Camera();
326 EXPORT void update_projection_matrix();
336 EXPORT std::vector<glm::vec3> calculate_frustum_points();
350 EXPORT std::vector<float> calculate_frustum_distance(glm::vec3 point);
351};
352
353}
354
355#endif
float far_plane
The far plane of the camera frustum.
Definition camera.h:37
void move_forward(float delta)
Move the camera along the forward vector.
Definition camera.cpp:37
void move_by(float x, float y, float z)
Move the camera by the vector (x, y, z)
Definition camera.cpp:41
float height
Viewport height.
Definition camera.h:29
glm::vec3 right
The right vector of the camera.
Definition camera.h:57
float width
Viewport width.
Definition camera.h:25
glm::mat4 view_matrix
The view matrix.
Definition camera.h:17
glm::vec3 direction
The direction the camera is pointing.
Definition camera.h:49
void pitch(float angle)
Rotate the camera using the right vector as the axis.
Definition camera.cpp:63
glm::vec3 up
The up vector of the camera.
Definition camera.h:53
void roll(float angle)
Rotate the camera using the forward vector as the axis.
Definition camera.cpp:57
glm::vec3 position
The camera position.
Definition camera.h:45
Camera(glm::vec3 position, glm::vec3 direction, glm::vec3 up)
Definition camera.cpp:5
void move_right(float delta)
Move the camera along the right vector.
Definition camera.cpp:33
float near_plane
The near plane of the camera frustum.
Definition camera.h:41
float fovy
The vertical field of view angle of the camera.
Definition camera.h:33
void update_view_matrix()
Recalculates the view matrix.
Definition camera.cpp:25
void yaw(float angle)
Rotate the camera using the up vector as the axis.
Definition camera.cpp:51
glm::mat4 projection_matrix
The perspective projection matrix.
Definition camera.h:21
void move_up(float delta)
Move the camera along the up vector.
Definition camera.cpp:29
virtual void update_projection_matrix()=0
Recalculates the projection matrix.
std::vector< glm::vec3 > calculate_frustum_points()
Calculates the corner points of the camera's frustum.
Definition camera_ip.cpp:48
std::vector< float > calculate_frustum_distance(glm::vec3 point)
Calculates the distances of a point to all planes of the camera's frustum. Positive values indicate t...
Definition camera_ip.cpp:68
void update_projection_matrix()
Recalculates the projection matrix.
Definition camera_ip.cpp:41
void update_projection_matrix()
Recalculates the projection matrix.
Definition camera_o.cpp:49
std::vector< glm::vec3 > calculate_frustum_points()
Calculates the corner points of the camera's frustum.
Definition camera_o.cpp:56
void calculate_bounding_frustum(O_Camera &camera, glm::vec3 direction, float offset)
Sets the camera parameters in such a way as to make the frustum of this camera the bounding box of th...
Definition camera_o.cpp:103
std::vector< float > calculate_frustum_distance(glm::vec3 point)
Calculates the distances of a point to all planes of the camera's frustum. Positive values indicate t...
Definition camera_o.cpp:78
Manages perspective cameras.
Definition camera.h:127
std::vector< glm::vec3 > calculate_frustum_points()
Calculates the corner points of the camera's frustum.
Definition camera_p.cpp:59
void update_projection_matrix()
Recalculates the projection matrix.
Definition camera_p.cpp:52
std::vector< float > calculate_frustum_distance(glm::vec3 point)
Calculates the distances of a point to all planes of the camera's frustum. Positive values indicate t...
Definition camera_p.cpp:83