Oxygen Engine
Modern C++ 3D Engine using OpenGL
Loading...
Searching...
No Matches
camera.h
1#ifndef OE_SCENE_CAMERA_H
2#define OE_SCENE_CAMERA_H
3
4#include "../common.h"
5
6#include <glm/mat4x4.hpp>
7#include "transform.h"
8
9#include "camera_projections.h"
10
11namespace oe::scene
12{
13 class AABB;
14 class Window;
15
32 class Camera : public Transform
33 {
34 public:
40 template <CameraProjection ProjectionSettings>
41 Camera(const ProjectionSettings& projection_settings)
42 {
43 setProjectionSettings(projection_settings);
44 }
45
51 template <CameraProjection ProjectionSettings>
52 void setProjectionSettings(const ProjectionSettings& projection_settings)
53 {
54 _projection = projection_settings.getProjectionMatrix();
55 _is_dirty = true;
56 }
57
63 void lookAt(const glm::vec3& target);
64
71 bool isInFrustum(const glm::vec3& point) const;
72
80 bool isInFrustum(const glm::vec3& center, const float& radius) const;
81
88 bool isInFrustum(const AABB& box) const;
89
95 const glm::mat4& getView() const;
96
102 const glm::mat4& getProjection() const;
103
104 const glm::mat4& getInverseView() const;
105 const glm::mat4& getInverseProjection() const;
106
114 const glm::mat4& getTransform() const noexcept;
115 const glm::mat4& getInverseTransform() const noexcept;
116
117 float getPitch() const noexcept
118 {
119 return _pitch;
120 }
121
122 float getYaw() const noexcept
123 {
124 return _yaw;
125 }
126
127 float getRoll() const noexcept
128 {
129 return _roll;
130 }
131
132 void setPitch(const float pitch);
133 void setYaw(const float yaw);
134 void setRoll(const float roll);
135
136 inline bool isDirty() const
137 {
138 return Transform::isDirty() || _is_dirty;
139 }
140
141 private:
142 mutable bool _is_dirty = true;
143
145 float _pitch = 0.f;
146
148 float _yaw = 0.f;
149
151 float _roll = 0.f;
152
153 mutable glm::mat4 _view{1.0f};
154 mutable glm::mat4 _projection{1.0f};
155
156 mutable glm::mat4 _inv_view{1.0f};
157 mutable glm::mat4 _inv_projection{1.0f};
158
159 mutable glm::mat4 _transform{1.0f};
160 mutable glm::mat4 _inv_transform{1.0f};
161
162 mutable glm::vec4 _frustum_planes[6];
163 mutable glm::vec3 _frustum_points[8];
164
165 void _recompute_rotation();
166 void _recompute_matrices() const;
167
168 };
169}
170
171#endif
Axis-aligned bounding box.
Definition aabb.h:13
The "eye of the scene".
Definition camera.h:33
Camera(const ProjectionSettings &projection_settings)
Constructor.
Definition camera.h:41
void setProjectionSettings(const ProjectionSettings &projection_settings)
Update the camera's projection matrix by recomputing it based on the provided settings.
Definition camera.h:52
const glm::mat4 & getProjection() const
Get the projection matrix of the camera.
bool isInFrustum(const glm::vec3 &point) const
Check if a point is visible from the camera point of view.
const glm::mat4 & getView() const
Get the view matrix of the camera.
bool isInFrustum(const AABB &box) const
Check if a AABB is visible from the camera point of view.
const glm::mat4 & getTransform() const noexcept
Get the transformation matrix of the camera.
bool isInFrustum(const glm::vec3 &center, const float &radius) const
Check if a sphere is visible from the camera point of view.
void lookAt(const glm::vec3 &target)
Orient the camera to stare at a specified target.
Manage local Translation / Rotation / Scale of an entity in the world.
Definition transform.h:20
bool isDirty() const
Check if something modified this transform.
Definition transform.h:364
Scene related management (Render-agnostic Geometry, Manger, etc...)
Definition debug.h:19