Represents a camera in a 3D space, managing its properties and transformations. More...
#include <Camera.hpp>
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 Matrix4x4 & | get_projection_matrix () const |
Get the projection matrix object. | |
const Matrix4x4 & | get_view_matrix () const |
Get the view matrix object. | |
const Matrix4x4 & | get_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. | |
![]() | |
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. | |
Component & | operator= (const Component &)=delete |
Deleted assignment operator for the Component class. | |
Component & | operator= (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. | |
![]() | |
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. | |
Node & | operator= (const Node &)=delete |
Deleted assignment operator for Node. Prevents assignment of Node instances. | |
Node & | operator= (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. | |
![]() | |
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 | |
![]() | |
std::vector< std::shared_ptr< Component > > | components |
Collection of components managed by this Component instance. | |
![]() | |
std::vector< std::shared_ptr< Node > > | children |
List of child nodes. | |
Node * | parent = nullptr |
Pointer to the parent node. | |
![]() | |
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. | |
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).
using Ragot::Camera::Matrix4x4 = glm::mat4 |
|
delete |
Delete default constructor to prevent instantiation without parameters.
|
inline |
Constructs a Camera object with specified parameters.
aspect_ratio | Aspect ratio of the camera (default is 1.0). |
near_plane | Distance to the near clipping plane (default is 1.0). |
far_plane | Distance to the far clipping plane (default is 100.0). |
fov_deg | Vertical field of view in degrees (default is 60.0). |
|
default |
Default destructor for Camera class.
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.
v1 | First vertex of the face. |
v2 | Second vertex of the face. |
v3 | Third vertex of the face. |
|
inline |
Returns the camera's aspect ratio (width/height).
|
inline |
Returns the camera's far clipping plane distance.
|
inline |
Returns the camera's field of view in degrees.
|
inline |
Returns the camera's position in world space.
|
inline |
Returns the camera's near clipping plane distance.
|
inline |
Get the projection matrix object.
|
inline |
Get the right direction object.
|
inline |
Returns the camera's target position in world space.
|
inline |
Get the up direction object.
|
inline |
Get the view direction object.
|
inline |
Get the view matrix object.
|
inline |
Get the vp matrix object.
|
inline |
Returns the camera's position in world space.
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.
v1 | First vertex of the face. |
v2 | Second vertex of the face. |
v3 | Third vertex of the face. |
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.
|
inline |
worldPos |
|
inline |
Set the aspect ratio of the camera.
ar | Aspect ratio (width/height). |
|
inline |
Set the far clipping plane distance.
fp | Distance to the far clipping plane. |
|
inline |
Set the fov object.
deg | Field of view in degrees. |
|
inline |
Set the camera's position in world space.
p | Position of the camera. |
|
inline |
Set the near clipping plane distance.
np | Distance to the near clipping plane. |
|
inline |
Set the camera's target position in world space.
t | Target position of the camera. |
|
private |
aspect ratio (width/height)
|
staticprivate |
Tag for logging camera-related messages.
|
private |
far clipping plane distance
|
private |
vertical field of view in degrees
|
private |
near clipping plane distance
|
mutableprivate |
flag to indicate if projection matrix is dirty
|
mutableprivate |
cached projection matrix
|
private |
world space look-at target
|
mutableprivate |
cached view matrix
|
mutableprivate |
flag to indicate if view matrix is dirty
|
mutableprivate |
cached view-projection matrix
|
mutableprivate |
flag to indicate if view-projection matrix is dirty