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

Represents a 3D mesh created by extruding a 2D shape along a specified height. This class inherits from the Mesh class and provides methods to generate vertices and faces for the extruded mesh. It also includes methods for culling faces based on the camera's view direction and logging mesh information. More...

#include <ExtrudeMesh.hpp>

Inheritance diagram for Ragot::ExtrudeMesh:
Inheritance graph
Collaboration diagram for Ragot::ExtrudeMesh:
Collaboration graph

Public Member Functions

 ExtrudeMesh (mesh_info_t &mesh_info, const Camera &cam)
 Constructs an ExtrudeMesh object with the specified mesh information and camera reference.
 
 ~ExtrudeMesh ()=default
 Default destructor for the ExtrudeMesh class.
 
void generate_vertices () override
 Deleted copy constructor for the ExtrudeMesh class.
 
void generate_faces () override
 Generates the faces of the extruded mesh.
 
bool are_vertices_coplanar (const glm::fvec4 &v1, const glm::fvec4 &v2, const glm::fvec4 &v3, const glm::fvec4 &v4, float tolerance=0.1f)
 Verifies if four vertices are coplanar.
 
void log_mesh_info () const
 Logs detailed information about the mesh.
 
- Public Member Functions inherited from Ragot::Mesh
 Mesh ()=delete
 Construct a new Mesh object (deleted constructor).
 
virtual ~Mesh ()=default
 Default virtual destructor for the Mesh class.
 
 Mesh (mesh_info_t &mesh_info)
 Construct a new Mesh object with mesh information.
 
const std::vector< glm::fvec4 > & get_vertices () const
 Get the vertices object.
 
const std::vector< face_t > & get_faces () const
 Get the faces object.
 
const size_t get_total_vertices () const
 Get the total vertices object.
 
size_t get_total_vertices ()
 Get the total vertices object.
 
void recalculate ()
 Recalculate the mesh vertices and faces.
 
void apply_transform_to_vertices ()
 Apply the current transformation to the vertices of the mesh. This method applies the transformation matrix obtained from the Transform class to each vertex in the mesh. This is useful for updating the mesh vertices after any transformation has been applied, such as translation, rotation, or scaling. It modifies the vertices in place, transforming them according to the current transformation matrix.
 
void set_color (uint16_t new_color)
 Set the color of the mesh.
 
uint16_t get_color () const
 Get the color of the mesh.
 
- 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).
 

Protected Attributes

float height = 1.0f
 Height of the extrusion.
 
bool faces_can_be_quads = false
 Flag indicating whether the faces can be quads.
 
const Cameracam
 Camera reference for culling faces based on the camera's view direction.
 
glm::vec4 planes [4]
 Array of planes used for culling faces.
 
glm::vec3 camPos
 Position of the camera in world space.
 
- Protected Attributes inherited from Ragot::Mesh
mesh_info_t mesh_info
 Information about the mesh, including coordinates and rendering type.
 
uint16_t color = 0xFFFF
 Color of the mesh, default is white (0xFFFF).
 
std::vector< glm::fvec4 > vertices
 Vector of vertices representing the mesh in 3D space.
 
std::vector< face_tfaces
 Vector of faces representing the mesh, each face can be a triangle or a quad.
 
int slices = 16
 Number of slices for generating the mesh, default is 16.
 
- 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.
 

Static Protected Attributes

static const char * EXTRUDE_TAG = "ExtrudeMesh"
 Tag for logging messages related to the ExtrudeMesh class.
 

Detailed Description

Represents a 3D mesh created by extruding a 2D shape along a specified height. This class inherits from the Mesh class and provides methods to generate vertices and faces for the extruded mesh. It also includes methods for culling faces based on the camera's view direction and logging mesh information.

The ExtrudeMesh class is designed to create a 3D mesh by extruding a 2D shape along a specified height. It uses the GLM library for vector and matrix operations, and includes functionality for face culling based on the camera's view direction. The class also provides a method to log detailed information about the mesh, including its position, rotation, scale, and vertex data.

