Rendering Engine 0.2.0
Modular Graphics Rendering Engine | v0.2.0
Loading...
Searching...
No Matches
rendering_engine::Camera Class Reference

Represents a 3D perspective camera with world transform and projection settings. More...

#include <camera.hpp>

Public Member Functions

 Camera (IApplication &app)
 Constructs a camera for the given application context.
virtual ~Camera ()=default
 Virtual destructor.
virtual void Initialize ()
 Initializes camera parameters and matrices.
virtual void Update (float deltaTime)
 Updates camera logic, recalculates view/projection matrices as needed.
void SetPosition (const glm::vec3 &position)
 Sets the camera position in world space.
void SetRotation (const glm::quat &rotation)
 Sets the camera rotation via quaternion.
void SetRotation (const glm::vec3 &rotation)
 Sets the camera rotation via Euler angles (degrees).
glm::vec3 GetPosition () const
 Gets the camera position.
glm::quat GetRotationQuat () const
 Gets the camera rotation as a quaternion.
glm::vec3 GetRotation () const
 Gets the camera rotation as Euler angles (degrees).
glm::vec3 GetForward () const
 Gets the camera's forward direction vector.
glm::vec3 GetUp () const
 Gets the camera's up direction vector.
glm::vec3 GetRight () const
 Gets the camera's right direction vector.
const glm::mat4 & ViewMatrix () const
 Gets the camera view matrix.
const glm::mat4 & ProjectionMatrix () const
 Gets the camera projection matrix.
glm::mat4 ViewProjectionMatrix () const
 Gets the combined view-projection matrix.
void Reset ()
 Resets the camera to the default position and rotation.
void UpdateProjectionMatrix ()
 Updates the camera's projection matrix (based on FOV, aspect, near/far).
void UpdateViewMatrix ()
 Updates the camera's view matrix (based on position/orientation).
 Camera (const Camera &rhs)=delete
Cameraoperator= (const Camera &rhs)=delete

Protected Attributes

IApplicationmApp
std::unique_ptr< SceneComponentmSceneComponent
glm::mat4 mViewMatrix
glm::mat4 mProjectionMatrix
float mFieldOfView
float mAspectRatio
float mNearPlaneDistance
float mFarPlaneDistance

Static Protected Attributes

static const float sDefaultFieldOfView = 45.0f
static const float sDefaultAspectRatio
static const float sDefaultNearPlaneDistance = 0.01f
static const float sDefaultFarPlaneDistance = 1000.0f

Detailed Description

Represents a 3D perspective camera with world transform and projection settings.

The Camera defines the viewpoint in the 3D scene, including position and orientation (via a SceneComponent) and projection parameters (field of view, aspect ratio, near/far planes). The camera supports standard view matrix construction using GLM and can be subclassed for additional camera types (third-person, orbit, etc).

Coordinate System

The rendering engine uses a left-handed coordinate system:

By default, the camera looks along the world Y+ direction after Reset().

Note
  • Angles (Euler) are in degrees, matching typical editor/engine conventions.
  • The camera transform is provided by a SceneComponent.
  • The camera generates a perspective projection matrix using a vertical field of view.
See also
rendering_engine::SceneComponent
rendering_engine::axes

Definition at line 47 of file camera.hpp.

Constructor & Destructor Documentation

◆ Camera() [1/2]

rendering_engine::Camera::Camera ( IApplication & app)

Constructs a camera for the given application context.

Parameters
appReference to the IApplication (for screen settings, etc.).

Definition at line 12 of file camera.cpp.

13 :
14 mApp(app),
15 mSceneComponent(std::make_unique<SceneComponent>()),
19{
20 mAspectRatio = static_cast<float>(mApp.GetScreenSettings().width) /
21 static_cast<float>(mApp.GetScreenSettings().height);
22}
IApplication & mApp
Definition camera.hpp:154
static const float sDefaultFarPlaneDistance
Definition camera.hpp:164
static const float sDefaultFieldOfView
Definition camera.hpp:161
std::unique_ptr< SceneComponent > mSceneComponent
Definition camera.hpp:156
static const float sDefaultNearPlaneDistance
Definition camera.hpp:163

