21#include <glm/gtc/matrix_transform.hpp>
22#include <glm/gtc/quaternion.hpp>
41class Node :
public std::enable_shared_from_this<Node> {
52 Node(
const std::string &name =
"Node");
128 inline const glm::vec3 &
get_scale()
const {
return m_scale; }
138 void rotate(
float angle,
const glm::vec3 &axis);
157 void look_at(
const glm::vec3 &target,
const glm::vec3 &up = glm::vec3(0.0f, 1.0f, 0.0f));
187 void add_child(std::shared_ptr<Node> child);
205 inline std::shared_ptr<Node>
get_parent()
const {
return m_parent.lock(); }
214 inline const std::vector<std::shared_ptr<Node>> &
get_children()
const {
return m_children; }
241 inline void set_mesh(std::shared_ptr<Mesh> mesh) { m_mesh = mesh; }
250 inline std::shared_ptr<Mesh>
get_mesh()
const {
return m_mesh; }
259 inline bool has_mesh()
const {
return m_mesh !=
nullptr; }
277 inline void set_name(
const std::string &name) { m_name = name; }
284 inline std::shared_ptr<Light>
get_light()
const {
return m_light; }
291 inline void set_light(std::shared_ptr<Light> light) { m_light = light; }
303 inline void set_lod(std::shared_ptr<LOD> lod) { m_lod = lod; };
310 inline std::shared_ptr<LOD>
get_lod()
const {
return m_lod; }
317 inline bool has_lod()
const {
return m_lod !=
nullptr && m_lod->has_levels(); }
335 glm::vec3 m_position{0.0f, 0.0f, 0.0f};
338 glm::quat m_rotation{1.0f, 0.0f, 0.0f, 0.0f};
341 glm::vec3 m_scale{1.0f, 1.0f, 1.0f};
344 glm::mat4 m_local_transform{1.0f};
347 glm::mat4 m_world_transform{1.0f};
350 std::weak_ptr<Node> m_parent;
353 std::vector<std::shared_ptr<Node>> m_children;
356 std::shared_ptr<Mesh> m_mesh;
359 std::shared_ptr<Light> m_light;
362 std::shared_ptr<LOD> m_lod;
370 void update_local_transform();
void set_position(const glm::vec3 &position)
Set the position of the node.
Definition node.cpp:16
Node(const std::string &name="Node")
Constructor for the Node class.
Definition node.cpp:12
glm::mat4 get_local_transform() const
Get the local and world transforms of the node.
Definition node.hpp:166
void set_scale(const glm::vec3 &scale)
Set the scale of the node.
Definition node.cpp:32
void add_child(std::shared_ptr< Node > child)
Manage child nodes.
Definition node.cpp:58
bool has_lod() const
Check if the node has an associated LOD with levels.
Definition node.hpp:317
void update_transform(const glm::mat4 &par_transform=glm::mat4(1.0f))
Update transforms.
Definition node.cpp:90
std::shared_ptr< Light > get_light() const
Retrieves the light associated with the node.
Definition node.hpp:284
void look_at(const glm::vec3 &target, const glm::vec3 &up=glm::vec3(0.0f, 1.0f, 0.0f))
Make the node look at a target point.
Definition node.cpp:50
void set_mesh(std::shared_ptr< Mesh > mesh)
Manage the mesh associated with the node.
Definition node.hpp:241
const glm::quat & get_rotation() const
Get the rotation of the node.
Definition node.hpp:119
glm::vec3 get_euler_angles() const
Get the Euler angles of the node's rotation.
Definition node.cpp:48
void set_lod(std::shared_ptr< LOD > lod)
Set the LOD (Level of Detail) for the node.
Definition node.hpp:303
const glm::vec3 & get_scale() const
Get the scale of the node.
Definition node.hpp:128
const glm::vec3 & get_position() const
Getters for position, rotation, scale, and transforms.
Definition node.hpp:110
void remove_child(std::shared_ptr< Node > child)
Remove a child node.
Definition node.cpp:67
std::shared_ptr< LOD > get_lod() const
Get the LOD (Level of Detail) associated with the node.
Definition node.hpp:310
void set_rotation(const glm::quat &rotation)
Set the rotation of the node.
Definition node.cpp:21
void rotate(float angle, const glm::vec3 &axis)
Rotate the node around a specified axis.
Definition node.cpp:42
const std::vector< std::shared_ptr< Node > > & get_children() const
Get the list of child nodes.
Definition node.hpp:214
std::shared_ptr< Mesh > get_mesh_for_rendering(const glm::vec3 &camera_pos) const
Get the appropriate mesh for rendering based on camera position.
Definition node.cpp:97
bool has_mesh() const
Check if the node has an associated mesh.
Definition node.hpp:259
void detach_from_parent()
Detach the node from its parent.
Definition node.cpp:77
bool has_light() const
Check if node has a light.
Definition node.hpp:296
void set_light(std::shared_ptr< Light > light)
Set the light associated with the node.
Definition node.hpp:291
void set_name(const std::string &name)
Set the name of the node.
Definition node.hpp:277
std::shared_ptr< Node > get_parent() const
Getters for parent and children.
Definition node.hpp:205
glm::mat4 get_world_transform() const
Get the world transform of the node.
Definition node.hpp:175
std::shared_ptr< Mesh > get_mesh() const
Get the mesh associated with the node.
Definition node.hpp:250
~Node()=default
Destructor for the Node class.
std::string & get_name()
Getters and setters for the node's name.
Definition node.hpp:268
Definition of the Light class and LightType enumeration.
Level of Detail (LOD) management for 3D objects.
Defines the Mesh class for managing 3D mesh data.
Namespace for scene-related classes and functions.
Definition camera.cpp:7
Forward declarations for Assimp Material structure.
Definition model_loader.cpp:12