Nameless Engine
Loading...
Searching...
No Matches
CameraProperties.h
1#pragma once
2
3// Standard.
4#include <mutex>
5#include <optional>
6
7// Custom.
8#include "math/GLMath.hpp"
9#include "misc/Globals.h"
10#include "misc/shapes/Frustum.h"
11
12namespace ne {
14 enum class CameraMode {
15 FREE,
16 ORBITAL
19 };
20
23 // Only camera node can control internal data.
24 friend class CameraNode;
25
26 // Renderer sets render target size and also looks if projection matrix was changed or
27 // not to recalculate grid of frustums for light culling.
28 friend class Renderer;
29
30 public:
31 CameraProperties() = default;
32
34 struct Data {
35 Data() = default;
36
39 OrbitalModeData() = default;
40
42 float distanceToTarget = 10.0F; // NOLINT: magic number
43
45 float theta = 0.0F; // NOLINT: magic number
46
48 float phi = 0.0F; // NOLINT: magic number
49 };
50
52 struct ViewData {
53 ViewData() = default;
54
56 glm::mat4x4 viewMatrix = glm::identity<glm::mat4x4>();
57
60
62 glm::vec3 worldLocation = glm::vec3(0.0F, 0.0F, 0.0F);
63
66
68 glm::vec3 targetPointWorldLocation = glm::vec3(1.0F, 0.0F, 0.0F);
69 };
70
73 ProjectionData() = default;
74
79 glm::mat4x4 projectionMatrix = glm::identity<glm::mat4x4>();
80
83
92
94 float nearClipPlaneDistance = 0.3F; // NOLINT: magic number
95
97 float farClipPlaneDistance = 500.0F; // NOLINT: good default value
98
100 unsigned int iVerticalFov = 90; // NOLINT: magic number
101
103 unsigned int iRenderTargetWidth = 800; // NOLINT: default value
104
106 unsigned int iRenderTargetHeight = 600; // NOLINT: default value
107
110
112 float farClipPlaneHeight = 0.0F;
113 };
114
122
132
135
137 CameraMode currentCameraMode = CameraMode::FREE;
138
141
143 static inline const float minimumClipPlaneDistance = 0.00001F;
144 };
145
151 void setFov(unsigned int iVerticalFov);
152
158 void setNearClipPlaneDistance(float nearClipPlaneDistance);
159
165 void setFarClipPlaneDistance(float farClipPlaneDistance);
166
172 unsigned int getVerticalFov();
173
180
187
193 CameraMode getCurrentCameraMode();
194
201
207 glm::vec3 getWorldLocation();
208
214 glm::mat4x4 getViewMatrix();
215
222 glm::mat4x4 getProjectionMatrix();
223
237 inline Frustum* getCameraFrustum() { return &mtxData.second.frustum; }
238
239 private:
250 void setRenderTargetSize(unsigned int iRenderTargetWidth, unsigned int iRenderTargetHeight);
251
258
265
271 void recalculateFrustum();
272
274 std::pair<std::recursive_mutex, Data> mtxData{};
275
277 static inline constexpr float floatDelta = 0.00001F;
278 };
279} // namespace ne
Definition: CameraNode.h:11
Definition: CameraProperties.h:22
Data::OrbitalModeData getOrbitalModeProperties()
Definition: CameraProperties.cpp:104
glm::mat4x4 getViewMatrix()
Definition: CameraProperties.cpp:114
void setFov(unsigned int iVerticalFov)
Definition: CameraProperties.cpp:30
float getFarClipPlaneDistance()
Definition: CameraProperties.cpp:92
void makeSureViewMatrixIsUpToDate()
Definition: CameraProperties.cpp:130
std::pair< std::recursive_mutex, Data > mtxData
Definition: CameraProperties.h:274
void makeSureProjectionMatrixAndClipPlanesAreUpToDate()
Definition: CameraProperties.cpp:153
void setRenderTargetSize(unsigned int iRenderTargetWidth, unsigned int iRenderTargetHeight)
Definition: CameraProperties.cpp:13
Frustum * getCameraFrustum()
Definition: CameraProperties.h:237
glm::vec3 getWorldLocation()
Definition: CameraProperties.cpp:109
static constexpr float floatDelta
Definition: CameraProperties.h:277
void setFarClipPlaneDistance(float farClipPlaneDistance)
Definition: CameraProperties.cpp:60
CameraMode getCurrentCameraMode()
Definition: CameraProperties.cpp:98
void recalculateFrustum()
Definition: CameraProperties.cpp:196
glm::mat4x4 getProjectionMatrix()
Definition: CameraProperties.cpp:122
unsigned int getVerticalFov()
Definition: CameraProperties.cpp:80
float getNearClipPlaneDistance()
Definition: CameraProperties.cpp:86
void setNearClipPlaneDistance(float nearClipPlaneDistance)
Definition: CameraProperties.cpp:40
Definition: Renderer.h:43
Definition: CameraProperties.h:38
float theta
Definition: CameraProperties.h:45
float phi
Definition: CameraProperties.h:48
float distanceToTarget
Definition: CameraProperties.h:42
Definition: CameraProperties.h:72
float nearClipPlaneHeight
Definition: CameraProperties.h:109
bool bProjectionMatrixNeedsUpdate
Definition: CameraProperties.h:82
glm::mat4x4 projectionMatrix
Definition: CameraProperties.h:79
bool bLightGridFrustumsNeedUpdate
Definition: CameraProperties.h:91
float nearClipPlaneDistance
Definition: CameraProperties.h:94
unsigned int iRenderTargetHeight
Definition: CameraProperties.h:106
unsigned int iVerticalFov
Definition: CameraProperties.h:100
unsigned int iRenderTargetWidth
Definition: CameraProperties.h:103
float farClipPlaneDistance
Definition: CameraProperties.h:97
float farClipPlaneHeight
Definition: CameraProperties.h:112
Definition: CameraProperties.h:52
glm::mat4x4 viewMatrix
Definition: CameraProperties.h:56
glm::vec3 worldUpDirection
Definition: CameraProperties.h:65
glm::vec3 worldLocation
Definition: CameraProperties.h:62
glm::vec3 targetPointWorldLocation
Definition: CameraProperties.h:68
bool bViewMatrixNeedsUpdate
Definition: CameraProperties.h:59
Definition: CameraProperties.h:34
Frustum frustum
Definition: CameraProperties.h:134
OrbitalModeData orbitalModeData
Definition: CameraProperties.h:140
ProjectionData projectionData
Definition: CameraProperties.h:131
static const float minimumClipPlaneDistance
Definition: CameraProperties.h:143
ViewData viewData
Definition: CameraProperties.h:121
CameraMode currentCameraMode
Definition: CameraProperties.h:137
Definition: Frustum.h:12
static const glm::vec3 up
Definition: Globals.h:19