|
Vulkan Schnee 0.0.1
High-performance rendering engine
|
A camera component that provides view and projection matrices based on its SceneNode transform. Use setActive() to mark this camera as the active camera for rendering. More...
#include <CameraComponent.h>
Public Member Functions | |
| 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 | |
| void | beginPlay () override |
| Called when the component is added to the scene or the game starts. | |
| void | tick (double deltaTime) override |
| Called every frame if ticking is enabled. | |
| void | endPlay () override |
| Called when the component is removed or the game ends. | |
| void | setActive (bool active) |
| Sets this camera as the active camera for rendering. | |
| bool | isActive () const |
| Checks if this camera is currently the active camera. | |
| glm::mat4 | getViewMatrix () const |
| Gets the view matrix computed from the camera's world transform. | |
| glm::mat4 | getProjectionMatrix () const |
| Gets the projection matrix based on FOV, aspect ratio, and clipping planes. | |
| glm::mat4 | getViewProjectionMatrix () const |
| Gets the combined view-projection matrix. | |
| void | setFov (float fov) |
| Sets the vertical field of view. | |
| float | getFov () const |
| Gets the vertical field of view. | |
| void | setAspectRatio (float aspectRatio) |
| Sets the aspect ratio (width / height) | |
| float | getAspectRatio () const |
| Gets the aspect ratio. | |
| void | setNearPlane (float nearPlane) |
| Sets the near clipping plane distance. | |
| float | getNearPlane () const |
| Gets the near clipping plane distance. | |
| void | setFarPlane (float farPlane) |
| Sets the far clipping plane distance. | |
| float | getFarPlane () const |
| Gets the far clipping plane distance. | |
| glm::vec3 | getWorldPosition () const |
| Gets the camera's world position from its scene node. | |
| glm::vec3 | getForwardVector () const |
| Gets the forward direction vector of the camera. | |
| glm::vec3 | getRightVector () const |
| Gets the right direction vector of the camera. | |
| glm::vec3 | getUpVector () const |
| Gets the up direction vector of the camera. | |
| std::shared_ptr< SceneNode > | getSceneNode () const |
| Gets the scene node associated with this camera. | |
| Public Member Functions inherited from EngineCore::LogicComponent | |
| LogicComponent (Scene *owningScene) | |
| virtual | ~LogicComponent ()=default |
| bool | canTick () const |
| Checks if the component is currently set to tick. | |
| void | setCanTick (bool enable) |
| Enables or disables ticking for this component. | |
| Entity * | getOwningEntity () const |
| Gets the entity this component belongs to. | |
Static Public Attributes | |
| static constexpr bool | IsUnique = true |
| Static Public Attributes inherited from EngineCore::LogicComponent | |
| static constexpr bool | IsUnique = false |
| Defines whether multiple instances of this component can exist on the same entity. Defaults to false (multiple allowed). Override in derived classes with static constexpr bool IsUnique = true; if needed. | |
Private Member Functions | |
| void | updateProjectionMatrix () |
Private Attributes | |
| std::shared_ptr< SceneNode > | sceneNode_ |
| entt::entity | cameraEntity_ = entt::null |
| float | fov_ |
| float | nearPlane_ |
| float | farPlane_ |
| float | aspectRatio_ = 16.0f / 9.0f |
| glm::mat4 | cachedProjectionMatrix_ {1.0f} |
| bool | projectionDirty_ = true |
Additional Inherited Members | |
| Protected Member Functions inherited from EngineCore::LogicComponent | |
| Scene * | getScene () const |
| Gets the scene this component belongs to. | |
| SceneManager * | getSceneManager () const |
| Helper to get the SceneManager from the owning scene. | |
A camera component that provides view and projection matrices based on its SceneNode transform. Use setActive() to mark this camera as the active camera for rendering.
Definition at line 17 of file CameraComponent.h.
| EngineCore::CameraComponent::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.
| owningScene | The scene this component belongs to |
| sceneNode | The scene node providing the camera's transform |
| fov | Vertical field of view in degrees (default: 60) |
| nearPlane | Near clipping plane distance (default: 0.01) |
| farPlane | Far clipping plane distance (default: 1000) |
Definition at line 13 of file CameraComponent.cpp.
References farPlane_, fov_, EngineCore::LogicComponent::LogicComponent(), nearPlane_, sceneNode_, and EngineCore::LogicComponent::setCanTick().
Referenced by getProjectionMatrix().
|
overridedefault |
|
overridevirtual |
Called when the component is added to the scene or the game starts.
Reimplemented from EngineCore::LogicComponent.
Definition at line 27 of file CameraComponent.cpp.
References aspectRatio_, EngineCore::LogicComponent::beginPlay(), cameraEntity_, farPlane_, Ecs::CameraProperties::fov, fov_, Ecs::RegistryManager::get(), nearPlane_, and updateProjectionMatrix().
|
overridevirtual |
Called when the component is removed or the game ends.
Reimplemented from EngineCore::LogicComponent.
Definition at line 50 of file CameraComponent.cpp.
References cameraEntity_, EngineCore::LogicComponent::endPlay(), Ecs::RegistryManager::get(), and EngineCore::s_activeCamera.
|
inlinenodiscard |
Gets the aspect ratio.
Definition at line 93 of file CameraComponent.h.
References aspectRatio_.
|
inlinenodiscard |
Gets the far clipping plane distance.
Definition at line 117 of file CameraComponent.h.
References farPlane_.
|
nodiscard |
Gets the forward direction vector of the camera.
Definition at line 186 of file CameraComponent.cpp.
References sceneNode_.
|
inlinenodiscard |
Gets the vertical field of view.
Definition at line 81 of file CameraComponent.h.
References fov_.
|
inlinenodiscard |
Gets the near clipping plane distance.
Definition at line 105 of file CameraComponent.h.
References nearPlane_.
|
nodiscard |
Gets the projection matrix based on FOV, aspect ratio, and clipping planes.
Definition at line 119 of file CameraComponent.cpp.
References cachedProjectionMatrix_, CameraComponent(), projectionDirty_, and updateProjectionMatrix().
Referenced by getViewProjectionMatrix().
|
nodiscard |
Gets the right direction vector of the camera.
Definition at line 195 of file CameraComponent.cpp.
References sceneNode_.
|
inlinenodiscard |
Gets the scene node associated with this camera.
Definition at line 147 of file CameraComponent.h.
References sceneNode_.
|
nodiscard |
Gets the up direction vector of the camera.
Definition at line 204 of file CameraComponent.cpp.
References sceneNode_.
|
nodiscard |
Gets the view matrix computed from the camera's world transform.
Definition at line 109 of file CameraComponent.cpp.
References sceneNode_.
Referenced by getViewProjectionMatrix(), and EngineCore::RenderProcess::updateEyeViewProjectionMatrices().
|
nodiscard |
Gets the combined view-projection matrix.
Definition at line 126 of file CameraComponent.cpp.
References getProjectionMatrix(), and getViewMatrix().
|
nodiscard |
Gets the camera's world position from its scene node.
Definition at line 178 of file CameraComponent.cpp.
References sceneNode_.
|
nodiscard |
Checks if this camera is currently the active camera.
Definition at line 101 of file CameraComponent.cpp.
References cameraEntity_, and Ecs::RegistryManager::get().
| void EngineCore::CameraComponent::setActive | ( | bool | active | ) |
Sets this camera as the active camera for rendering.
| active | If true, this camera becomes the active camera (removing active tag from others) |
Definition at line 67 of file CameraComponent.cpp.
References cameraEntity_, Ecs::RegistryManager::get(), and EngineCore::s_activeCamera.
| void EngineCore::CameraComponent::setAspectRatio | ( | float | aspectRatio | ) |
Sets the aspect ratio (width / height)
| aspectRatio | New aspect ratio |
Definition at line 142 of file CameraComponent.cpp.
References aspectRatio_, cameraEntity_, Ecs::RegistryManager::get(), and projectionDirty_.
| void EngineCore::CameraComponent::setFarPlane | ( | float | farPlane | ) |
Sets the far clipping plane distance.
| farPlane | Far plane distance |
Definition at line 166 of file CameraComponent.cpp.
References cameraEntity_, farPlane_, Ecs::RegistryManager::get(), and projectionDirty_.
| void EngineCore::CameraComponent::setFov | ( | float | fov | ) |
Sets the vertical field of view.
| fov | Field of view in degrees |
Definition at line 130 of file CameraComponent.cpp.
References cameraEntity_, fov_, Ecs::RegistryManager::get(), and projectionDirty_.
| void EngineCore::CameraComponent::setNearPlane | ( | float | nearPlane | ) |
Sets the near clipping plane distance.
| nearPlane | Near plane distance |
Definition at line 154 of file CameraComponent.cpp.
References cameraEntity_, Ecs::RegistryManager::get(), nearPlane_, and projectionDirty_.
|
overridevirtual |
Called every frame if ticking is enabled.
| deltaTime | Time elapsed since last frame. |
Reimplemented from EngineCore::LogicComponent.
Definition at line 45 of file CameraComponent.cpp.
|
private |
Definition at line 213 of file CameraComponent.cpp.
References aspectRatio_, cachedProjectionMatrix_, farPlane_, fov_, nearPlane_, and projectionDirty_.
Referenced by beginPlay(), and getProjectionMatrix().
|
private |
Definition at line 158 of file CameraComponent.h.
Referenced by beginPlay(), getAspectRatio(), setAspectRatio(), and updateProjectionMatrix().
|
mutableprivate |
Definition at line 160 of file CameraComponent.h.
Referenced by getProjectionMatrix(), and updateProjectionMatrix().
|
private |
Definition at line 153 of file CameraComponent.h.
Referenced by beginPlay(), endPlay(), isActive(), setActive(), setAspectRatio(), setFarPlane(), setFov(), and setNearPlane().
|
private |
Definition at line 157 of file CameraComponent.h.
Referenced by beginPlay(), CameraComponent(), getFarPlane(), setFarPlane(), and updateProjectionMatrix().
|
private |
Definition at line 155 of file CameraComponent.h.
Referenced by beginPlay(), CameraComponent(), getFov(), setFov(), and updateProjectionMatrix().
|
staticconstexpr |
Definition at line 19 of file CameraComponent.h.
|
private |
Definition at line 156 of file CameraComponent.h.
Referenced by beginPlay(), CameraComponent(), getNearPlane(), setNearPlane(), and updateProjectionMatrix().
|
private |
Definition at line 161 of file CameraComponent.h.
Referenced by getProjectionMatrix(), setAspectRatio(), setFarPlane(), setFov(), setNearPlane(), and updateProjectionMatrix().
|
private |
Definition at line 152 of file CameraComponent.h.
Referenced by CameraComponent(), getForwardVector(), getRightVector(), getSceneNode(), getUpVector(), getViewMatrix(), and getWorldPosition().