Vulkan Schnee 0.0.1
High-performance rendering engine
Loading...
Searching...
No Matches
Engine::Entities::SceneNode Class Reference

Represents a node in the scene graph, containing information about its position, rotation, and scale relative to its parent. It also holds references to its parent and children nodes. More...

#include <SceneGraph.h>

Inheritance diagram for Engine::Entities::SceneNode:
Collaboration diagram for Engine::Entities::SceneNode:

Public Member Functions

 ~SceneNode ()
Ecs::TransformgetLocalTransform ()
 Gets the local transform of the scene node. The local transform is relative to the parent node.
const Ecs::TransformgetLocalTransform () const
void registerWithEcs ()
entt::entity getEntity () const
 Gets the entity associated with this scene node.
void setWorldPosition (const glm::vec3 &newLocation)
 Sets the world position of the scene node. This will calculate the corresponding local position based on the parent's world transform.
void setWorldRotation (const glm::vec3 &newRotation)
 Sets the world rotation of this node with euler angles.
void setWorldRotation (const glm::quat &newRotation)
 Sets a new world rotation with a quaternion on this node.
void rotateWorld (const glm::vec3 &deltaRotation)
 Applies an incremental rotation to the current world rotation using quaternion multiplication. This avoids euler angle instability that occurs with get/set rotation round-trips.
void rotateWorld (const glm::quat &deltaRotation)
 Applies an incremental rotation to the current world rotation using quaternion multiplication.
void setWorldScale (const glm::vec3 &newScale)
 sets the scale for this node
void setLocalModelMatrix (const glm::mat4 &newModelMatrix)
 Overwrites all components of the transform.
void setWorldModelMatrix (const glm::mat4 &newModelMatrix)
 Overwrites all components of this transform.
void addChild (const std::shared_ptr< SceneNode > &newChild)
 Adds a child node to this node.
void addChildren (std::vector< std::shared_ptr< SceneNode > > newChildren)
 adds new children to this node
void clearChildren ()
 Removes all children from this node.
void removeChild (const std::shared_ptr< SceneNode > &child)
 Removes a single child from this node.
const glm::mat4 & getWorldMatrix () const
 get the world matrix as a raw glm matrix
bool isWorldMatrixDirty () const
 Checks if the world matrix has to be recalculated.
bool isRoot () const
 Checks if this node is the root node.
std::vector< std::weak_ptr< SceneNode > > getChildren () const
 Get a list of all children of this node.
void markDirtyRecursive () const
 Marks this node and its children as dirty.

Protected Member Functions

 SceneNode (entt::registry &registry, bool disableCaching=false)
 Constructs a new Scene Node object.

Private Member Functions

void updateWorldMatrix () const

Private Attributes

std::weak_ptr< SceneNodeparent_
std::vector< std::shared_ptr< SceneNode > > children_
size_t indexInParent_ = 0
entt::entity entity_
entt::registry * registry
glm::mat4 worldMatrix
bool disableCaching = false

Detailed Description

Represents a node in the scene graph, containing information about its position, rotation, and scale relative to its parent. It also holds references to its parent and children nodes.

Definition at line 18 of file SceneGraph.h.

Constructor & Destructor Documentation

◆ SceneNode()

Engine::Entities::SceneNode::SceneNode ( entt::registry & registry,
bool disableCaching = false )
explicitprotected

Constructs a new Scene Node object.

Parameters
registryentt registry where the transform should be registered to
disableCachingIf true, the world matrix of this node will be recalculated every time it is requested, rather than being cached. This is useful for nodes that change frequently.

References disableCaching, and registry.

◆ ~SceneNode()

Engine::Entities::SceneNode::~SceneNode ( )

Member Function Documentation

◆ addChild()

void Engine::Entities::SceneNode::addChild ( const std::shared_ptr< SceneNode > & newChild)

Adds a child node to this node.

Parameters
newChildchild node to add to this node

◆ addChildren()

void Engine::Entities::SceneNode::addChildren ( std::vector< std::shared_ptr< SceneNode > > newChildren)

adds new children to this node

Parameters
newChildrenlist of new children to add to this node

◆ clearChildren()

void Engine::Entities::SceneNode::clearChildren ( )

Removes all children from this node.

◆ getChildren()

std::vector< std::weak_ptr< SceneNode > > Engine::Entities::SceneNode::getChildren ( ) const

Get a list of all children of this node.

Returns
list of all children of this node

◆ getEntity()

entt::entity Engine::Entities::SceneNode::getEntity ( ) const

Gets the entity associated with this scene node.

Returns
The entt entity for this node.

◆ getLocalTransform() [1/2]

Ecs::Transform & Engine::Entities::SceneNode::getLocalTransform ( )

