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
38 bool drawImGui() override;
39
44 void setActive(bool active);
45
50 [[nodiscard]] bool isActive() const;
51
56 [[nodiscard]] virtual glm::mat4 getViewMatrix() const;
57
62 [[nodiscard]] virtual glm::mat4 getProjectionMatrix() const;
63
68 [[nodiscard]] virtual glm::mat4 getEyeViewMatrix(size_t eyeIndex) const;
69
74 [[nodiscard]] virtual glm::mat4 getEyeProjectionMatrix(size_t eyeIndex) const;
75
80 [[nodiscard]] glm::mat4 getViewProjectionMatrix() const;
81
86 void setFov(float fov);
87
92 [[nodiscard]] float getFov() const { return fov_; }
93
98 void setAspectRatio(float aspectRatio);
99
104 [[nodiscard]] float getAspectRatio() const { return aspectRatio_; }
105
110 void setNearPlane(float nearPlane);
111
116 [[nodiscard]] float getNearPlane() const { return nearPlane_; }
117
122 void setFarPlane(float farPlane);
123
128 [[nodiscard]] float getFarPlane() const { return farPlane_; }
129
134 [[nodiscard]] glm::vec3 getWorldPosition() const;
135
140 [[nodiscard]] glm::vec3 getForwardVector() const;
141
146 [[nodiscard]] glm::vec3 getRightVector() const;
147
152 [[nodiscard]] glm::vec3 getUpVector() const;
153
158 [[nodiscard]] std::shared_ptr<Entities::SceneNode> getSceneNode() const { return sceneNode_; }
159
160 private:
162
163 std::shared_ptr<Entities::SceneNode> sceneNode_;
164 entt::entity cameraEntity_ = entt::null;
165
166 float fov_;
169 float aspectRatio_ = 16.0f / 9.0f;
170
171 mutable glm::mat4 cachedProjectionMatrix_{1.0f};
172 bool projectionDirty_ = true;
173 };
174
180
186}
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.
bool drawImGui() override
Draws component-specific ImGui inspector controls.
Logic(Entities::Scene *owningScene)
A scene is the overarching structure which can spawn, contain and destroy actors or entities.
Definition Scene.h:62
bool hasActiveCamera()
Checks if there is an active camera set.
Camera * getActiveCamera()
Gets the currently active camera.