◆ ~Camera()

virtual rendering_engine::Camera::~Camera ( )
virtualdefault

Virtual destructor.

◆ Camera() [2/2]

rendering_engine::Camera::Camera ( const Camera & rhs)
delete

Member Function Documentation

◆ GetForward()

glm::vec3 rendering_engine::Camera::GetForward ( ) const

Gets the camera's forward direction vector.

Definition at line 59 of file camera.cpp.

60{
61 return mSceneComponent->GetForward();
62}

◆ GetPosition()

glm::vec3 rendering_engine::Camera::GetPosition ( ) const

Gets the camera position.

Definition at line 47 of file camera.cpp.

48{
49 return mSceneComponent->GetPosition();
50}

◆ GetRight()

glm::vec3 rendering_engine::Camera::GetRight ( ) const

Gets the camera's right direction vector.

Definition at line 67 of file camera.cpp.

68{
69 return mSceneComponent->GetRight();
70}

◆ GetRotation()

glm::vec3 rendering_engine::Camera::GetRotation ( ) const

Gets the camera rotation as Euler angles (degrees).

Definition at line 55 of file camera.cpp.

56{
57 return mSceneComponent->GetRotation();
58}

◆ GetRotationQuat()

glm::quat rendering_engine::Camera::GetRotationQuat ( ) const

Gets the camera rotation as a quaternion.

Definition at line 51 of file camera.cpp.

52{
53 return mSceneComponent->GetRotationQuat();
54}

◆ GetUp()

glm::vec3 rendering_engine::Camera::GetUp ( ) const

Gets the camera's up direction vector.

Definition at line 63 of file camera.cpp.

64{
65 return mSceneComponent->GetUp();
66}

◆ Initialize()

void rendering_engine::Camera::Initialize ( )
virtual

Initializes camera parameters and matrices.

Definition at line 24 of file camera.cpp.

25{
27 Reset();
29}
void Reset()
Resets the camera to the default position and rotation.
Definition camera.cpp:83
void UpdateProjectionMatrix()
Updates the camera's projection matrix (based on FOV, aspect, near/far).
Definition camera.cpp:89
void UpdateViewMatrix()
Updates the camera's view matrix (based on position/orientation).
Definition camera.cpp:95

◆ operator=()

Camera & rendering_engine::Camera::operator= ( const Camera & rhs)
delete

◆ ProjectionMatrix()

const glm::mat4 & rendering_engine::Camera::ProjectionMatrix ( ) const

Gets the camera projection matrix.

Definition at line 75 of file camera.cpp.

76{
77 return mProjectionMatrix;
78}
glm::mat4 mProjectionMatrix
Definition camera.hpp:159

◆ Reset()

void rendering_engine::Camera::Reset ( )

Resets the camera to the default position and rotation.

Definition at line 83 of file camera.cpp.

84{
85 // Turn leff, as by default it will look to the right
86 SetPosition(glm::vec3(-10.0f, 0.0f, 0.0f));
87 SetRotation(glm::vec3(0.0f, 0.0f, 0.0f));
88}
void SetRotation(const glm::quat &rotation)
Sets the camera rotation via quaternion.
Definition camera.cpp:39
void SetPosition(const glm::vec3 &position)
Sets the camera position in world space.
Definition camera.cpp:35

◆ SetPosition()

void rendering_engine::Camera::SetPosition ( const glm::vec3 & position)

Sets the camera position in world space.

Parameters
positionNew position (glm::vec3).

Definition at line 35 of file camera.cpp.

36{
37 mSceneComponent->SetPosition(position);
38}

◆ SetRotation() [1/2]

void rendering_engine::Camera::SetRotation ( const glm::quat & rotation)

Sets the camera rotation via quaternion.

Parameters
rotationNew rotation (glm::quat).