Constructor & Destructor Documentation

◆ ExtrudeMesh()

Ragot::ExtrudeMesh::ExtrudeMesh ( mesh_info_t & mesh_info,
const Camera & cam )
inline

Constructs an ExtrudeMesh object with the specified mesh information and camera reference.

Parameters
mesh_infoInformation about the mesh to be extruded.
camReference to the camera used for culling faces.
Here is the call graph for this function:

◆ ~ExtrudeMesh()

Ragot::ExtrudeMesh::~ExtrudeMesh ( )
default

Default destructor for the ExtrudeMesh class.

This destructor is used to clean up resources when the ExtrudeMesh object is destroyed.

Member Function Documentation

◆ are_vertices_coplanar()

bool Ragot::ExtrudeMesh::are_vertices_coplanar ( const glm::fvec4 & v1,
const glm::fvec4 & v2,
const glm::fvec4 & v3,
const glm::fvec4 & v4,
float tolerance = 0.1f )

Verifies if four vertices are coplanar.

This method checks if the four vertices v1, v2, v3, and v4 are coplanar within a specified tolerance. It uses the scalar triple product to determine coplanarity.

Parameters
v1First vertex in homogeneous coordinates.
v2Second vertex in homogeneous coordinates.
v3Third vertex in homogeneous coordinates.
v4Fourth vertex in homogeneous coordinates.
toleranceTolerance value for coplanarity check (default is 0.1).
Returns
true if the vertices are coplanar, false otherwise.

The method calculates the scalar triple product of the vectors formed by the vertices and checks if it is close to zero within the specified tolerance. The scalar triple product is computed as the dot product of the first vector with the cross product of the other two vectors. This method is useful for determining if a set of vertices can form a valid face in the mesh.

Note
This method assumes that the vertices are provided in homogeneous coordinates (4D vectors).
Here is the caller graph for this function:

◆ generate_faces()

void Ragot::ExtrudeMesh::generate_faces ( )
overridevirtual

Generates the faces of the extruded mesh.

This method creates the faces of the mesh based on the vertices generated by the generate_vertices method. It checks if the vertices are coplanar and creates either quads or triangles accordingly.

Implements Ragot::Mesh.

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

◆ generate_vertices()

void Ragot::ExtrudeMesh::generate_vertices ( )
overridevirtual

Deleted copy constructor for the ExtrudeMesh class.

This constructor is deleted to prevent copying of ExtrudeMesh objects.

Implements Ragot::Mesh.

Here is the caller graph for this function:

◆ log_mesh_info()

void Ragot::ExtrudeMesh::log_mesh_info ( ) const

Logs detailed information about the mesh.

Here is the call graph for this function:

Member Data Documentation

◆ cam

const Camera& Ragot::ExtrudeMesh::cam
protected

Camera reference for culling faces based on the camera's view direction.

This reference is used to determine which faces of the mesh are visible from the camera's perspective.

◆ camPos

glm::vec3 Ragot::ExtrudeMesh::camPos
protected

Position of the camera in world space.

This vector represents the position of the camera in the 3D world. It is used to calculate the visibility of faces based on the camera's position.

◆ EXTRUDE_TAG

const char * Ragot::ExtrudeMesh::EXTRUDE_TAG = "ExtrudeMesh"
staticprotected

Tag for logging messages related to the ExtrudeMesh class.

◆ faces_can_be_quads

bool Ragot::ExtrudeMesh::faces_can_be_quads = false
protected

Flag indicating whether the faces can be quads.

This flag is set to true if the number of vertices is a multiple of 8 or if it is exactly 4. It determines how faces are generated in the mesh.

◆ height

float Ragot::ExtrudeMesh::height = 1.0f
protected

Height of the extrusion.

This value determines how far the 2D shape is extruded in the Z direction.

◆ planes

glm::vec4 Ragot::ExtrudeMesh::planes[4]
protected

Array of planes used for culling faces.

This array contains the planes that define the view frustum of the camera. It is used to determine which faces are visible and which can be culled.


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