Vulkan Schnee 0.0.1
High-performance rendering engine
Loading...
Searching...
No Matches
Engine::Components::Camera 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 Engine::Components::Camera:
Collaboration diagram for Engine::Components::Camera:

Public Member Functions

 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.
 ~Camera () 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.
virtual glm::mat4 getViewMatrix () const
 Gets the view matrix computed from the camera's world transform.
virtual glm::mat4 getProjectionMatrix () const
 Gets the projection matrix based on FOV, aspect ratio, and clipping planes.
virtual glm::mat4 getEyeViewMatrix (size_t eyeIndex) const
 Gets the view matrix for a specific eye. Base returns getViewMatrix() for both (mono).
virtual glm::mat4 getEyeProjectionMatrix (size_t eyeIndex) const
 Gets the projection matrix for a specific eye. Base returns getProjectionMatrix() for both (mono).
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< Entities::SceneNodegetSceneNode () const
 Gets the scene node associated with this camera.
Public Member Functions inherited from Engine::Components::Logic
 Logic (Entities::Scene *owningScene)
virtual ~Logic ()=default
virtual std::string getComponentName () const
 Gets the component type name for debugging/UI.
bool hasBegunPlay () const
bool canTick () const
 Checks if the component is currently set to tick.
void setCanTick (bool enable)
 Enables or disables ticking for this component.
Entities::EntitygetOwningEntity () const
 Gets the entity this component belongs to.

Static Public Attributes

static constexpr bool IsUnique = true
static constexpr const char * ComponentName = "Camera"
Static Public Attributes inherited from Engine::Components::Logic
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.
static constexpr const char * ComponentName = "Logic"
 Fallback component type name. Derived classes may override getComponentName() for custom labels.

Private Member Functions

void updateProjectionMatrix ()

Private Attributes

std::shared_ptr< Entities::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 Engine::Components::Logic
Entities::ScenegetScene () const
 Gets the scene this component belongs to.
Core::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.

Definition at line 13 of file CameraComponent.h.

Constructor & Destructor Documentation

◆ Camera()

Engine::Components::Camera::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.

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)

◆ ~Camera()

Engine::Components::Camera::~Camera ( )
overridedefault

Member Function Documentation

◆ beginPlay()

void Engine::Components::Camera::beginPlay ( )
overridevirtual

Called when the component is added to the scene or the game starts.

Reimplemented from Engine::Components::Logic.

◆ endPlay()

void Engine::Components::Camera::endPlay ( )
overridevirtual

Called when the component is removed or the game ends.

Reimplemented from Engine::Components::Logic.

◆ getAspectRatio()

float Engine::Components::Camera::getAspectRatio ( ) const
inlinenodiscard

Gets the aspect ratio.

Returns
Aspect ratio (width / height)

Definition at line 102 of file CameraComponent.h.

References aspectRatio_.

◆ getEyeProjectionMatrix()

virtual glm::mat4 Engine::Components::Camera::getEyeProjectionMatrix ( size_t eyeIndex) const
nodiscardvirtual

Gets the projection matrix for a specific eye. Base returns getProjectionMatrix() for both (mono).

Parameters
eyeIndex0 = left eye, 1 = right eye

Reimplemented in Engine::Components::VrCamera.

◆ getEyeViewMatrix()

virtual glm::mat4 Engine::Components::Camera::getEyeViewMatrix ( size_t eyeIndex) const
nodiscardvirtual

Gets the view matrix for a specific eye. Base returns getViewMatrix() for both (mono).

Parameters
eyeIndex0 = left eye, 1 = right eye

Reimplemented in Engine::Components::VrCamera.

◆ getFarPlane()

float Engine::Components::Camera::getFarPlane ( ) const
inlinenodiscard

Gets the far clipping plane distance.

Returns
Far plane distance

Definition at line 126 of file CameraComponent.h.

References farPlane_.

◆ getForwardVector()

glm::vec3 Engine::Components::Camera::getForwardVector ( ) const
nodiscard

Gets the forward direction vector of the camera.

Returns
Normalized forward direction in world space

◆ getFov()

float Engine::Components::Camera::getFov ( ) const
inlinenodiscard

Gets the vertical field of view.

Returns
FOV in degrees

Definition at line 90 of file CameraComponent.h.

References fov_.

◆ getNearPlane()

float Engine::Components::Camera::getNearPlane ( ) const
inlinenodiscard

Gets the near clipping plane distance.

Returns
Near plane distance

Definition at line 114 of file CameraComponent.h.

References nearPlane_.

◆ getProjectionMatrix()

