3D Graphics Engine for ESP32
 
Loading...
Searching...
No Matches
Ragot::Camera Class Reference

Represents a camera in a 3D space, managing its properties and transformations. More...

#include <Camera.hpp>

Inheritance diagram for Ragot::Camera:
Inheritance graph
Collaboration diagram for Ragot::Camera:
Collaboration graph

Public Types

using Matrix4x4 = glm::mat4
 

Public Member Functions

 Camera ()=delete
 Delete default constructor to prevent instantiation without parameters.
 
 Camera (float aspect_ratio=1.f, float near_plane=1.f, float far_plane=100.f, float fov_deg=60.f)
 Constructs a Camera object with specified parameters.
 
 ~Camera ()=default
 Default destructor for Camera class.
 
float get_fov () const
 Returns the camera's field of view in degrees.
 
float get_near_plane () const
 Returns the camera's near clipping plane distance.
 
float get_far_plane () const
 Returns the camera's far clipping plane distance.
 
float get_aspect_ratio () const
 Returns the camera's aspect ratio (width/height).
 
glm::vec3 get_location () const
 Returns the camera's position in world space.
 
glm::vec3 get_target () const
 Returns the camera's target position in world space.
 
bool is_dirty () const
 Returns the camera's position in world space.
 
void set_fov (float deg)
 Set the fov object.
 
void set_near_plane (float np)
 Set the near clipping plane distance.
 
void set_far_plane (float fp)
 Set the far clipping plane distance.
 
void set_aspect_ratio (float ar)
 Set the aspect ratio of the camera.
 
void set_location (const glm::vec3 &p)
 Set the camera's position in world space.
 
void set_target (const glm::vec3 &t)
 Set the camera's target position in world space.
 
const Matrix4x4get_projection_matrix () const
 Get the projection matrix object.
 
const Matrix4x4get_view_matrix () const
 Get the view matrix object.
 
const Matrix4x4get_vp_matrix () const
 Get the vp matrix object.
 
glm::vec3 get_view_direction () const
 Get the view direction object.
 
glm::vec3 get_right_direction () const
 Get the right direction object.
 
glm::vec3 get_up_direction () const
 Get the up direction object.
 
glm::vec3 project_to_ndc (const glm::vec4 &worldPos) const
 
vertex_t calculate_normal (const vertex_t &v1, const vertex_t &v2, const vertex_t &v3)
 Calculate the normal vector of a face defined by three vertices.
 
bool is_face_visible (const vertex_t &v1, const vertex_t &v2, const vertex_t &v3)
 Check if a face defined by three vertices is visible from the camera's perspective.
 
void log_camera_info () const
 Logs the camera's properties for debugging purposes.
 
- Public Member Functions inherited from Ragot::Component
 Component ()=default
 Default constructor for the Component class.
 
virtual ~Component ()=default
 Default virtual destructor for the Component class.
 
 Component (const Component &)=delete
 Deleted copy constructor for the Component class.
 
 Component (const Component &&)=delete
 Deleted move constructor for the Component class.
 
Componentoperator= (const Component &)=delete
 Deleted assignment operator for the Component class.
 
Componentoperator= (const Component &&)=delete
 Deleted move assignment operator for the Component class.
 
void add_component (std::shared_ptr< Component > component)
 Adds a component to the collection.
 
void remove_component (std::shared_ptr< Component > component)
 Removes a component from the collection.
 
const std::vector< std::shared_ptr< Component > > get_components () const
 Gets the collection of components.
 
- Public Member Functions inherited from Ragot::Node
 Node ()=default
 Default constructor for Node. Initializes an empty node with no parent and no children.
 
virtual ~Node ()=default
 Default destructor for Node. Cleans up the node and its children.
 
 Node (const Node &)=delete
 Deleted copy constructor for Node. Prevents copying of Node instances.
 
 Node (const Node &&)=delete
 Deleted move constructor for Node. Prevents moving of Node instances.
 
Nodeoperator= (const Node &)=delete
 Deleted assignment operator for Node. Prevents assignment of Node instances.
 
Nodeoperator= (const Node &&)=delete
 Deleted move assignment operator for Node. Prevents moving of Node instances.
 
void add_child (std::shared_ptr< Node > child)
 Get the parent node.
 
void remove_child (std::shared_ptr< Node > child)
 Remove a child node.
 
const std::vector< std::shared_ptr< Node > > & get_children () const
 Get the parent node.
 
mat4 get_transform_matrix () override
 Get the transform matrix object.
 
- Public Member Functions inherited from Ragot::Transform
 Transform ()
 Default constructor for the Transform class.
 
virtual ~Transform ()=default
 Virtual destructor for the Transform class.
 
