Rendering Engine 0.2.0
Modular Graphics Rendering Engine | v0.2.0
Loading...
Searching...
No Matches
camera.hpp
Go to the documentation of this file.
1// This file is part of the Rendering Engine project.
2// Author: Alexander Obzherin <alexanderobzherin@gmail.com>
3// Copyright (c) 2025 Alexander Obzherin
4// Distributed under the terms of the zlib License. See LICENSE.md for details.
5
6#pragma once
7
8#include <glm/vec4.hpp>
9#include <glm/mat4x4.hpp>
10#include <glm/matrix.hpp>
11#include <glm/glm.hpp>
12#include <glm/gtc/matrix_transform.hpp>
13#include <memory>
16
17namespace rendering_engine
18{
19class IApplication;
20class SceneComponent;
21
22/**
23 * @class Camera
24 * @brief Represents a 3D perspective camera with world transform and projection settings.
25 *
26 * The Camera defines the viewpoint in the 3D scene, including position and orientation (via a SceneComponent)
27 * and projection parameters (field of view, aspect ratio, near/far planes). The camera supports standard
28 * view matrix construction using GLM and can be subclassed for additional camera types (third-person, orbit, etc).
29 *
30 * @section CoordinateSystem Coordinate System
31 * The rendering engine uses a left-handed coordinate system:
32 * - X+ : Forward (world forward direction)
33 * - Y+ : Right
34 * - Z+ : Up
35 * See @ref rendering_engine::axes for axis definitions.
36 *
37 * By default, the camera looks along the world Y+ direction after Reset().
38 *
39 * @note
40 * - Angles (Euler) are in degrees, matching typical editor/engine conventions.
41 * - The camera transform is provided by a SceneComponent.
42 * - The camera generates a perspective projection matrix using a vertical field of view.
43 *
44 * @see rendering_engine::SceneComponent
45 * @see rendering_engine::axes
46 */
48{
49public:
50 /**
51 * @brief Constructs a camera for the given application context.
52 * @param app Reference to the IApplication (for screen settings, etc.).
53 */
54 Camera(IApplication& app);
55
56 /**
57 * @brief Virtual destructor.
58 */
59 virtual ~Camera() = default;
60
61 /**
62 * @brief Initializes camera parameters and matrices.
63 */
64 virtual void Initialize();
65
66 /**
67 * @brief Updates camera logic, recalculates view/projection matrices as needed.
68 * @param deltaTime Elapsed time since last update (seconds).
69 */
70 virtual void Update(float deltaTime);
71
72 /**
73 * @brief Sets the camera position in world space.
74 * @param position New position (glm::vec3).
75 */
76 void SetPosition(const glm::vec3& position);
77
78 /**
79 * @brief Sets the camera rotation via quaternion.
80 * @param rotation New rotation (glm::quat).
81 */
82 void SetRotation(const glm::quat& rotation);
83
84 /**
85 * @brief Sets the camera rotation via Euler angles (degrees).
86 * @param rotation Euler angles (pitch, yaw, roll), in degrees.
87 */
88 void SetRotation(const glm::vec3& rotation);
89
90 /**
91 * @brief Gets the camera position.
92 */
93 glm::vec3 GetPosition() const;
94
95 /**
96 * @brief Gets the camera rotation as a quaternion.
97 */
98 glm::quat GetRotationQuat() const;
99
100 /**
101 * @brief Gets the camera rotation as Euler angles (degrees).
102 */
103 glm::vec3 GetRotation() const;
104
105 /**
106 * @brief Gets the camera's forward direction vector.
107 */
108 glm::vec3 GetForward() const;
109
110 /**
111 * @brief Gets the camera's up direction vector.
112 */
113 glm::vec3 GetUp() const;
114
115 /**
116 * @brief Gets the camera's right direction vector.
117 */
118 glm::vec3 GetRight() const;
119
120 /**
121 * @brief Gets the camera view matrix.
122 */
123 const glm::mat4& ViewMatrix() const;
124
125 /**
126 * @brief Gets the camera projection matrix.
127 */
128 const glm::mat4& ProjectionMatrix() const;
129
130 /**
131 * @brief Gets the combined view-projection matrix.
132 */
133 glm::mat4 ViewProjectionMatrix() const;
134
135 /**
136 * @brief Resets the camera to the default position and rotation.
137 */
138 void Reset();
139
140 /**
141 * @brief Updates the camera's projection matrix (based on FOV, aspect, near/far).
142 */
144
145 /**
146 * @brief Updates the camera's view matrix (based on position/orientation).
147 */
148 void UpdateViewMatrix();
149
150 Camera(const Camera& rhs) = delete;
151 Camera& operator=(const Camera& rhs) = delete;
152
153protected:
155
156 std::unique_ptr<SceneComponent> mSceneComponent;
157
158 glm::mat4 mViewMatrix;
160
161 static const float sDefaultFieldOfView;
162 static const float sDefaultAspectRatio;
163 static const float sDefaultNearPlaneDistance;
164 static const float sDefaultFarPlaneDistance;
165
170};
171} //rendering_engine
glm::vec3 GetForward() const
Gets the camera's forward direction vector.
Definition camera.cpp:59
const glm::mat4 & ViewMatrix() const
Gets the camera view matrix.
Definition camera.cpp:71
static const float sDefaultAspectRatio
Definition camera.hpp:162
IApplication & mApp
Definition camera.hpp:154
glm::quat GetRotationQuat() const
Gets the camera rotation as a quaternion.
Definition camera.cpp:51
virtual void Initialize()
Initializes camera parameters and matrices.
Definition camera.cpp:24
const glm::mat4 & ProjectionMatrix() const
Gets the camera projection matrix.
Definition camera.cpp:75
void SetRotation(const glm::quat &rotation)
Sets the camera rotation via quaternion.
Definition camera.cpp:39
glm::vec3 GetPosition() const
Gets the camera position.
Definition camera.cpp:47
virtual ~Camera()=default
Virtual destructor.
Camera(const Camera &rhs)=delete
static const float sDefaultFarPlaneDistance
Definition camera.hpp:164
Camera & operator=(const Camera &rhs)=delete
glm::vec3 GetUp() const
Gets the camera's up direction vector.
Definition camera.cpp:63
glm::vec3 GetRight() const
Gets the camera's right direction vector.
Definition camera.cpp:67
static const float sDefaultFieldOfView
Definition camera.hpp:161
void SetPosition(const glm::vec3 &position)
Sets the camera position in world space.
Definition camera.cpp:35
std::unique_ptr< SceneComponent > mSceneComponent
Definition camera.hpp:156
glm::mat4 ViewProjectionMatrix() const
Gets the combined view-projection matrix.
Definition camera.cpp:79
glm::mat4 mProjectionMatrix
Definition camera.hpp:159
static const float sDefaultNearPlaneDistance
Definition camera.hpp:163
void Reset()
Resets the camera to the default position and rotation.
Definition camera.cpp:83
Camera(IApplication &app)
Constructs a camera for the given application context.
Definition camera.cpp:12
void UpdateProjectionMatrix()
Updates the camera's projection matrix (based on FOV, aspect, near/far).
Definition camera.cpp:89
virtual void Update(float deltaTime)
Updates camera logic, recalculates view/projection matrices as needed.
Definition camera.cpp:30
glm::vec3 GetRotation() const
Gets the camera rotation as Euler angles (degrees).
Definition camera.cpp:55
void UpdateViewMatrix()
Updates the camera's view matrix (based on position/orientation).
Definition camera.cpp:95
Defines a generic application interface for rendering-based programs.
Represents a 3D transformable scene component with position, rotation, and scale.
#define RE_API