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 "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; // Only one camera per entity
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
32 ~Camera() override = default;
33
34 void beginPlay() override;
35 void tick(double deltaTime) override;
36 void endPlay() override;
37
42 void setActive(bool active);
43
48 [[nodiscard]] bool isActive() const;
49
54 [[nodiscard]] virtual glm::mat4 getViewMatrix() const;
55
60 [[nodiscard]] virtual glm::mat4 getProjectionMatrix() const;
61
66 [[nodiscard]] virtual glm::mat4 getEyeViewMatrix(size_t eyeIndex) const;
67
72 [[nodiscard]] virtual glm::mat4 getEyeProjectionMatrix(size_t eyeIndex) const;
73
78 [[nodiscard]] glm::mat4 getViewProjectionMatrix() const;
79
84 void setFov(float fov);
85
90 [[nodiscard]] float getFov() const { return fov_; }
91
96 void setAspectRatio(float aspectRatio);
97
102 [[nodiscard]] float getAspectRatio() const { return aspectRatio_; }
103
108 void setNearPlane(float nearPlane);
109
114 [[nodiscard]] float getNearPlane() const { return nearPlane_; }
115
120 void setFarPlane(float farPlane);
121
126 [[nodiscard]] float getFarPlane() const { return farPlane_; }
127
132 [[nodiscard]] glm::vec3 getWorldPosition() const;
133
138 [[nodiscard]] glm::vec3 getForwardVector() const;
139
144 [[nodiscard]] glm::vec3 getRightVector() const;
145
150 [[nodiscard]] glm::vec3 getUpVector() const;
151
156 [[nodiscard]] std::shared_ptr<Entities::SceneNode> getSceneNode() const { return sceneNode_; }
157
158 private:
160
161 std::shared_ptr<Entities::SceneNode> sceneNode_;
162 entt::entity cameraEntity_ = entt::null;
163
164 float fov_;
167 float aspectRatio_ = 16.0f / 9.0f;
168
169 mutable glm::mat4 cachedProjectionMatrix_{1.0f};
170 bool projectionDirty_ = true;
171 };
172
178
184}
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
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
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
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.
Logic(Entities::Scene *owningScene)
A scene is the overarching structure which can spawn, contain and destroy actors or entities.
Definition Scene.h:56
bool hasActiveCamera()
Checks if there is an active camera set.
Camera * getActiveCamera()
Gets the currently active camera.