void set_position (const vec3 &pos)
 Sets the position of the object.
 
vec3 get_position () const
 Gets the current position of the object.
 
void set_rotation (const vec3 &rot)
 Moves the object by a specified vector.
 
vec3 get_rotation () const
 Gets the current rotation of the object.
 
void rotate (const float angle, const vec3 &axis)
 Rotates the object by a specified angle around a given axis.
 
void set_scale (const vec3 &scale)
 Sets the scale of the object.
 
vec3 get_scale () const
 Sets the scale of the object uniformly.
 
bool is_dirty () const
 Checks if the transformation matrix is dirty (needs recalculation).
 

Private Attributes

float fov
 vertical field of view in degrees
 
float near_plane
 near clipping plane distance
 
float far_plane
 far clipping plane distance
 
float aspect_ratio
 aspect ratio (width/height)
 
glm::vec3 target
 world space look-at target
 
Matrix4x4 projection_matrix
 cached projection matrix
 
Matrix4x4 view_matrix
 cached view matrix
 
Matrix4x4 vp_matrix
 cached view-projection matrix
 
bool projDirty = true
 flag to indicate if projection matrix is dirty
 
bool viewDirty = true
 flag to indicate if view matrix is dirty
 
bool vpDirty = true
 flag to indicate if view-projection matrix is dirty
 

Static Private Attributes

static const char * CAMERA_TAG = "Camera"
 Tag for logging camera-related messages.
 

Additional Inherited Members

- Protected Attributes inherited from Ragot::Component
std::vector< std::shared_ptr< Component > > components
 Collection of components managed by this Component instance.
 
- Protected Attributes inherited from Ragot::Node
std::vector< std::shared_ptr< Node > > children
 List of child nodes.
 
Nodeparent = nullptr
 Pointer to the parent node.
 
- Protected Attributes inherited from Ragot::Transform
vec3 position
 The position of the object in 3D space.
 
vec3 rotation
 The rotation of the object in degrees around each axis (x, y, z).
 
vec3 scale
 The scale of the object in 3D space, default is (1, 1, 1).
 
bool dirty = true
 Flag indicating whether the transformation matrix needs to be recalculated.
 

Detailed Description

Represents a camera in a 3D space, managing its properties and transformations.

The Camera class provides functionality to set and get camera properties such as field of view, near and far planes, aspect ratio, and target position. It also computes projection, view, and combined view-projection matrices, and provides methods for projecting world coordinates to normalized device coordinates (NDC).

Member Typedef Documentation

◆ Matrix4x4

using Ragot::Camera::Matrix4x4 = glm::mat4

Constructor & Destructor Documentation

◆ Camera() [1/2]

Ragot::Camera::Camera ( )
delete

Delete default constructor to prevent instantiation without parameters.

◆ Camera() [2/2]

Ragot::Camera::Camera ( float aspect_ratio = 1.f,
float near_plane = 1.f,
float far_plane = 100.f,
float fov_deg = 60.f )
inline

Constructs a Camera object with specified parameters.

Parameters
aspect_ratioAspect ratio of the camera (default is 1.0).
near_planeDistance to the near clipping plane (default is 1.0).
far_planeDistance to the far clipping plane (default is 100.0).
fov_degVertical field of view in degrees (default is 60.0).
Here is the call graph for this function:

◆ ~Camera()

Ragot::Camera::~Camera ( )
default

Default destructor for Camera class.

Member Function Documentation

◆ calculate_normal()

vertex_t Ragot::Camera::calculate_normal ( const vertex_t & v1,
const vertex_t & v2,
const vertex_t & v3 )

Calculate the normal vector of a face defined by three vertices.

Parameters
v1First vertex of the face.
v2Second vertex of the face.
v3Third vertex of the face.
Returns
vertex_t
Here is the caller graph for this function:

◆ get_aspect_ratio()

float Ragot::Camera::get_aspect_ratio ( ) const
inline

Returns the camera's aspect ratio (width/height).

Returns
float The aspect ratio of the camera.

◆ get_far_plane()

float Ragot::Camera::get_far_plane ( ) const
inline

Returns the camera's far clipping plane distance.

Returns
float The distance to the far clipping plane.

◆ get_fov()

float Ragot::Camera::get_fov ( ) const
inline

Returns the camera's field of view in degrees.

Returns
float The field of view in degrees.

◆ get_location()

glm::vec3 Ragot::Camera::get_location ( ) const
inline

Returns the camera's position in world space.

Returns
glm::vec3 The position of the camera.
Here is the call graph for this function:

◆ get_near_plane()

float Ragot::Camera::get_near_plane ( ) const
inline

Returns the camera's near clipping plane distance.

Returns
float The distance to the near clipping plane.

