Vulkan Schnee 0.0.1 (22840dc8)
High-performance rendering engine
Loading...
Searching...
No Matches
CameraComponent.h
1#pragma once
2#include "Engine/Component/LogicComponent.h"
3#include "SceneComponent.h"
4
5#include <glm/glm.hpp>
6#include <memory>
7
8namespace Engine::Components {
13 class Camera : public Logic {
14 public:
15 static constexpr bool IsUnique = true;
16 static constexpr const char* ComponentName = "Camera";
17
26 Camera(Entities::Scene* owningScene,
27 std::shared_ptr<Entities::SceneNode> sceneNode,
28 float fov = 60.0f,
29 float nearPlane = 0.01f,
30 float farPlane = 1000.0f);
31
35 ~Camera() override = default;
36
37 void beginPlay() override;
38 void tick(double deltaTime) override;
39 void endPlay() override;
40
41 bool drawImGui() override;
42
47 void setActive(bool active);
48
53 [[nodiscard]] bool isActive() const;
54
59 [[nodiscard]] virtual glm::mat4 getViewMatrix() const;
60
65 [[nodiscard]] virtual glm::mat4 getProjectionMatrix() const;
66
71 [[nodiscard]] virtual glm::mat4 getEyeViewMatrix(size_t eyeIndex) const;
72
77 [[nodiscard]] virtual glm::mat4 getEyeProjectionMatrix(size_t eyeIndex) const;
78
83 [[nodiscard]] glm::mat4 getViewProjectionMatrix() const;
84
89 void setFov(float fov);
90
95 [[nodiscard]] float getFov() const { return fov_; }
96
101 void setAspectRatio(float aspectRatio);
102
107 [[nodiscard]] float getAspectRatio() const { return aspectRatio_; }
108
113 void setNearPlane(float nearPlane);
114
119 [[nodiscard]] float getNearPlane() const { return nearPlane_; }
120
125 void setFarPlane(float farPlane);
126
131 [[nodiscard]] float getFarPlane() const { return farPlane_; }
132
137 [[nodiscard]] glm::vec3 getWorldPosition() const;
138
143 [[nodiscard]] glm::vec3 getForwardVector() const;
144
149 [[nodiscard]] glm::vec3 getRightVector() const;
150
155 [[nodiscard]] glm::vec3 getUpVector() const;
156
161 [[nodiscard]] std::shared_ptr<Entities::SceneNode> getSceneNode() const { return sceneNode_; }
162
163 private:
165
166 std::shared_ptr<Entities::SceneNode> sceneNode_;
167 entt::entity cameraEntity_ = entt::null;
168
169 float fov_;
172 float aspectRatio_ = 16.0f / 9.0f;
173
174 mutable glm::mat4 cachedProjectionMatrix_{1.0f};
175 bool projectionDirty_ = true;
176 };
177
183
189}
A camera component that provides view and projection matrices based on its SceneNode transform....
void tick(double deltaTime) override
Called every frame if ticking is enabled.
std::shared_ptr< Entities::SceneNode > getSceneNode() const
Gets the scene node associated with this camera.
virtual glm::mat4 getViewMatrix() const
Gets the view matrix computed from the camera's world transform.
virtual glm::mat4 getEyeViewMatrix(size_t eyeIndex) const
Gets the view matrix for a specific eye. Base returns getViewMatrix() for both (mono).
static constexpr bool IsUnique
Only one camera component is allowed per entity.
void setAspectRatio(float aspectRatio)
Sets the aspect ratio (width / height)
void setActive(bool active)
Sets this camera as the active camera for rendering.
glm::vec3 getRightVector() const
Gets the right direction vector of the camera.
float getNearPlane() const
Gets the near clipping plane distance.
void setFov(float fov)
Sets the vertical field of view.
glm::vec3 getWorldPosition() const
Gets the camera's world position from its scene node.
void endPlay() override
Called when the component is removed or the game ends.
float getFarPlane() const
Gets the far clipping plane distance.
Camera(Entities::Scene *owningScene, std::shared_ptr< Entities::SceneNode > sceneNode, float fov=60.0f, float nearPlane=0.01f, float farPlane=1000.0f)
Constructs a camera component with default parameters.
glm::vec3 getUpVector() const
Gets the up direction vector of the camera.
std::shared_ptr< Entities::SceneNode > sceneNode_
virtual glm::mat4 getProjectionMatrix() const
Gets the projection matrix based on FOV, aspect ratio, and clipping planes.
glm::vec3 getForwardVector() const
Gets the forward direction vector of the camera.
~Camera() override=default
Destroys the camera component.
void setNearPlane(float nearPlane)
Sets the near clipping plane distance.
bool isActive() const
Checks if this camera is currently the active camera.
virtual glm::mat4 getEyeProjectionMatrix(size_t eyeIndex) const
Gets the projection matrix for a specific eye. Base returns getProjectionMatrix() for both (mono).
void setFarPlane(float farPlane)
Sets the far clipping plane distance.
static constexpr const char * ComponentName
Component registry name.
void beginPlay() override
Called when the component is added to the scene or the game starts.
glm::mat4 getViewProjectionMatrix() const
Gets the combined view-projection matrix.
float getFov() const
Gets the vertical field of view.
float getAspectRatio() const
Gets the aspect ratio.
bool drawImGui() override
Draws component-specific ImGui inspector controls.
Logic(Entities::Scene *owningScene)
Constructs a logic component owned by a scene.
Owns scene entities, actor lifetime, and the scene graph root.
Definition Scene.h:84
bool hasActiveCamera()
Checks if there is an active camera set.
Camera * getActiveCamera()
Gets the currently active camera.