yage.scene.node
Authors:
Eric Poggel
License:
LGPL v3
- abstract class
Node
: yage.core.tree.Tree!(Node).Tree, yage.core.object2.IDisposable, yage.core.object2.ICloneable;
- Nodes are used for building scene graphs in Yage.
Every node has an array of child nodes as well as a parent node, with
the exception of a Scene that exists at the top of the scene graph and has no parent.
When one node is moved or rotated, all of its child nodes move and rotate as well.
Likewise, setting the position or rotation of a node does so relative to its parent.
Rendering is done recursively from the Scene down through every child node.
Likewise, updating of position and rotation occurs recursively from Scene's update() method.
All other Nodes extend this class.
Methods for modifying the hierarchy of Nodes (parents, children) are defined here.
Example:
Scene s = new Scene();
ModelNode a = s.addChild(new ModelNode()); // a is a child of s, it exists in Scene s.
a.setPosition(3, 5, 0); // Position is set relative to 0, 0, 0 of the entire scene.
a.setRotation(0, 3.14, 0); // a is rotated PI radians (180 degrees) around the Y axis.
SpriteNode b = new SpriteNode(a); // b is a child of a, therefore,
b.setPosition(5, 0, 0); // its positoin and rotation are relative to a's.
b.getAbsolutePosition(); // Returns Vec3f(-2, 5, 0), b's position relative to the origin.
s.addChild(b); // b is now a child of s.
b.getAbsolutePosition(); // Returns Vec3f(5, 0, 0), since it's position is relative
// to 0, 0, 0, instead of a.
- this();
- Constructor
- T
addChild
(T)(T child);
- Add a child Node to this Node's array of children.
Overridden to call ancestorChange() and mark transformation matrices dirty.
Params:
Returns:
The child Node that was added. Templating is used to ensure the return type is exactly the same.
- T
removeChild
(T)(T child);
- Remove a child Node to this Node's array of children.
Overridden to call ancestorChange() and mark transformation matrices dirty.
Params:
child |
The Node to remove. |
Returns:
The child Node that was removed. Templating is used to ensure the return type is exactly the same.
- Node
clone
();
Node
clone
(bool children);
- Make a duplicate of this node, unattached to any parent Node.
Params:
children |
recursively
clone
children (and descendants) and add them as children to the new Node. |
Returns:
The cloned Node.
- void
dispose
();
- Some types of Nodes may need to free resources before being destructed.
- float
getLifetime
();
void
setLifetime
(float seconds);
- Get / set the lifeime of a Node (in seconds).
The default lifetime is float.infinity. A lower number will cause the Node to be removed
from the scene graph after that amount of time.
It's lifetime is decreased every time update() is called (usually by the Node's scene).
- Scene
getScene
();
- Get the Scene at the top of the tree that this node belongs to, or null
if this is part of a scene-less node tree.
- char[]
getType
();
- Get the type of this Node as a string; i.e. "yage.scene.visible.ModelNode".
- bool
getVisible
();
- Always returns false
for Nodes but can be true
for subtypes.
- char[]
toString
();
- Return a string representation of this Node for human reading.
- void
onUpdate
(void delegate(Node self) on_update);
- Set a function that will be called every time this Node is updated.
Specifically, the supplied function is called after a Node's matrices
are updated and before its children are updated and before it's removed if
it's lifetime is zero.
Params:
void delegate(Node self) on_update |
the function that will be called. Use null
as an argument to clear
the function. |
Example:
SpriteNode s = new SpriteNode(scene);
s.setMaterial("something.xml");
// Gradually fade to transparent as lifetime decreases.
void fade(Node self)
{ SpriteNode node = cast(SpriteNode)self;
node.setColor(1, 1, 1, node.getLifetime()/5);
}
s.setLifetime(5);
s.onUpdate(&fade);
- void
update
(float delta);
- Update the positions and rotations of this Node and all children by delta seconds.
|