Vulkan Schnee 0.0.1
High-performance rendering engine
Loading...
Searching...
No Matches
EngineCore::CameraComponent Class Reference

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>

Inheritance diagram for EngineCore::CameraComponent:
Collaboration diagram for EngineCore::CameraComponent:

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< SceneNodegetSceneNode () 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.
EntitygetOwningEntity () 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< SceneNodesceneNode_
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
ScenegetScene () const
 Gets the scene this component belongs to.
SceneManagergetSceneManager () const
 Helper to get the SceneManager from the owning scene.

Detailed Description

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.

Date
2026-01-17
Author
Konstantin Passig

Definition at line 17 of file CameraComponent.h.

Constructor & Destructor Documentation

◆ CameraComponent()

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.

Parameters
owningSceneThe scene this component belongs to
sceneNodeThe scene node providing the camera's transform
fovVertical field of view in degrees (default: 60)
nearPlaneNear clipping plane distance (default: 0.01)
farPlaneFar 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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~CameraComponent()

EngineCore::CameraComponent::~CameraComponent ( )
overridedefault

Member Function Documentation

◆ beginPlay()

void EngineCore::CameraComponent::beginPlay ( )
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().

Here is the call graph for this function:

◆ endPlay()

void EngineCore::CameraComponent::endPlay ( )
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.

Here is the call graph for this function:

◆ getAspectRatio()

float EngineCore::CameraComponent::getAspectRatio ( ) const
inlinenodiscard

Gets the aspect ratio.

Returns
Aspect ratio (width / height)

Definition at line 93 of file CameraComponent.h.

References aspectRatio_.

◆ getFarPlane()

float EngineCore::CameraComponent::getFarPlane ( ) const
inlinenodiscard

Gets the far clipping plane distance.

Returns
Far plane distance

Definition at line 117 of file CameraComponent.h.

References farPlane_.

◆ getForwardVector()

glm::vec3 EngineCore::CameraComponent::getForwardVector ( ) const
nodiscard

Gets the forward direction vector of the camera.

Returns
Normalized forward direction in world space

Definition at line 186 of file CameraComponent.cpp.

References sceneNode_.

◆ getFov()

float EngineCore::CameraComponent::getFov ( ) const
inlinenodiscard

Gets the vertical field of view.

Returns
FOV in degrees

Definition at line 81 of file CameraComponent.h.

References fov_.

◆ getNearPlane()

float EngineCore::CameraComponent::getNearPlane ( ) const
inlinenodiscard

Gets the near clipping plane distance.

Returns
Near plane distance

Definition at line 105 of file CameraComponent.h.

References nearPlane_.

◆ getProjectionMatrix()

glm::mat4 EngineCore::CameraComponent::getProjectionMatrix ( ) const
nodiscard

Gets the projection matrix based on FOV, aspect ratio, and clipping planes.

Returns
Projection matrix

Definition at line 119 of file CameraComponent.cpp.

References cachedProjectionMatrix_, CameraComponent(), projectionDirty_, and updateProjectionMatrix().

Referenced by getViewProjectionMatrix().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getRightVector()

glm::vec3 EngineCore::CameraComponent::getRightVector ( ) const
nodiscard

Gets the right direction vector of the camera.

Returns
Normalized right direction in world space

Definition at line 195 of file CameraComponent.cpp.

References sceneNode_.

◆ getSceneNode()

std::shared_ptr< SceneNode > EngineCore::CameraComponent::getSceneNode ( ) const
inlinenodiscard

Gets the scene node associated with this camera.

Returns
The camera's scene node

Definition at line 147 of file CameraComponent.h.

References sceneNode_.

◆ getUpVector()

glm::vec3 EngineCore::CameraComponent::getUpVector ( ) const
nodiscard

Gets the up direction vector of the camera.

Returns
Normalized up direction in world space

Definition at line 204 of file CameraComponent.cpp.

References sceneNode_.

◆ getViewMatrix()

glm::mat4 EngineCore::CameraComponent::getViewMatrix ( ) const
nodiscard

Gets the view matrix computed from the camera's world transform.

Returns
View matrix (inverse of world matrix)

Definition at line 109 of file CameraComponent.cpp.

References sceneNode_.

Referenced by getViewProjectionMatrix(), and EngineCore::RenderProcess::updateEyeViewProjectionMatrices().

Here is the caller graph for this function:

◆ getViewProjectionMatrix()

glm::mat4 EngineCore::CameraComponent::getViewProjectionMatrix ( ) const
nodiscard

