Class for managing a 3D scene. More...
#include <Scene.hpp>
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< Node > | find_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. | |
Camera * | get_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< Node > | get_root () |
Get the root object. | |
const std::shared_ptr< Node > | get_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 | |
Camera * | main_camera = nullptr |
Pointer to the main camera used for rendering the scene. | |
std::shared_ptr< Node > | root_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. | |
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.
Ragot::Scene::Scene | ( | ) |
Default constructor for the Scene class.
Initializes the scene with a root node and prepares it for use.
|
default |
Destructor for the Scene class.
Ragot::Scene::Scene | ( | Camera * | camera | ) |
void Ragot::Scene::add_node | ( | std::shared_ptr< Node > | node, |
const basics::Id | name ) |
Adds a node to the scene with a specified name.
node | Shared pointer to the Node object to be added to the scene. |
name | Unique identifier for the node, used for quick access. |
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.
T | The type of component to collect. |
std::shared_ptr< Node > Ragot::Scene::find_node | ( | const basics::Id | name | ) |
Finds a node in the scene by its name.
name | Unique identifier for the node to be found. |
|
inline |
Gets the main camera of the scene.
|
inline |
Get the root object.
|
inline |
Get the root object.
void Ragot::Scene::remove_node | ( | std::shared_ptr< Node > | node | ) |
Removes a node from the scene.
node | Shared pointer to the Node object to be removed from the scene. |
void Ragot::Scene::set_main_camera | ( | Camera * | camera | ) |
Sets the main camera for the scene.
camera | Pointer to the Camera object to be set as the main camera for the scene. |
|
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.
|
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.
|
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.
stop_token | Token to signal when the task should stop. |
delta_time | The 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.
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.
callback | Function to be called for each node in the scene graph. |
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.
delta_time | The time elapsed since the last update, in seconds. |
|
private |
Pointer to the main camera used for rendering the scene.
|
private |
Map of named nodes for quick access by name.
|
private |
Shared pointer to the root node of the scene graph.
|
private |
Flag indicating whether the scene is currently running or not.