virtual glm::mat4 Engine::Components::Camera::getProjectionMatrix ( ) const
nodiscardvirtual

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

Returns
Projection matrix

◆ getRightVector()

glm::vec3 Engine::Components::Camera::getRightVector ( ) const
nodiscard

Gets the right direction vector of the camera.

Returns
Normalized right direction in world space

◆ getSceneNode()

std::shared_ptr< Entities::SceneNode > Engine::Components::Camera::getSceneNode ( ) const
inlinenodiscard

Gets the scene node associated with this camera.

Returns
The camera's scene node

Definition at line 156 of file CameraComponent.h.

References sceneNode_.

◆ getUpVector()

glm::vec3 Engine::Components::Camera::getUpVector ( ) const
nodiscard

Gets the up direction vector of the camera.

Returns
Normalized up direction in world space

◆ getViewMatrix()

virtual glm::mat4 Engine::Components::Camera::getViewMatrix ( ) const
nodiscardvirtual

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

Returns
View matrix (inverse of world matrix)

◆ getViewProjectionMatrix()

glm::mat4 Engine::Components::Camera::getViewProjectionMatrix ( ) const
nodiscard

Gets the combined view-projection matrix.

Returns
Projection * View matrix

◆ getWorldPosition()

glm::vec3 Engine::Components::Camera::getWorldPosition ( ) const
nodiscard

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

Returns
Camera position in world space

◆ isActive()

bool Engine::Components::Camera::isActive ( ) const
nodiscard

Checks if this camera is currently the active camera.

Returns
true if this is the active camera

◆ setActive()

void Engine::Components::Camera::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)

◆ setAspectRatio()

void Engine::Components::Camera::setAspectRatio ( float aspectRatio)

Sets the aspect ratio (width / height)

Parameters
aspectRatioNew aspect ratio

◆ setFarPlane()

void Engine::Components::Camera::setFarPlane ( float farPlane)

Sets the far clipping plane distance.

Parameters
farPlaneFar plane distance

◆ setFov()

void Engine::Components::Camera::setFov ( float fov)

Sets the vertical field of view.

Parameters
fovField of view in degrees

◆ setNearPlane()

void Engine::Components::Camera::setNearPlane ( float nearPlane)

Sets the near clipping plane distance.

Parameters
nearPlaneNear plane distance

◆ tick()

void Engine::Components::Camera::tick ( double deltaTime)
overridevirtual

Called every frame if ticking is enabled.

Parameters
deltaTimeTime elapsed since last frame.

Reimplemented from Engine::Components::Logic.

Reimplemented in Engine::Components::VrCamera.

◆ updateProjectionMatrix()

void Engine::Components::Camera::updateProjectionMatrix ( )
private

Member Data Documentation

◆ aspectRatio_

float Engine::Components::Camera::aspectRatio_ = 16.0f / 9.0f
private

Definition at line 167 of file CameraComponent.h.

Referenced by getAspectRatio().

◆ cachedProjectionMatrix_

glm::mat4 Engine::Components::Camera::cachedProjectionMatrix_ {1.0f}
mutableprivate

Definition at line 169 of file CameraComponent.h.

◆ cameraEntity_

entt::entity Engine::Components::Camera::cameraEntity_ = entt::null
private

Definition at line 162 of file CameraComponent.h.

◆ ComponentName

const char* Engine::Components::Camera::ComponentName = "Camera"
staticconstexpr

Definition at line 16 of file CameraComponent.h.

◆ farPlane_

float Engine::Components::Camera::farPlane_
private

Definition at line 166 of file CameraComponent.h.

Referenced by getFarPlane().

◆ fov_

float Engine::Components::Camera::fov_
private

Definition at line 164 of file CameraComponent.h.

Referenced by getFov().

◆ IsUnique

bool Engine::Components::Camera::IsUnique = true
staticconstexpr

Definition at line 15 of file CameraComponent.h.

◆ nearPlane_

float Engine::Components::Camera::nearPlane_
private

Definition at line 165 of file CameraComponent.h.

Referenced by getNearPlane().

◆ projectionDirty_

bool Engine::Components::Camera::projectionDirty_ = true
private

Definition at line 170 of file CameraComponent.h.

◆ sceneNode_

std::shared_ptr<Entities::SceneNode> Engine::Components::Camera::sceneNode_
private

Definition at line 161 of file CameraComponent.h.

Referenced by getSceneNode().


The documentation for this class was generated from the following file:
  • /home/magerbeton/Documents/gl3-vulkan/Engine/include/Engine/Component/CameraComponent.h