Definition at line 39 of file camera.cpp.

40{
41 mSceneComponent->SetRotation(rotation);
42}

◆ SetRotation() [2/2]

void rendering_engine::Camera::SetRotation ( const glm::vec3 & rotation)

Sets the camera rotation via Euler angles (degrees).

Parameters
rotationEuler angles (pitch, yaw, roll), in degrees.

Definition at line 43 of file camera.cpp.

44{
45 mSceneComponent->SetRotation(rotation);
46}

◆ Update()

void rendering_engine::Camera::Update ( float deltaTime)
virtual

Updates camera logic, recalculates view/projection matrices as needed.

Parameters
deltaTimeElapsed time since last update (seconds).

Definition at line 30 of file camera.cpp.

◆ UpdateProjectionMatrix()

void rendering_engine::Camera::UpdateProjectionMatrix ( )

Updates the camera's projection matrix (based on FOV, aspect, near/far).

Definition at line 89 of file camera.cpp.

90{
91 mAspectRatio = static_cast<float>(mApp.GetScreenSettings().width) /
92 static_cast<float>(mApp.GetScreenSettings().height);
94}

◆ UpdateViewMatrix()

void rendering_engine::Camera::UpdateViewMatrix ( )

Updates the camera's view matrix (based on position/orientation).

Definition at line 95 of file camera.cpp.

96{
97 const glm::vec3 target = mSceneComponent->GetPosition() + mSceneComponent->GetForward();
98 mViewMatrix = glm::lookAt(mSceneComponent->GetPosition(), target, mSceneComponent->GetUp());
99}

◆ ViewMatrix()

const glm::mat4 & rendering_engine::Camera::ViewMatrix ( ) const

Gets the camera view matrix.

Definition at line 71 of file camera.cpp.

72{
73 return mViewMatrix;
74}

◆ ViewProjectionMatrix()

glm::mat4 rendering_engine::Camera::ViewProjectionMatrix ( ) const

Gets the combined view-projection matrix.

Definition at line 79 of file camera.cpp.

80{
82}

Member Data Documentation

◆ mApp

IApplication& rendering_engine::Camera::mApp
protected

Definition at line 154 of file camera.hpp.

◆ mAspectRatio

float rendering_engine::Camera::mAspectRatio
protected

Definition at line 167 of file camera.hpp.

◆ mFarPlaneDistance

float rendering_engine::Camera::mFarPlaneDistance
protected

Definition at line 169 of file camera.hpp.

◆ mFieldOfView

float rendering_engine::Camera::mFieldOfView
protected

Definition at line 166 of file camera.hpp.

◆ mNearPlaneDistance

float rendering_engine::Camera::mNearPlaneDistance
protected

Definition at line 168 of file camera.hpp.

◆ mProjectionMatrix

glm::mat4 rendering_engine::Camera::mProjectionMatrix
protected

Definition at line 159 of file camera.hpp.

◆ mSceneComponent

std::unique_ptr<SceneComponent> rendering_engine::Camera::mSceneComponent
protected

Definition at line 156 of file camera.hpp.

◆ mViewMatrix

glm::mat4 rendering_engine::Camera::mViewMatrix
protected

Definition at line 158 of file camera.hpp.

◆ sDefaultAspectRatio

const float rendering_engine::Camera::sDefaultAspectRatio
staticprotected

Definition at line 162 of file camera.hpp.

◆ sDefaultFarPlaneDistance

const float rendering_engine::Camera::sDefaultFarPlaneDistance = 1000.0f
staticprotected

Definition at line 164 of file camera.hpp.

◆ sDefaultFieldOfView

const float rendering_engine::Camera::sDefaultFieldOfView = 45.0f
staticprotected

Definition at line 161 of file camera.hpp.

◆ sDefaultNearPlaneDistance

const float rendering_engine::Camera::sDefaultNearPlaneDistance = 0.01f
staticprotected

Definition at line 163 of file camera.hpp.


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