Gets the local transform of the scene node. The local transform is relative to the parent node.

Returns
A reference to the local LocalTransform ECS component.

◆ getLocalTransform() [2/2]

const Ecs::Transform & Engine::Entities::SceneNode::getLocalTransform ( ) const

◆ getWorldMatrix()

const glm::mat4 & Engine::Entities::SceneNode::getWorldMatrix ( ) const

get the world matrix as a raw glm matrix

Returns
the world matrix

◆ isRoot()

bool Engine::Entities::SceneNode::isRoot ( ) const

Checks if this node is the root node.

Returns
true if it is the root node

◆ isWorldMatrixDirty()

bool Engine::Entities::SceneNode::isWorldMatrixDirty ( ) const

Checks if the world matrix has to be recalculated.

Returns
if the world matrix is dirty

◆ markDirtyRecursive()

void Engine::Entities::SceneNode::markDirtyRecursive ( ) const

Marks this node and its children as dirty.

◆ registerWithEcs()

void Engine::Entities::SceneNode::registerWithEcs ( )

◆ removeChild()

void Engine::Entities::SceneNode::removeChild ( const std::shared_ptr< SceneNode > & child)

Removes a single child from this node.

Parameters
childthe child to remove

◆ rotateWorld() [1/2]

void Engine::Entities::SceneNode::rotateWorld ( const glm::quat & deltaRotation)

Applies an incremental rotation to the current world rotation using quaternion multiplication.

Parameters
deltaRotationquaternion to multiply with the current rotation

◆ rotateWorld() [2/2]

void Engine::Entities::SceneNode::rotateWorld ( const glm::vec3 & deltaRotation)

Applies an incremental rotation to the current world rotation using quaternion multiplication. This avoids euler angle instability that occurs with get/set rotation round-trips.

Parameters
deltaRotationeuler angles (degrees) to rotate by

◆ setLocalModelMatrix()

void Engine::Entities::SceneNode::setLocalModelMatrix ( const glm::mat4 & newModelMatrix)

Overwrites all components of the transform.

Parameters
newModelMatrixnew 4x4 model matrix

◆ setWorldModelMatrix()

void Engine::Entities::SceneNode::setWorldModelMatrix ( const glm::mat4 & newModelMatrix)

Overwrites all components of this transform.

Parameters
newModelMatrixnew 4x4 model matrix

◆ setWorldPosition()

void Engine::Entities::SceneNode::setWorldPosition ( const glm::vec3 & newLocation)

Sets the world position of the scene node. This will calculate the corresponding local position based on the parent's world transform.

Parameters
newLocationThe new position in world space.

◆ setWorldRotation() [1/2]

void Engine::Entities::SceneNode::setWorldRotation ( const glm::quat & newRotation)

Sets a new world rotation with a quaternion on this node.

Parameters
newRotationquaternion rotation

◆ setWorldRotation() [2/2]

void Engine::Entities::SceneNode::setWorldRotation ( const glm::vec3 & newRotation)

Sets the world rotation of this node with euler angles.

Parameters
newRotationyaw pitch roll

◆ setWorldScale()

void Engine::Entities::SceneNode::setWorldScale ( const glm::vec3 & newScale)

sets the scale for this node

Parameters
newScalethe scale to be set to

◆ updateWorldMatrix()

void Engine::Entities::SceneNode::updateWorldMatrix ( ) const
private

Member Data Documentation

◆ children_

std::vector<std::shared_ptr<SceneNode> > Engine::Entities::SceneNode::children_
private

Definition at line 171 of file SceneGraph.h.

◆ disableCaching

bool Engine::Entities::SceneNode::disableCaching = false
private

Definition at line 178 of file SceneGraph.h.

Referenced by SceneNode().

◆ entity_

entt::entity Engine::Entities::SceneNode::entity_
private

Definition at line 174 of file SceneGraph.h.

◆ indexInParent_

size_t Engine::Entities::SceneNode::indexInParent_ = 0
private

Definition at line 172 of file SceneGraph.h.

◆ parent_

std::weak_ptr<SceneNode> Engine::Entities::SceneNode::parent_
private

Definition at line 170 of file SceneGraph.h.

◆ registry

entt::registry* Engine::Entities::SceneNode::registry
private

Definition at line 175 of file SceneGraph.h.

Referenced by Engine::Entities::RootNode::RootNode(), and SceneNode().

◆ worldMatrix

glm::mat4 Engine::Entities::SceneNode::worldMatrix
mutableprivate

Definition at line 177 of file SceneGraph.h.


The documentation for this class was generated from the following file:
  • /home/magerbeton/Documents/gl3-vulkan/Engine/include/Engine/World/SceneGraph.h