Brenta Engine 1.0
Loading...
Searching...
No Matches
camera.hpp
1/*
2 * MIT License
3 *
4 * Copyright (c) 2024 Giovanni Santini
5
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 all
15 * copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 * SOFTWARE.
24 *
25 */
26
27#pragma once
28
29#include <glad/glad.h>
30#include <glm/glm.hpp>
31#include <glm/gtc/matrix_transform.hpp>
32
33namespace Brenta
34{
35
36namespace Types
37{
38
45enum CameraMovement
46{
47 FORWARD,
48 BACKWARD,
49 LEFT,
50 RIGHT
51};
52
60{
61 float theta;
62 float phi;
63 float radius;
64};
65
73{
74 float yaw;
75 float pitch;
76 float roll;
77};
78
79} // namespace Types
80
81namespace Enums
82{
83
84enum CameraType
85{
86 AIRCRAFT,
87 SPHERICAL
88};
89
90enum ProjectionType
91{
92 PERSPECTIVE,
93 ORTHOGRAPHIC
94};
95
96} // namespace Enums
97
120{
121 public:
125 Enums::ProjectionType ProjectionType;
129 Enums::CameraType CameraType;
133 glm::vec3 Position;
139 glm::vec3 WorldUp;
146 glm::vec3 center;
158 float Zoom;
181 glm::vec3 Front;
187 glm::vec3 Up;
193 glm::vec3 Right;
200 bool firstMouse = true;
204 float lastX;
208 float lastY;
209
210 /* Constructors */
211
217 Camera() = default;
223 Camera(Enums::CameraType camera_type, Enums::ProjectionType projection_type,
224 glm::vec3 position, glm::vec3 worldUp, glm::vec3 center,
225 float movementSpeed, float mouseSensitivity, float zoom,
227 Types::EulerAngles eulerAngles, glm::vec3 front, glm::vec3 up,
228 glm::vec3 right);
229
236 class Builder;
237
238 /* Getters */
239
244 Enums::CameraType GetCameraType();
249 Enums::ProjectionType GetProjectionType();
254 glm::vec3 GetPosition();
259 glm::vec3 GetWorldUp();
264 glm::vec3 GetCenter();
269 float GetMovementSpeed();
274 float GetMouseSensitivity();
279 float GetZoom();
294 glm::mat4 GetViewMatrix();
299 glm::mat4 GetProjectionMatrix();
304 glm::vec3 GetFront();
309 glm::vec3 GetUp();
314 glm::vec3 GetRight();
319 bool GetFirstMouse();
324 float GetLastX();
329 float GetLastY();
330
331 /* Setters */
332
337 void SetCameraType(Enums::CameraType camera_type);
342 void SetProjectionType(Enums::ProjectionType projection_type);
347 void SetWorldUp(glm::vec3 worldUp);
352 void SetCenter(glm::vec3 center);
357 void SetMovementSpeed(float movementSpeed);
362 void SetMouseSensitivity(float mouseSensitivity);
367 void SetZoom(float zoom);
372 void
383 void SetFront(glm::vec3 front);
388 void SetUp(glm::vec3 up);
393 void SetRight(glm::vec3 right);
398 void SetPosition(glm::vec3 position);
403 void SetFirstMouse(bool firstMouse);
408 void SetLastX(float lastX);
413 void SetLastY(float lastY);
414
415 /* Utilities */
416
425 void updateCameraEuler();
435};
436
441{
442 private:
443 Enums::CameraType camera_type = Enums::CameraType::AIRCRAFT;
444 Enums::ProjectionType projection_type = Enums::ProjectionType::PERSPECTIVE;
445 glm::vec3 position = glm::vec3(0.0f, 0.0f, 0.0f);
446 glm::vec3 worldUp = glm::vec3(0.0f, 1.0f, 0.0f);
447 glm::vec3 center = glm::vec3(0.0f, 0.0f, 0.0f);
448 float movementSpeed = 2.5f;
449 float mouseSensitivity = 0.1f;
450 float zoom = 45.0f;
451 glm::vec3 front = glm::vec3(0.0f, 0.0f, -1.0f);
452 glm::vec3 up = glm::vec3(0.0f, 1.0f, 0.0f);
453 glm::vec3 right = glm::vec3(1.0f, 0.0f, 0.0f);
454 Types::SphericalCoordinates sphericalCoordinates = {0.0f, 0.0f, 10.0f};
455 Types::EulerAngles eulerAngles = {0.0f, 0.0f, 0.0f};
456
457 public:
458 Builder &set_camera_type(Enums::CameraType camera_type);
459 Builder &set_projection_type(Enums::ProjectionType projection_type);
460 Builder &set_position(glm::vec3 position);
461 Builder &set_world_up(glm::vec3 worldUp);
462 Builder &set_center(glm::vec3 center);
463 Builder &set_movement_speed(float movementSpeed);
464 Builder &set_mouse_sensitivity(float mouseSensitivity);
465 Builder &set_zoom(float zoom);
466 Builder &
467 set_spherical_coordinates(Types::SphericalCoordinates sphericalCoordinates);
468 Builder &set_eulerAngles(Types::EulerAngles eulerAngles);
469 Builder &set_front(glm::vec3 front);
470 Builder &set_up(glm::vec3 up);
471 Builder &set_right(glm::vec3 right);
472
473 Camera build();
474};
475
481extern Camera camera;
482
483} // namespace Brenta
Builder pattern for the Camera class.
Definition camera.hpp:441
The Camera class.
Definition camera.hpp:120
glm::vec3 Position
Camera position.
Definition camera.hpp:133
Types::EulerAngles GetEulerAngles()
Get the euler angles of the camera.
Definition camera.cpp:226
Types::SphericalCoordinates GetSphericalCoordinates()
Get the spherical coordinates of the camera.
Definition camera.cpp:215
Types::SphericalCoordinates sphericalCoordinates
Spherical coordinates.
Definition camera.hpp:167
float GetLastX()
Get the last x position of the mouse.
Definition camera.cpp:276
float lastX
Last x position of the mouse.
Definition camera.hpp:204
void updateCameraEuler()
Update the camera euler angles.
Definition camera.cpp:120
float MouseSensitivity
Mouse sensitivity.
Definition camera.hpp:154
Enums::ProjectionType GetProjectionType()
Get the projection type.
Definition camera.cpp:145
void SetZoom(float zoom)
Set the zoom level.
Definition camera.cpp:210
Enums::CameraType GetCameraType()
Get the camera type.
Definition camera.cpp:135
void SetMovementSpeed(float movementSpeed)
Set the movement speed.
Definition camera.cpp:190
float GetZoom()
Get the zoom level.
Definition camera.cpp:205
glm::vec3 WorldUp
The world up vector.
Definition camera.hpp:139
void SetPosition(glm::vec3 position)
Set the position of the camera.
Definition camera.cpp:160
void SetLastY(float lastY)
Set the last y position of the mouse.
Definition camera.cpp:291
void SetCameraType(Enums::CameraType camera_type)
Set the camera type.
Definition camera.cpp:140
glm::vec3 GetRight()
Get the right vector.
Definition camera.cpp:256
float lastY
Last y position of the mouse.
Definition camera.hpp:208
Types::EulerAngles eulerAngles
Euler angles.
Definition camera.hpp:175
glm::vec3 GetPosition()
Get the position of the camera.
Definition camera.cpp:155
float GetMovementSpeed()
Get the movement speed.
Definition camera.cpp:185
float GetLastY()
Get the last y position of the mouse.
Definition camera.cpp:286
float MovementSpeed
Space translational movement speed.
Definition camera.hpp:150
bool firstMouse
Is the first mouse movement?
Definition camera.hpp:200
void SetRight(glm::vec3 right)
Set the right vector.
Definition camera.cpp:261
void SetEulerAngles(Types::EulerAngles eulerAngles)
Set the euler angles of the camera.
Definition camera.cpp:231
glm::vec3 GetCenter()
Get the center of the sphere.
Definition camera.cpp:175
void SetWorldUp(glm::vec3 worldUp)
Set the world up vector.
Definition camera.cpp:170
void SetLastX(float lastX)
Set the last x position of the mouse.
Definition camera.cpp:281
void SetCenter(glm::vec3 center)
Set the center of the sphere.
Definition camera.cpp:180
void SetProjectionType(Enums::ProjectionType projection_type)
Set the projection type.
Definition camera.cpp:150
float Zoom
Zoom level (field of view)
Definition camera.hpp:158
float GetMouseSensitivity()
Get the mouse sensitivity.
Definition camera.cpp:195
glm::vec3 Up
Up vector.
Definition camera.hpp:187
Enums::CameraType CameraType
Camera type.
Definition camera.hpp:129
Camera()=default
Default constructor.
glm::mat4 GetProjectionMatrix()
Get the projection matrix.
Definition camera.cpp:88
void SetFirstMouse(bool firstMouse)
Set the first mouse flag.
Definition camera.cpp:271
void SetUp(glm::vec3 up)
Set the up vector.
Definition camera.cpp:251
glm::vec3 Front
Front vector.
Definition camera.hpp:181
void SetSphericalCoordinates(Types::SphericalCoordinates sphericalCoordinates)
Set the spherical coordinates of the camera.
Definition camera.cpp:220
glm::vec3 GetWorldUp()
Get the world up vector.
Definition camera.cpp:165
glm::vec3 Right
Right vector.
Definition camera.hpp:193
void SetMouseSensitivity(float mouseSensitivity)
Set the mouse sensitivity.
Definition camera.cpp:200
bool GetFirstMouse()
Get the first mouse flag.
Definition camera.cpp:266
void SetFront(glm::vec3 front)
Set the front vector.
Definition camera.cpp:241
glm::vec3 GetFront()
Get the front vector.
Definition camera.cpp:236
glm::vec3 center
The center of the spehere.
Definition camera.hpp:146
Enums::ProjectionType ProjectionType
Projection type.
Definition camera.hpp:125
void SphericalToCartesian()
Update the camera spherical coordinates.
Definition camera.cpp:107
glm::vec3 GetUp()
Get the up vector.
Definition camera.cpp:246
glm::mat4 GetViewMatrix()
Get the view matrix.
Definition camera.cpp:75
Spherical coordinates.
Definition camera.hpp:60