Gets the combined view-projection matrix.

Returns
Projection * View matrix

Definition at line 126 of file CameraComponent.cpp.

References getProjectionMatrix(), and getViewMatrix().

Here is the call graph for this function:

◆ getWorldPosition()

glm::vec3 EngineCore::CameraComponent::getWorldPosition ( ) const
nodiscard

Gets the camera's world position from its scene node.

Returns
Camera position in world space

Definition at line 178 of file CameraComponent.cpp.

References sceneNode_.

◆ isActive()

bool EngineCore::CameraComponent::isActive ( ) const
nodiscard

Checks if this camera is currently the active camera.

Returns
true if this is the active camera

Definition at line 101 of file CameraComponent.cpp.

References cameraEntity_, and Ecs::RegistryManager::get().

Here is the call graph for this function:

◆ setActive()

void EngineCore::CameraComponent::setActive ( bool active)

Sets this camera as the active camera for rendering.

Parameters
activeIf 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.

Here is the call graph for this function:

◆ setAspectRatio()

void EngineCore::CameraComponent::setAspectRatio ( float aspectRatio)

Sets the aspect ratio (width / height)

Parameters
aspectRatioNew aspect ratio

Definition at line 142 of file CameraComponent.cpp.

References aspectRatio_, cameraEntity_, Ecs::RegistryManager::get(), and projectionDirty_.

Here is the call graph for this function:

◆ setFarPlane()

void EngineCore::CameraComponent::setFarPlane ( float farPlane)

Sets the far clipping plane distance.

Parameters
farPlaneFar plane distance

Definition at line 166 of file CameraComponent.cpp.

References cameraEntity_, farPlane_, Ecs::RegistryManager::get(), and projectionDirty_.

Here is the call graph for this function:

◆ setFov()

void EngineCore::CameraComponent::setFov ( float fov)

Sets the vertical field of view.

Parameters
fovField of view in degrees

Definition at line 130 of file CameraComponent.cpp.

References cameraEntity_, fov_, Ecs::RegistryManager::get(), and projectionDirty_.

Here is the call graph for this function:

◆ setNearPlane()

void EngineCore::CameraComponent::setNearPlane ( float nearPlane)

Sets the near clipping plane distance.

Parameters
nearPlaneNear plane distance

Definition at line 154 of file CameraComponent.cpp.

References cameraEntity_, Ecs::RegistryManager::get(), nearPlane_, and projectionDirty_.

Here is the call graph for this function:

◆ tick()

void EngineCore::CameraComponent::tick ( double deltaTime)
overridevirtual

Called every frame if ticking is enabled.

Parameters
deltaTimeTime elapsed since last frame.

Reimplemented from EngineCore::LogicComponent.

Definition at line 45 of file CameraComponent.cpp.

◆ updateProjectionMatrix()

void EngineCore::CameraComponent::updateProjectionMatrix ( )
private

Definition at line 213 of file CameraComponent.cpp.

References aspectRatio_, cachedProjectionMatrix_, farPlane_, fov_, nearPlane_, and projectionDirty_.

Referenced by beginPlay(), and getProjectionMatrix().

Here is the caller graph for this function:

Member Data Documentation

◆ aspectRatio_

float EngineCore::CameraComponent::aspectRatio_ = 16.0f / 9.0f
private

◆ cachedProjectionMatrix_

glm::mat4 EngineCore::CameraComponent::cachedProjectionMatrix_ {1.0f}
mutableprivate

Definition at line 160 of file CameraComponent.h.

Referenced by getProjectionMatrix(), and updateProjectionMatrix().

◆ cameraEntity_

entt::entity EngineCore::CameraComponent::cameraEntity_ = entt::null
private

◆ farPlane_

float EngineCore::CameraComponent::farPlane_
private

◆ fov_

float EngineCore::CameraComponent::fov_
private

Definition at line 155 of file CameraComponent.h.

Referenced by beginPlay(), CameraComponent(), getFov(), setFov(), and updateProjectionMatrix().

◆ IsUnique

bool EngineCore::CameraComponent::IsUnique = true
staticconstexpr

Definition at line 19 of file CameraComponent.h.

◆ nearPlane_

float EngineCore::CameraComponent::nearPlane_
private

◆ projectionDirty_

bool EngineCore::CameraComponent::projectionDirty_ = true
private

◆ sceneNode_

std::shared_ptr<SceneNode> EngineCore::CameraComponent::sceneNode_
private

The documentation for this class was generated from the following files: