lmgl 1.0.0
A lightweight OpenGL graphics engine library written in C++
Loading...
Searching...
No Matches
lmgl::scene::Node Class Reference

Represents a node in a scene graph. More...

#include <node.hpp>

Inheritance diagram for lmgl::scene::Node:

Public Member Functions

 Node (const std::string &name="Node")
 Constructor for the Node class.
 
 ~Node ()=default
 Destructor for the Node class.
 
void set_position (const glm::vec3 &position)
 Set the position of the node.
 
void set_rotation (const glm::quat &rotation)
 Set the rotation of the node.
 
void set_rotation (const glm::vec3 &euler_angles)
 Set the rotation of the node using Euler angles.
 
void set_scale (const glm::vec3 &scale)
 Set the scale of the node.
 
void set_scale (float scale)
 Set the uniform scale of the node.
 
const glm::vec3 & get_position () const
 Getters for position, rotation, scale, and transforms.
 
const glm::quat & get_rotation () const
 Get the rotation of the node.
 
const glm::vec3 & get_scale () const
 Get the scale of the node.
 
void rotate (float angle, const glm::vec3 &axis)
 Rotate the node around a specified axis.
 
glm::vec3 get_euler_angles () const
 Get the Euler angles of the node's rotation.
 
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.
 
glm::mat4 get_local_transform () const
 Get the local and world transforms of the node.
 
glm::mat4 get_world_transform () const
 Get the world transform of the node.
 
void add_child (std::shared_ptr< Node > child)
 Manage child nodes.
 
void remove_child (std::shared_ptr< Node > child)
 Remove a child node.
 
std::shared_ptr< Nodeget_parent () const
 Getters for parent and children.
 
const std::vector< std::shared_ptr< Node > > & get_children () const
 Get the list of child nodes.
 
void detach_from_parent ()
 Detach the node from its parent.
 
void update_transform (const glm::mat4 &par_transform=glm::mat4(1.0f))
 Update transforms.
 
void set_mesh (std::shared_ptr< Mesh > mesh)
 Manage the mesh associated with the node.
 
std::shared_ptr< Meshget_mesh () const
 Get the mesh associated with the node.
 
bool has_mesh () const
 Check if the node has an associated mesh.
 
std::string & get_name ()
 Getters and setters for the node's name.
 
void set_name (const std::string &name)
 Set the name of the node.
 
std::shared_ptr< Lightget_light () const
 Retrieves the light associated with the node.
 
void set_light (std::shared_ptr< Light > light)
 Set the light associated with the node.
 
bool has_light () const
 Check if node has a light.
 
void set_lod (std::shared_ptr< LOD > lod)
 Set the LOD (Level of Detail) for the node.
 
std::shared_ptr< LODget_lod () const
 Get the LOD (Level of Detail) associated with the node.
 
bool has_lod () const
 Check if the node has an associated LOD with levels.
 
std::shared_ptr< Meshget_mesh_for_rendering (const glm::vec3 &camera_pos) const
 Get the appropriate mesh for rendering based on camera position.
 

Detailed Description

Represents a node in a scene graph.

The Node class encapsulates the properties and behaviors of a node in a 3D scene graph. Each node can have a position, rotation, scale, and can contain child nodes, forming a hierarchical structure. Nodes can also hold a reference to a Mesh object.

Note
The class uses glm for vector and matrix operations.

Constructor & Destructor Documentation

◆ Node()

lmgl::scene::Node::Node ( const std::string & name = "Node")

Constructor for the Node class.

Initializes a Node with default position, rotation, and scale.

Parameters
nameOptional name for the node.

Member Function Documentation

◆ add_child()

void lmgl::scene::Node::add_child ( std::shared_ptr< Node > child)

Manage child nodes.

Methods to add and remove child nodes, retrieve the parent node, get the list of child nodes, and detach the node from its parent.

Parameters
childChild node to be added or removed.

◆ detach_from_parent()

void lmgl::scene::Node::detach_from_parent ( )

Detach the node from its parent.

Removes this node from its parent's list of children.

◆ get_children()

const std::vector< std::shared_ptr< Node > > & lmgl::scene::Node::get_children ( ) const
inline

Get the list of child nodes.

Provides access to the vector of child nodes.

Returns
Vector of shared pointers to child nodes.

◆ get_euler_angles()

glm::vec3 lmgl::scene::Node::get_euler_angles ( ) const

Get the Euler angles of the node's rotation.

Converts the node's quaternion rotation to Euler angles (in radians).

Returns
Euler angles as a glm::vec3.

◆ get_light()

std::shared_ptr< Light > lmgl::scene::Node::get_light ( ) const
inline

Retrieves the light associated with the node.

Returns
the light associated with the node.

◆ get_local_transform()

glm::mat4 lmgl::scene::Node::get_local_transform ( ) const
inline

Get the local and world transforms of the node.

Provides access to the node's local and world transformation matrices.

Returns
Corresponding transformation matrix.

◆ get_lod()

std::shared_ptr< LOD > lmgl::scene::Node::get_lod ( ) const
inline

Get the LOD (Level of Detail) associated with the node.

Returns
Shared pointer to the LOD object.

◆ get_mesh()

std::shared_ptr< Mesh > lmgl::scene::Node::get_mesh ( ) const
inline

Get the mesh associated with the node.

