Brenta Engine 1.2
Loading...
Searching...
No Matches
camera.hpp
1// SPDX-License-Identifier: MIT
2// Author: Giovanni Santini
3// Mail: giovanni.santini@proton.me
4// Github: @San7o
5
6#pragma once
7
8#include <glad/glad.h>
9#include <glm/glm.hpp>
10#include <glm/gtc/matrix_transform.hpp>
11
12namespace brenta
13{
14
15namespace types
16{
17
25{
26 float theta;
27 float phi;
28 float radius;
39 spherical_coordinates(float theta, float phi, float radius)
40 : theta(theta), phi(phi), radius(radius)
41 {
42 }
43};
44
52{
53 float yaw;
54 float pitch;
55 float roll;
59 euler_angles() = default;
66 euler_angles(float yaw, float pitch, float roll)
67 : yaw(yaw), pitch(pitch), roll(roll)
68 {
69 }
70};
71
72} // namespace types
73
96class camera
97{
98public:
99
100 enum class camera_type
101 {
102 aircraft,
103 spherical
104 };
105
106 enum class projection_type
107 {
108 perspective,
109 orthographic
110 };
111
119 {
120 forward,
121 backward,
122 left,
123 right
124 };
125
126 projection_type proj_type;
127 camera_type cam_type;
128 glm::vec3 position;
134 glm::vec3 world_up;
141 glm::vec3 center;
146 float mouse_sensitivity;
150 float zoom;
173 glm::vec3 front;
179 glm::vec3 up;
185 glm::vec3 right;
192 bool first_mouse = true;
196 float last_x;
200 float last_y;
201
202 class config;
203
204 // Constructors
205
211 camera() = default;
218 camera(config conf);
219
226 class builder;
227
228 // Getters
229
230 camera::camera_type get_camera_type();
231 camera::projection_type get_projection_type();
232 glm::vec3 get_position();
233 glm::vec3 get_world_up();
234 glm::vec3 get_center();
235 float get_movement_speed();
236 float get_mouse_sensitivity();
237 float get_zoom();
238 types::spherical_coordinates get_spherical_coordinates();
239 types::euler_angles get_euler_angles();
240 glm::mat4 get_view_matrix();
241 glm::mat4 get_projection_matrix(int window_width, int window_height);
242 glm::vec3 get_front();
243 glm::vec3 get_up();
244 glm::vec3 get_right();
249 bool get_first_mouse();
254 float get_last_x();
259 float get_last_y();
260
261 // Setters
262
263 void set_camera_type(camera::camera_type camera_type);
264 void set_projection_type(camera::projection_type projection_type);
265 void set_world_up(glm::vec3 world_up);
266 void set_center(glm::vec3 center);
267 void set_movement_speed(float movement_speed);
268 void set_mouse_sensitivity(float mouse_sensitivity);
269 void set_zoom(float zoom);
270 void
271 set_spherical_coordinates(types::spherical_coordinates spherical_coordinates);
272 void set_euler_angles(types::euler_angles euler_angles);
273 void set_front(glm::vec3 front);
274 void set_up(glm::vec3 up);
275 void set_right(glm::vec3 right);
276 void set_position(glm::vec3 position);
277 void set_first_mouse(bool first_mouse);
282 void set_last_x(float last_x);
287 void set_last_y(float last_y);
288
289 // Utilities
290
298 void update_camera_euler();
307};
308
310{
311 camera_type cam_type;
312 projection_type proj_type;
313 glm::vec3 position;
314 glm::vec3 world_up;
315 glm::vec3 center;
316 float movement_speed;
317 float mouse_sensitivity;
318 float zoom;
319 types::spherical_coordinates spherical_coordinates;
320 types::euler_angles euler_angles;
321 glm::vec3 front;
322 glm::vec3 up;
323 glm::vec3 right;
324};
325
330{
331private:
332
333 camera::config conf = {
334 camera::camera_type::aircraft,
335 camera::projection_type::perspective,
336 glm::vec3(0.0f, 0.0f, 0.0f),
337 glm::vec3(0.0f, 1.0f, 0.0f),
338 glm::vec3(0.0f, 0.0f, 0.0f),
339 2.5f,
340 0.1f,
341 45.0f,
342 {0.0f, 0.0f, 10.0f},
343 {0.0f, 0.0f, 0.0f},
344 glm::vec3(0.0f, 0.0f, -1.0f),
345 glm::vec3(0.0f, 1.0f, 0.0f),
346 glm::vec3(1.0f, 0.0f, 0.0f),
347 };
348
349public:
350
351 builder &camera_type(camera::camera_type camera_type);
352 builder &projection_type(camera::projection_type projection_type);
353 builder &position(glm::vec3 position);
354 builder &world_up(glm::vec3 worldUp);
355 builder &center(glm::vec3 center);
357 builder &mouse_sensitivity(float mouse_sensitivity);
358 builder &zoom(float zoom);
359 builder &
362 builder &front(glm::vec3 front);
363 builder &up(glm::vec3 up);
364 builder &right(glm::vec3 right);
365
366 camera build();
367};
368
369} // namespace brenta
Builder pattern for the Camera class.
Definition camera.hpp:330
The Camera class.
Definition camera.hpp:97
types::spherical_coordinates spherical_coordinates
Spherical coordinates.
Definition camera.hpp:159
glm::vec3 front
Front vector.
Definition camera.hpp:173
void set_last_y(float last_y)
Set the last y position of the mouse.
Definition camera.cpp:261
float last_x
Last x position of the mouse.
Definition camera.hpp:196
camera_movement
Camera movement directions.
Definition camera.hpp:119
void set_last_x(float last_x)
Set the last x position of the mouse.
Definition camera.cpp:251
glm::vec3 right
Right vector.
Definition camera.hpp:185
glm::vec3 world_up
The world up vector.
Definition camera.hpp:134
float get_last_x()
Get the last x position of the mouse.
Definition camera.cpp:246
void update_camera_euler()
Update the camera euler angles.
Definition camera.cpp:90
float movement_speed
Space translational movement speed.
Definition camera.hpp:145
bool get_first_mouse()
Get the first mouse flag.
Definition camera.cpp:236
camera()=default
Default constructor.
types::euler_angles euler_angles
Euler angles.
Definition camera.hpp:167
void spherical_to_cartesian()
Update the camera spherical coordinates.
Definition camera.cpp:74
float zoom
Zoom level (field of view)
Definition camera.hpp:150
bool first_mouse
Is the first mouse movement?
Definition camera.hpp:192
glm::vec3 center
The center of the spehere.
Definition camera.hpp:141
glm::vec3 up
Up vector.
Definition camera.hpp:179
float get_last_y()
Get the last y position of the mouse.
Definition camera.cpp:256
float last_y
Last y position of the mouse.
Definition camera.hpp:200
euler_angles(float yaw, float pitch, float roll)
Constructor.
Definition camera.hpp:66
euler_angles()=default
Default constructor.
Spherical coordinates.
Definition camera.hpp:25
spherical_coordinates(float theta, float phi, float radius)
Constructor.
Definition camera.hpp:39
spherical_coordinates()=default
Default constructor.