Skip to content

Node

Base class for all scene graph objects.

Node represents a transformable object that can be placed within a scene graph hierarchy. Nodes support local and world transforms, parent-child relationships, and can respond to events and updates. All renderable, light-emitting, and camera entities in the engine inherit from this class.

Nodes can be organized in a tree structure, and transformations will propagate through the hierarchy. When attached to a scene, nodes gain access to the shared context and may perform initialization in OnAttached.

To define behavior, override virtual methods such as OnUpdate, OnKeyboardEvent, or OnMouseEvent.

Construction

Constructors


Node()

cpp
vglx::Node::Node()

Constructs an Node instance.

Factories preferred


Node::Create() auto

cpp
static auto vglx::Node::Create()

Creates a shared pointer to a Node object.

Types

Node::Type scoped enum

Enumerates all node types.

ValueDescription
CameraPerspective or orthographic camera.
DefaultGeneric node without special behavior.
InstancedMeshNode containing instanced geometry.
LightLight source (directional, point, or spot).
MeshSingle mesh with an associated material.
RenderableAny node that can be rendered to the screen.
SceneRoot of a scene hierarchy.
SpriteBillboarded sprite.

Properties

frustum_culled bool

cpp
bool frustum_culled { true }

If true, the node is subject to frustum culling during rendering.

transform Transform3

cpp
Transform3 transform

Local transformation.

transform_auto_update bool

cpp
bool transform_auto_update { true }

If true, the local transform is automatically updated before rendering.

up Vector3

cpp
Vector3 up { Vector3::Up() }

Local up direction (defaults to +Y).

Functions

LookAt() void virtual

cpp
virtual void vglx::Node::LookAt(const Vector3 &target)
ParameterDescription
targetTarget world-space position to look at.

Rotates the node to face a given target position in world space.

TranslateX() auto

cpp
auto vglx::Node::TranslateX(float value)
ParameterDescription
valueTranslation distance.

Translates the node along the X axis in local space.

TranslateY() auto

cpp
auto vglx::Node::TranslateY(float value)
ParameterDescription
valueTranslation distance.

Translates the node along the Y axis in local space.

TranslateZ() auto

cpp
auto vglx::Node::TranslateZ(float value)
ParameterDescription
valueTranslation distance.

Translates the node along the Z axis in local space.

RotateX() auto

cpp
auto vglx::Node::RotateX(float angle)
ParameterDescription
angleRotation angle in radians.

Rotates the node along the X axis in local space.

RotateY() auto

cpp
auto vglx::Node::RotateY(float angle)
ParameterDescription
angleRotation angle in radians.

Rotates the node along the Y axis in local space.

RotateZ() auto

cpp
auto vglx::Node::RotateZ(float angle)
ParameterDescription
angleRotation angle in radians.

Rotates the node along the Z axis in local space.

SetScale() auto

cpp
auto vglx::Node::SetScale(const Vector3 &value)
ParameterDescription
valueScale vector applied to the X, Y, and Z axes.

Scales the node non-uniformly in local space.

OnUpdate() void virtual

cpp
virtual void vglx::Node::OnUpdate(float delta)
ParameterDescription
deltaTime in seconds since the last frame.

Called every frame. Override this method to implement per-frame logic or animation.

OnAttached() void virtual

cpp
virtual void vglx::Node::OnAttached(SharedContextPointer context)
ParameterDescription
contextPointer to the shared context (const).

Called when the node becomes part of an attached scene. This method is invoked when the node is added to a scene that is currently attached to the application context. The shared context is guaranteed to be initialized and available. Use this hook to perform resource loading or event registration that depends on application state.

OnKeyboardEvent() void virtual

cpp
virtual void vglx::Node::OnKeyboardEvent(KeyboardEvent *event)
ParameterDescription
eventPointer to the dispatched keyboard event.

Called when a keyboard event is dispatched to this node. Override to handle key presses or releases.

OnMouseEvent() void virtual

cpp
virtual void vglx::Node::OnMouseEvent(MouseEvent *event)
ParameterDescription
eventPointer to the dispatched mouse event.

Called when a mouse event is dispatched to this node. Override to handle mouse movement, clicks, or scrolling.

Add() void

cpp
void vglx::Node::Add(const std::shared_ptr< Node > &node)
ParameterDescription
nodeChild node to add.

Adds a child node to this node.

Children() const std::vector< std::shared_ptr<Node> > &

cpp
const std::vector< std::shared_ptr< Node > > & vglx::Node::Children() const

Returns the list of child nodes.

GetNodeType() Node::Type virtual

cpp
virtual Node::Type vglx::Node::GetNodeType() const

Returns node type.

GetWorldPosition() Vector3

cpp
Vector3 vglx::Node::GetWorldPosition()

Returns the world-space position of this node.

GetWorldTransform() Matrix4

cpp
Matrix4 vglx::Node::GetWorldTransform()

Returns the world transformation matrix of this node.

IsChild() bool

cpp
bool vglx::Node::IsChild(const Node *node) const
ParameterDescription
nodePointer to the node to check.

Checks whether the given node is a direct child of this node.

IsRenderable() bool virtual

cpp
virtual bool vglx::Node::IsRenderable() const

Returns true if the node is renderable.

Parent() constNode*

cpp
const Node * vglx::Node::Parent() const

Returns the parent node.

Remove() void

cpp
void vglx::Node::Remove(const std::shared_ptr< Node > &node)
ParameterDescription
nodeChild node to remove.

Removes a child node from this node.

RemoveAllChildren() void

cpp
void vglx::Node::RemoveAllChildren()

Removes all children from this node.

ShouldUpdateWorldTransform() bool

cpp
bool vglx::Node::ShouldUpdateWorldTransform() const

Determines whether the world transform should be recalculated.

UpdateTransformHierarchy() void

cpp
void vglx::Node::UpdateTransformHierarchy()

Recursively updates this node and all child world transforms. This updates the transformation matrix of the current node first, then propagates the update recursively through all children.

UpdateWorldTransform() void

cpp
void vglx::Node::UpdateWorldTransform()

Updates this node’s world transform, ensuring parent transforms are current. This ensures that the world transform of all ancestors is updated before updating the current node. Required for correct world positioning.

Released under the MIT License.