◆ get_projection_matrix()

const Matrix4x4 & Ragot::Camera::get_projection_matrix ( ) const
inline

Get the projection matrix object.

Returns
const Matrix4x4&
Here is the caller graph for this function:

◆ get_right_direction()

glm::vec3 Ragot::Camera::get_right_direction ( ) const
inline

Get the right direction object.

Returns
glm::vec3
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_target()

glm::vec3 Ragot::Camera::get_target ( ) const
inline

Returns the camera's target position in world space.

Returns
glm::vec3 The target position of the camera.

◆ get_up_direction()

glm::vec3 Ragot::Camera::get_up_direction ( ) const
inline

Get the up direction object.

Returns
glm::vec3
Here is the call graph for this function:

◆ get_view_direction()

glm::vec3 Ragot::Camera::get_view_direction ( ) const
inline

Get the view direction object.

Returns
glm::vec3
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_view_matrix()

const Matrix4x4 & Ragot::Camera::get_view_matrix ( ) const
inline

Get the view matrix object.

Returns
const Matrix4x4&
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_vp_matrix()

const Matrix4x4 & Ragot::Camera::get_vp_matrix ( ) const
inline

Get the vp matrix object.

Returns
const Matrix4x4&
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_dirty()

bool Ragot::Camera::is_dirty ( ) const
inline

Returns the camera's position in world space.

Returns
glm::vec3 The position of the camera.

◆ is_face_visible()

bool Ragot::Camera::is_face_visible ( const vertex_t & v1,
const vertex_t & v2,
const vertex_t & v3 )

Check if a face defined by three vertices is visible from the camera's perspective.

A face is considered visible if its normal vector points towards the camera.

Parameters
v1First vertex of the face.
v2Second vertex of the face.
v3Third vertex of the face.
Returns
true if the face is visible, false otherwise.
Here is the call graph for this function:

◆ log_camera_info()

void Ragot::Camera::log_camera_info ( ) const

Logs the camera's properties for debugging purposes.

This method logs the camera's position, target, field of view, near and far planes, and aspect ratio.

◆ project_to_ndc()

glm::vec3 Ragot::Camera::project_to_ndc ( const glm::vec4 & worldPos) const
inline
Parameters
worldPos
Returns
glm::vec3
Here is the call graph for this function:

◆ set_aspect_ratio()

void Ragot::Camera::set_aspect_ratio ( float ar)
inline

Set the aspect ratio of the camera.

Parameters
arAspect ratio (width/height).

◆ set_far_plane()

void Ragot::Camera::set_far_plane ( float fp)
inline

Set the far clipping plane distance.

Parameters
fpDistance to the far clipping plane.

◆ set_fov()

void Ragot::Camera::set_fov ( float deg)
inline

Set the fov object.

Parameters
degField of view in degrees.

◆ set_location()

void Ragot::Camera::set_location ( const glm::vec3 & p)
inline

Set the camera's position in world space.

Parameters
pPosition of the camera.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_near_plane()

void Ragot::Camera::set_near_plane ( float np)
inline

Set the near clipping plane distance.

Parameters
npDistance to the near clipping plane.

◆ set_target()

void Ragot::Camera::set_target ( const glm::vec3 & t)
inline

Set the camera's target position in world space.

Parameters
tTarget position of the camera.
Here is the caller graph for this function:

Member Data Documentation

◆ aspect_ratio

float Ragot::Camera::aspect_ratio
private

aspect ratio (width/height)

◆ CAMERA_TAG

const char * Ragot::Camera::CAMERA_TAG = "Camera"
staticprivate

Tag for logging camera-related messages.

◆ far_plane

float Ragot::Camera::far_plane
private

far clipping plane distance

◆ fov

float Ragot::Camera::fov
private

vertical field of view in degrees

◆ near_plane

float Ragot::Camera::near_plane
private

near clipping plane distance

◆ projDirty

bool Ragot::Camera::projDirty = true
mutableprivate

flag to indicate if projection matrix is dirty

◆ projection_matrix

Matrix4x4 Ragot::Camera::projection_matrix
mutableprivate

cached projection matrix

◆ target

glm::vec3 Ragot::Camera::target
private

world space look-at target

◆ view_matrix

Matrix4x4 Ragot::Camera::view_matrix
mutableprivate

cached view matrix

◆ viewDirty

bool Ragot::Camera::viewDirty = true
mutableprivate

flag to indicate if view matrix is dirty

◆ vp_matrix

Matrix4x4 Ragot::Camera::vp_matrix
mutableprivate

cached view-projection matrix

◆ vpDirty

bool Ragot::Camera::vpDirty = true
mutableprivate

flag to indicate if view-projection matrix is dirty


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