Provides access to the Mesh object held by the node.

Returns
Shared pointer to the Mesh object.

◆ get_mesh_for_rendering()

std::shared_ptr< Mesh > lmgl::scene::Node::get_mesh_for_rendering ( const glm::vec3 & camera_pos) const

Get the appropriate mesh for rendering based on camera position.

Selects the appropriate mesh level of detail based on the distance from the camera to the node.

Parameters
camera_positionPosition of the camera in world space.
Returns
Shared pointer to the selected Mesh object for rendering.

◆ get_name()

std::string & lmgl::scene::Node::get_name ( )
inline

Getters and setters for the node's name.

Provides access to the node's name property.

Returns
Name of the node.

◆ get_parent()

std::shared_ptr< Node > lmgl::scene::Node::get_parent ( ) const
inline

Getters for parent and children.

Provides access to the parent node and the list of child nodes.

Returns
Corresponding node or list of nodes.

◆ get_position()

const glm::vec3 & lmgl::scene::Node::get_position ( ) const
inline

Getters for position, rotation, scale, and transforms.

Provides access to the node's position, rotation, scale, local transform, and world transform.

Returns
Corresponding property of the node.

◆ get_rotation()

const glm::quat & lmgl::scene::Node::get_rotation ( ) const
inline

Get the rotation of the node.

Provides access to the node's rotation as a quaternion.

Returns
Rotation of the node.

◆ get_scale()

const glm::vec3 & lmgl::scene::Node::get_scale ( ) const
inline

Get the scale of the node.

Provides access to the node's scale.

Returns
Scale of the node.

◆ get_world_transform()

glm::mat4 lmgl::scene::Node::get_world_transform ( ) const
inline

Get the world transform of the node.

Provides access to the node's world transformation matrix.

Returns
World transformation matrix.

◆ has_lod()

bool lmgl::scene::Node::has_lod ( ) const
inline

Check if the node has an associated LOD with levels.

Returns
Boolean indicating presence of a LOD with levels.

◆ has_mesh()

bool lmgl::scene::Node::has_mesh ( ) const
inline

Check if the node has an associated mesh.

Returns true if the node has a Mesh object, false otherwise.

Returns
Boolean indicating presence of a Mesh.

◆ look_at()

void lmgl::scene::Node::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.

Adjusts the node's rotation so that it faces the specified target point.

Parameters
targetTarget point to look at as a glm::vec3.
upUp direction for the node (default is world up).

◆ remove_child()

void lmgl::scene::Node::remove_child ( std::shared_ptr< Node > child)

Remove a child node.

Detaches the specified child node from this node.

Parameters
childChild node to be removed.

◆ rotate()

void lmgl::scene::Node::rotate ( float angle,
const glm::vec3 & axis )

Rotate the node around a specified axis.

Applies a rotation to the node by a given angle around the specified axis.

Parameters
angleRotation angle in radians.
axisAxis of rotation as a glm::vec3.

◆ set_light()

void lmgl::scene::Node::set_light ( std::shared_ptr< Light > light)
inline

Set the light associated with the node.

Parameters
lightThe new light associated with the node

◆ set_lod()

void lmgl::scene::Node::set_lod ( std::shared_ptr< LOD > lod)
inline

Set the LOD (Level of Detail) for the node.

Parameters
lodShared pointer to the LOD object.

◆ set_mesh()

void lmgl::scene::Node::set_mesh ( std::shared_ptr< Mesh > mesh)
inline

Manage the mesh associated with the node.

Methods to set, get, and check for the presence of a Mesh object.

Parameters
meshShared pointer to the Mesh object.

◆ set_name()

void lmgl::scene::Node::set_name ( const std::string & name)
inline

Set the name of the node.

Updates the node's name property.

Parameters
nameNew name for the node.

◆ set_position()

void lmgl::scene::Node::set_position ( const glm::vec3 & position)

Set the position of the node.

Updates the node's position in 3D space.

Parameters
positionNew position as a glm::vec3.

◆ set_rotation() [1/2]

void lmgl::scene::Node::set_rotation ( const glm::quat & rotation)

Set the rotation of the node.

Updates the node's rotation using a quaternion.

Parameters
rotationNew rotation as a glm::quat.

◆ set_rotation() [2/2]

void lmgl::scene::Node::set_rotation ( const glm::vec3 & euler_angles)

Set the rotation of the node using Euler angles.

Updates the node's rotation based on Euler angles (in radians).

Parameters
euler_anglesNew rotation as a glm::vec3 representing Euler angles.

◆ set_scale() [1/2]

void lmgl::scene::Node::set_scale ( const glm::vec3 & scale)

Set the scale of the node.

Updates the node's scale in 3D space.

Parameters
scaleNew scale as a glm::vec3.

◆ set_scale() [2/2]

void lmgl::scene::Node::set_scale ( float scale)

Set the uniform scale of the node.

Updates the node's scale uniformly in all dimensions.

Parameters
scaleNew uniform scale as a float.

◆ update_transform()

void lmgl::scene::Node::update_transform ( const glm::mat4 & par_transform = glm::mat4(1.0f))

Update transforms.

Updates the world transformation matrices of the node. This method should be called whenever the node's position, rotation, or scale changes, or when the parent's transform is updated.

Parameters
par_transformParent's world transform matrix (default is identity).

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