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

Class for managing a 3D scene. More...

#include <Scene.hpp>

Collaboration diagram for Ragot::Scene:
Collaboration graph

Public Member Functions

 Scene ()
 Default constructor for the Scene class.
 
 ~Scene ()=default
 Destructor for the Scene class.
 
 Scene (Camera *camera)
 Construct a new Scene object.
 
void add_node (std::shared_ptr< Node > node, const basics::Id name)
 Adds a node to the scene with a specified name.
 
void remove_node (std::shared_ptr< Node > node)
 Removes a node from the scene.
 
std::shared_ptr< Nodefind_node (const basics::Id name)
 Finds a node in the scene by its name.
 
void set_main_camera (Camera *camera)
 Sets the main camera for the scene.
 
Cameraget_main_camera () const
 Gets the main camera of the scene.
 
void traverse (const std::function< void(std::shared_ptr< Node >) > &callback)
 Traverses the scene graph and applies a callback function to each node.
 
template<typename T>
std::vector< std::shared_ptr< T > > collect_components ()
 Collects all components of a specified type from the scene.
 
void update (float delta_time)
 Updates the scene with a specified delta time.
 
std::shared_ptr< Nodeget_root ()
 Get the root object.
 
const std::shared_ptr< Nodeget_root () const
 Get the root object.
 
void start ()
 Starts the scene, setting the running flag to true.
 
void stop ()
 Stops the scene, setting the running flag to false.
 

Private Member Functions

void task_update (std::stop_token, float delta_time)
 Task to update the scene in a separate thread.
 

Private Attributes

Cameramain_camera = nullptr
 Pointer to the main camera used for rendering the scene.
 
std::shared_ptr< Noderoot_node
 Shared pointer to the root node of the scene graph.
 
std::unordered_map< basics::Id, std::shared_ptr< Node > > named_nodes
 Map of named nodes for quick access by name.
 
std::atomic< bool > running = false
 Flag indicating whether the scene is currently running or not.
 

Detailed Description

Class for managing a 3D scene.

The Scene class provides methods to manage nodes, cameras, and scene traversal. It allows adding and removing nodes, setting the main camera, and traversing the scene graph.

Constructor & Destructor Documentation

◆ Scene() [1/2]

Ragot::Scene::Scene ( )

Default constructor for the Scene class.

Initializes the scene with a root node and prepares it for use.

Here is the call graph for this function:

◆ ~Scene()

Ragot::Scene::~Scene ( )
default

Destructor for the Scene class.

◆ Scene() [2/2]

Ragot::Scene::Scene ( Camera * camera)

Construct a new Scene object.

Parameters
cameraPointer to the Camera object to be used as the main camera for the scene.
Here is the call graph for this function:

Member Function Documentation

◆ add_node()

void Ragot::Scene::add_node ( std::shared_ptr< Node > node,
const basics::Id name )

Adds a node to the scene with a specified name.

Parameters
nodeShared pointer to the Node object to be added to the scene.
nameUnique identifier for the node, used for quick access.

◆ collect_components()

template<typename T>
template std::vector< std::shared_ptr< Camera > > Ragot::Scene::collect_components< Camera > ( )

Collects all components of a specified type from the scene.

This method traverses the scene graph and collects all components of the specified type.

Template Parameters
TThe type of component to collect.
Returns
std::vector<std::shared_ptr<T>> A vector containing shared pointers to the collected components.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_node()

std::shared_ptr< Node > Ragot::Scene::find_node ( const basics::Id name)

Finds a node in the scene by its name.

Parameters
nameUnique identifier for the node to be found.
Returns
std::shared_ptr<Node> Shared pointer to the found Node object, or nullptr if not found.

◆ get_main_camera()

Camera * Ragot::Scene::get_main_camera ( ) const
inline

Gets the main camera of the scene.

Returns
Camera* Pointer to the main Camera object used for rendering the scene.
Here is the caller graph for this function:

◆ get_root() [1/2]

std::shared_ptr< Node > Ragot::Scene::get_root ( )
inline

Get the root object.

Returns
std::shared_ptr < Node >

◆ get_root() [2/2]

const std::shared_ptr< Node > Ragot::Scene::get_root ( ) const
inline

Get the root object.

Returns
const std::shared_ptr < Node >

◆ remove_node()

void Ragot::Scene::remove_node ( std::shared_ptr< Node > node)

Removes a node from the scene.

Parameters
nodeShared pointer to the Node object to be removed from the scene.

◆ set_main_camera()

void Ragot::Scene::set_main_camera ( Camera * camera)

Sets the main camera for the scene.

Parameters
cameraPointer to the Camera object to be set as the main camera for the scene.

◆ start()

void Ragot::Scene::start ( )
inline

Starts the scene, setting the running flag to true.

This method is used to indicate that the scene is active and should be updated.

Here is the caller graph for this function:

◆ stop()

void Ragot::Scene::stop ( )
inline

Stops the scene, setting the running flag to false.

This method is used to indicate that the scene is no longer active and should not be updated.

◆ task_update()

void Ragot::Scene::task_update ( std::stop_token stop_token,
float delta_time )
private

Task to update the scene in a separate thread.

This method runs in a separate thread and updates the scene based on the delta time. It uses a stop token to allow for graceful termination of the task.

Parameters
stop_tokenToken to signal when the task should stop.
delta_timeThe time elapsed since the last update, in seconds.

< Espera inicial para asegurar que la cámara esté lista.

< Espera inicial para asegurar que la cámara esté lista.

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

◆ traverse()

void Ragot::Scene::traverse ( const std::function< void(std::shared_ptr< Node >) > & callback)

Traverses the scene graph and applies a callback function to each node.

This method allows for custom operations on each node in the scene graph.

Parameters
callbackFunction to be called for each node in the scene graph.
Here is the caller graph for this function:

◆ update()

void Ragot::Scene::update ( float delta_time)

Updates the scene with a specified delta time.

This method updates the scene, allowing for animations or other time-based changes.

Parameters
delta_timeThe time elapsed since the last update, in seconds.
Here is the call graph for this function:

Member Data Documentation

◆ main_camera

Camera* Ragot::Scene::main_camera = nullptr
private

Pointer to the main camera used for rendering the scene.

◆ named_nodes

std::unordered_map<basics::Id, std::shared_ptr < Node > > Ragot::Scene::named_nodes
private

Map of named nodes for quick access by name.

◆ root_node

std::shared_ptr< Node > Ragot::Scene::root_node
private

Shared pointer to the root node of the scene graph.

◆ running

std::atomic<bool> Ragot::Scene::running = false
private

Flag indicating whether the scene is currently running or not.


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