Vulkan Schnee 0.0.1
High-performance rendering engine
Loading...
Searching...
No Matches
CameraComponent.h
Go to the documentation of this file.
1#pragma once
3#include <entt/entt.hpp>
4#include <glm/glm.hpp>
5#include <memory>
6
7namespace EngineCore {
8 class SceneNode;
9
18 public:
19 static constexpr bool IsUnique = true; // Only one camera per entity
20
29 CameraComponent(Scene* owningScene,
30 std::shared_ptr<SceneNode> sceneNode,
31 float fov = 60.0f,
32 float nearPlane = 0.01f,
33 float farPlane = 1000.0f);
34
35 ~CameraComponent() override = default;
36
37 void beginPlay() override;
38 void tick(double deltaTime) override;
39 void endPlay() override;
40
45 void setActive(bool active);
46
51 [[nodiscard]] bool isActive() const;
52
57 [[nodiscard]] glm::mat4 getViewMatrix() const;
58
63 [[nodiscard]] glm::mat4 getProjectionMatrix() const;
64
69 [[nodiscard]] glm::mat4 getViewProjectionMatrix() const;
70
75 void setFov(float fov);
76
81 [[nodiscard]] float getFov() const { return fov_; }
82
87 void setAspectRatio(float aspectRatio);
88
93 [[nodiscard]] float getAspectRatio() const { return aspectRatio_; }
94
99 void setNearPlane(float nearPlane);
100
105 [[nodiscard]] float getNearPlane() const { return nearPlane_; }
106
111 void setFarPlane(float farPlane);
112
117 [[nodiscard]] float getFarPlane() const { return farPlane_; }
118
123 [[nodiscard]] glm::vec3 getWorldPosition() const;
124
129 [[nodiscard]] glm::vec3 getForwardVector() const;
130
135 [[nodiscard]] glm::vec3 getRightVector() const;
136
141 [[nodiscard]] glm::vec3 getUpVector() const;
142
147 [[nodiscard]] std::shared_ptr<SceneNode> getSceneNode() const { return sceneNode_; }
148
149 private:
151
152 std::shared_ptr<SceneNode> sceneNode_;
153 entt::entity cameraEntity_ = entt::null;
154
155 float fov_;
158 float aspectRatio_ = 16.0f / 9.0f;
159
160 mutable glm::mat4 cachedProjectionMatrix_{1.0f};
161 bool projectionDirty_ = true;
162 };
163
169
174 bool hasActiveCamera();
175}
A camera component that provides view and projection matrices based on its SceneNode transform....
void endPlay() override
Called when the component is removed or the game ends.
bool isActive() const
Checks if this camera is currently the active camera.
void setAspectRatio(float aspectRatio)
Sets the aspect ratio (width / height)
glm::vec3 getForwardVector() const
Gets the forward direction vector of the camera.
glm::mat4 getProjectionMatrix() const
Gets the projection matrix based on FOV, aspect ratio, and clipping planes.
CameraComponent(Scene *owningScene, std::shared_ptr< SceneNode > sceneNode, float fov=60.0f, float nearPlane=0.01f, float farPlane=1000.0f)
Constructs a camera component with default parameters.
~CameraComponent() override=default
glm::mat4 getViewProjectionMatrix() const
Gets the combined view-projection matrix.
glm::vec3 getWorldPosition() const
Gets the camera's world position from its scene node.
glm::vec3 getUpVector() const
Gets the up direction vector of the camera.
glm::vec3 getRightVector() const
Gets the right direction vector of the camera.
void setActive(bool active)
Sets this camera as the active camera for rendering.
float getAspectRatio() const
Gets the aspect ratio.
glm::mat4 getViewMatrix() const
Gets the view matrix computed from the camera's world transform.
void setFov(float fov)
Sets the vertical field of view.
void tick(double deltaTime) override
Called every frame if ticking is enabled.
float getFarPlane() const
Gets the far clipping plane distance.
float getFov() const
Gets the vertical field of view.
void beginPlay() override
Called when the component is added to the scene or the game starts.
static constexpr bool IsUnique
float getNearPlane() const
Gets the near clipping plane distance.
std::shared_ptr< SceneNode > getSceneNode() const
Gets the scene node associated with this camera.
void setNearPlane(float nearPlane)
Sets the near clipping plane distance.
std::shared_ptr< SceneNode > sceneNode_
void setFarPlane(float farPlane)
Sets the far clipping plane distance.
LogicComponent(Scene *owningScene)
Represents a node in the scene graph, containing information about its position, rotation,...
Definition SceneGraph.h:24
A scene is the overarching structure which can spawn actors.
Definition Scene.h:17
Log category system implementation.
bool hasActiveCamera()
Checks if there is an active camera set.
CameraComponent * getActiveCamera()
Gets the currently active camera.