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 <glm/mat4x4.hpp>
5#include "transform.h"
6
7#include "camera_projections.h"
8
9namespace oe::scene
10{
11 class AABB;
12 class Window;
13
30 class Camera : public Transform
31 {
32 public:
38 template <CameraProjection ProjectionSettings>
39 Camera(const ProjectionSettings& projection_settings)
40 {
41 setProjectionSettings(projection_settings);
42 }
43
49 template <CameraProjection ProjectionSettings>
50 void setProjectionSettings(const ProjectionSettings& projection_settings)
51 {
52 _projection = projection_settings.getProjectionMatrix();
53 _is_dirty = true;
54 }
55
61 void lookAt(const glm::vec3& target);
62
69 bool isInFrustum(const glm::vec3& point) const;
70
78 bool isInFrustum(const glm::vec3& center, const float& radius) const;
79
86 bool isInFrustum(const AABB& box) const;
87
93 const glm::mat4& getView() const;
94
100 const glm::mat4& getProjection() const;
101
102 const glm::mat4& getInverseView() const;
103 const glm::mat4& getInverseProjection() const;
104
112 const glm::mat4& getTransform() const noexcept;
113 const glm::mat4& getInverseTransform() const noexcept;
114
115 float getPitch() const noexcept
116 {
117 return _pitch;
118 }
119
120 float getYaw() const noexcept
121 {
122 return _yaw;
123 }
124
125 float getRoll() const noexcept
126 {
127 return _roll;
128 }
129
130 void setPitch(const float pitch);
131 void setYaw(const float yaw);
132 void setRoll(const float roll);
133
134 inline bool isDirty() const
135 {
136 return Transform::isDirty() || _is_dirty;
137 }
138
139 private:
140 mutable bool _is_dirty = true;
141
143 float _pitch = 0.f;
144
146 float _yaw = 0.f;
147
149 float _roll = 0.f;
150
151 mutable glm::mat4 _view{1.0f};
152 mutable glm::mat4 _projection{1.0f};
153
154 mutable glm::mat4 _inv_view{1.0f};
155 mutable glm::mat4 _inv_projection{1.0f};
156
157 mutable glm::mat4 _transform{1.0f};
158 mutable glm::mat4 _inv_transform{1.0f};
159
160 mutable glm::vec4 _frustum_planes[6];
161 mutable glm::vec3 _frustum_points[8];
162
163 void _recompute_rotation();
164 void _recompute_matrices() const;
165
166 };
167}
168
169#endif
Axis-aligned bounding box.
Definition aabb.h:13
Camera(const ProjectionSettings &projection_settings)
Constructor.
Definition camera.h:39
void setProjectionSettings(const ProjectionSettings &projection_settings)
Update the camera's projection matrix by recomputing it based on the provided settings.
Definition camera.h:50
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.
Transform(const glm::vec3 &translation=glm::vec3(0.f), const glm::quat &rotation=glm::quat(1.f, 0.f, 0.f, 0.f), const glm::vec3 &scale=glm::vec3(1.f), const glm::vec3 &skew=glm::vec3(0.f), const glm::vec4 &perspective=glm::vec4(glm::vec3(0.f), 1.f))
Generate Transform from its translation, rotation, scale values.
Definition transform.h:76
bool isDirty() const noexcept
Check if something modified this transform.
Definition transform.h:528
Scene related management (Render-agnostic Geometry, Manger, etc...).
Definition debug.h:19