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()

Constructs an Node instance.

cpp
Node::Node();

Factories preferred


Node::Create() auto

Creates a shared pointer to a Node object.

cpp
static auto Node::Create();

Types

Node::Type enum

Enumerates all node types.

Each node subclass identifies its type through Node::GetNodeType, allowing runtime checks and scene traversal logic to distinguish between different kinds of nodes. The engine uses these identifiers internally for tasks such as culling, rendering, and event dispatch.

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

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

cpp
bool frustum_culled {true};

transform Transform3

Local transformation.

cpp
Transform3 transform {};

transform_auto_update bool

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

cpp
bool transform_auto_update {true};

Local up direction (defaults to +Y).

cpp
Vector3 up {Vector3::Up()};

Functions

LookAt() void virtual

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

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

TranslateX() auto

Translates the node along the X axis in local space.

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

TranslateY() auto

Translates the node along the Y axis in local space.

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

TranslateZ() auto

Translates the node along the Z axis in local space.

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

RotateX() auto

Rotates the node along the X axis in local space.

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

RotateY() auto

Rotates the node along the Y axis in local space.

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

RotateZ() auto

Rotates the node along the Z axis in local space.

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

SetScale() auto

Scales the node non-uniformly in local space.

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

OnUpdate() void virtual

Called every frame.

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

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

OnAttached() void virtual

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.

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

OnKeyboardEvent() void virtual

Called when a keyboard event is dispatched to this node.

Override to handle key presses or releases.

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

OnMouseEvent() void virtual

Called when a mouse event is dispatched to this node.

Override to handle mouse movement, clicks, or scrolling.

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

Add() void

Adds a child node to this node.

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

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

Returns the list of child nodes.

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

GetNodeType() Node::Type virtual

Returns node type.

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

GetWorldPosition() Vector3

Returns the world-space position of this node.

cpp
Vector3 Node::GetWorldPosition();

GetWorldTransform() Matrix4

Returns the world transformation matrix of this node.

cpp
Matrix4 Node::GetWorldTransform();

IsChild() bool

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

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

IsRenderable() bool virtual

Returns true if the node is renderable.

cpp
virtual bool Node::IsRenderable() const;

Parent() constNode*

Returns the parent node.

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

Remove() void

Removes a child node from this node.

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

RemoveAllChildren() void

Removes all children from this node.

cpp
void Node::RemoveAllChildren();

ShouldUpdateWorldTransform() bool

Determines whether the world transform should be recalculated.

cpp
bool Node::ShouldUpdateWorldTransform() const;

UpdateTransformHierarchy() void

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.

cpp
void Node::UpdateTransformHierarchy();

UpdateWorldTransform() void

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.

cpp
void Node::UpdateWorldTransform();

Released under the MIT License.