#include <Node.h>
Public Types | |
typedef STDEXT::hash_set< Node *, detail::node_hash, detail::node_equals > | node_set |
Convenience container type for storing a unique set of nodes. | |
typedef std::pair< Vector2f, Vector2f > | extents_t |
Result type returned from extents() method. | |
Iterator Types | |
typedef iterator_by_tag < random_access >::iterator | iterator_random_access |
Provides a random access iterator. | |
typedef iterator_by_tag < by_sequence >::iterator | iterator_by_sequence |
Provides an iterator ordered on insertion order. | |
typedef iterator_by_tag< by_id > ::iterator | iterator_by_id |
Provides an iterator ordered by Node id. | |
typedef iterator_by_tag < by_name >::iterator | iterator_by_name |
Provides an iterator ordered by Node name. | |
typedef iterator_by_tag < by_spatial_x >::iterator | iterator_by_spatial_x |
Provides an iterator ordered by Node x position. | |
typedef iterator_by_tag < by_spatial_y >::iterator | iterator_by_spatial_y |
Provides an iterator ordered by Node y position. | |
typedef iterator_by_tag < by_sequence >::iterator | iterator |
Default iterator. Same as Node::iterator_by_sequence. | |
typedef const_iterator_by_tag < random_access >::iterator | const_iterator_random_access |
Provides a const random access iterator. | |
typedef const_iterator_by_tag < by_sequence >::iterator | const_iterator_by_sequence |
Provides a const iterator ordered on insertion order. | |
typedef const_iterator_by_tag < by_id >::iterator | const_iterator_by_id |
Provides a const iterator ordered by Node id. | |
typedef const_iterator_by_tag < by_name >::iterator | const_iterator_by_name |
Provides a const iterator ordered by Node name. | |
typedef const_iterator_by_tag < by_spatial_x >::iterator | const_iterator_by_spatial_x |
Provides a const iterator ordered by Node x position. | |
typedef const_iterator_by_tag < by_spatial_y >::iterator | const_iterator_by_spatial_y |
Provides a const iterator ordered by Node x position. | |
typedef const_iterator_by_tag < by_sequence >::iterator | const_iterator |
Default const iterator. Same as Node::const_iterator_by_sequence. | |
Public Member Functions | |
Node () | |
Default constructor. | |
Node (const std::string &name) | |
Constructs a Node with a unique ID and name. | |
Node (const Node &node) | |
Copy constructor. | |
Spatial and Geometric Methods | |
virtual void | getDataPoints (std::vector< Vector2f > &points) const |
Appends the points of this Node to a points list. | |
virtual extents_t | extents () const |
Returns the bounding box of the current Node in object space. | |
virtual Vector2f | worldToObject (const Vector2f &world) const |
Returns object space coordinates of the given world space point. | |
virtual Vector2f | objectToWorld (const Vector2f &object) const |
Returns world space coordinates of the given object space point. | |
Vector2f | translation () const |
Returns the world translation of the Node. The translation may be influenced by any transformations in the parent Nodes of this Node. | |
float | rotation () const |
Returns the world rotation of the Node. The rotation may be influenced by any transformations in the parent Nodes of this Node. | |
bool | containsPoint (const Vector2f &point) const |
Returns whether the given point is contained inside the Node's geometrical representation (if it has one). | |
Appearance and Rendering Methods | |
Methods used to manipulate the spatial and geometric properties of a Node.
| |
TextureState & | texture () |
Returns the current TextureState. | |
MaterialState & | material () |
Returns the current MaterialState. | |
virtual void | setTexture (const TextureState &texState) |
Sets the current TextureState. | |
virtual void | setMaterial (const MaterialState &matState) |
Sets the current MaterialState. | |
void | setColour (float r, float g, float b) |
Sets the Node's colour. | |
void | setVisible (bool visible) |
Sets the visibility of this Node. | |
bool | visible () |
Gets the visibility of this Node. | |
void | ignoreActiveCamera (SceneNode *scene) |
Sets the node to ignore the currently active Camera's transformation. | |
void | render () |
Renders the current Node and all its children. | |
Hierachy and Event Management Methods | |
int | numChildren () const |
Returns the number of children under this Node. | |
void | attachChild (Node &s) |
Attaches a child to this Node. | |
void | attachChild (Node *s) |
Attaches a child to this Node. | |
void | removeChild (Node &s) |
Remove a child from this Node. | |
void | removeChild (Node *s) |
Remove a child from this Node. | |
void | removeAllChildren () |
Remove all children from this Node. | |
void | removeFromParent () |
Remove this Node from its parent. | |
void | reinsert () |
Removes a Node from its parent and then re-attaches it. | |
void | attachListener (NodeListener *listener, int priority=2) |
Attaches a listener to this Node. | |
void | removeListener (NodeListener *listener) |
Removes a listener from this Node. | |
void | applyToAll (boost::function< void(Node *)> f, bool parentsFirst=false) |
Applies a function to the current Node and all its children. | |
Node * | parent () const |
Get the parent of the current Node. | |
Node * | child (int index) const |
Get the child at the specified index. | |
Node * | findChild (int id) |
Find the Node in the hierarchy of this node with the specified ID. | |
Node * | findChild (const std::string &name) |
Find the first child in the hierachy of this Node with the specified name. | |
void | findAllChildren (const std::string &name, std::vector< Node * > &children) |
Find all children in the hierachy of this Node with the specified name. | |
const std::string & | name () const |
Gets the name of the Node. | |
void | setName (const std::string &name) |
Changes the name of the Node. | |
const int | id () const |
Gets the unique ID of the Node. | |
void | enableEvents (SceneNode *scene) |
Enables the per-Node event system. | |
void | enableMouseDragging () |
Enables dragging of Nodes. | |
void | respondToEvent (boost::signal< void(int, int, int)> &event, int value, const boost::function< void(int, int)> &action, bool trackEvent=false) |
Tell a Node to respond to an event. | |
void | respondToEvent (int priority, boost::signal< void(int, int, int)> &event, int value, const boost::function< void(int, int)> &action, bool trackEvent=false) |
Tell a Node to respond to an event with specified priority. | |
Child Iteration Methods | |
Methods used to retrieve iterators over a Node's children. | |
template<typename Tag> | |
iterator_by_tag< Tag >::iterator | begin () |
Returns an iterator over the children using the specified tag to describe the ordering of the sequence. | |
template<typename Tag> | |
iterator_by_tag< Tag >::iterator | end () |
Returns an iterator representing one past the end of the children for the specific ordering tag. | |
template<typename Tag> | |
const_iterator_by_tag< Tag > ::iterator | begin () const |
Returns a const iterator over the children using the specified tag to describe the ordering of the sequence. | |
template<typename Tag> | |
const_iterator_by_tag< Tag > ::iterator | end () const |
Returns a const iterator representing one past the end of the children for the specific ordering tag. | |
Public Attributes | |
Signals | |
boost::signal< void(Node *) | Destroyed ) |
Triggered when a Node is Destroyed. | |
boost::signal< void(Node *, Node *) | ChildAttached ) |
Triggered when a child is attached to this Node. | |
boost::signal< void(Node *, Node *) | ChildRemoved ) |
Triggered when a child is removed from this Node. | |
boost::signal< void(Node *, Node *) | ParentChanged ) |
Triggered when the parent of this Node is changed or removed. | |
boost::signal< void(Node *) | BeforeDraw ) |
Triggered when a Node is about to be drawn. | |
boost::signal< void(Node *) | AfterDraw ) |
Triggered after a Node is drawn. | |
boost::signal< void(Node *, bool) | VisibilityChanged ) |
Triggered when a Node's visibility changes. | |
Protected Member Functions | |
virtual void | draw () |
Called when a Node is to be drawn. | |
Classes | |
struct | by_id |
Order by ID tag. More... | |
struct | by_name |
Order by name tag. More... | |
struct | by_sequence |
Sequential ordering tag. More... | |
struct | by_spatial_x |
Order by x position tag. More... | |
struct | by_spatial_y |
Order by y position tag. More... | |
struct | random_access |
Random access tag. More... |
Each Node contains a hierarchy of children below it, and one parent above it. Nodes store their children on multiple criteria (by unique ID, by name, by spatial location, by order of insertion). And can provide iterators over their children for each of these orderings.
Nodes are Managed objects. If automatic scene graph management is enabled, then Nodes that are unattached to the scene graph are automatically deleted, unless retain() is called. Nodes may still be deleted manually, however.
Nodes are Spatial objects, and any spatial transform applied to a Node is propogated through its children. Points can be transformed to world or object coordinates using the worldToObject() and objectToWorld() methods.
Nodes also provide a signal interface through which users can be notified of Node-level events, such as when children are added or removed.
typedef STDEXT::hash_set<Node*, detail::node_hash, detail::node_equals> Node::node_set |
Convenience container type for storing a unique set of nodes.
While this type is not used internally to store nodes, it provides a convenient type that other classes can use to keep a unique set of nodes hashed by node id.
typedef std::pair<Vector2f, Vector2f> Node::extents_t |
Result type returned from extents() method.
Boudning box specified by two points. The first is the lower left corner (or minimum point), and the second is the upper right corner (or maximum point).
typedef iterator_by_tag<by_id>::iterator Node::iterator_by_id |
typedef iterator_by_tag<by_name>::iterator Node::iterator_by_name |
typedef const_iterator_by_tag<by_id>::iterator Node::const_iterator_by_id |
typedef const_iterator_by_tag<by_name>::iterator Node::const_iterator_by_name |
Node::Node | ( | ) |
Default constructor.
Constructs a Node with a unique ID but no name.
Node::Node | ( | const std::string & | name | ) |
Node::Node | ( | const Node & | node | ) |
Copy constructor.
Node the copy constructed Nodes still have a unique ID.
virtual void Node::getDataPoints | ( | std::vector< Vector2f > & | points | ) | const [virtual] |
Appends the points of this Node to a points list.
Subclassed Nodes may implement this method to provide an ordered (or unordered) list of points which describe the shape of this Node. The default implementation will get data points from the Node's children to add to the points list.
Note that Nodes may not be constructed of any points or may be used simply to transform other Nodes. In this case the default implementation should be sufficient.
points | vector of points to append to. |
Reimplemented in Shape.
virtual extents_t Node::extents | ( | ) | const [virtual] |
Returns object space coordinates of the given world space point.
world | a point in world space |
world
Reimplemented in OrthoCamera.
Returns world space coordinates of the given object space point.
object | a point in object space |
object
Reimplemented in OrthoCamera.
Vector2f Node::translation | ( | ) | const |
Returns the world translation of the Node. The translation may be influenced by any transformations in the parent Nodes of this Node.
float Node::rotation | ( | ) | const |
Returns the world rotation of the Node. The rotation may be influenced by any transformations in the parent Nodes of this Node.
bool Node::containsPoint | ( | const Vector2f & | point | ) | const |
Returns whether the given point is contained inside the Node's geometrical representation (if it has one).
point | the world space location of the point to test |
TextureState& Node::texture | ( | ) | [inline] |
MaterialState& Node::material | ( | ) | [inline] |
virtual void Node::setTexture | ( | const TextureState & | texState | ) | [virtual] |
Sets the current TextureState.
texState | TextureState to copy into this Node's TextureState |
virtual void Node::setMaterial | ( | const MaterialState & | matState | ) | [virtual] |
Sets the current MaterialState.
matState | MaterialState to copy into this Node's MaterialState |
void Node::setColour | ( | float | r, | |
float | g, | |||
float | b | |||
) |
Sets the Node's colour.
Simply a convenience method to modify the material state of the Node. That is, identical to:
r | red component from 0 to 1 | |
g | green component from 0 to 1 | |
b | blue component from 0 to 1 |
void Node::setVisible | ( | bool | visible | ) |
bool Node::visible | ( | ) | [inline] |
void Node::ignoreActiveCamera | ( | SceneNode * | scene | ) |
Sets the node to ignore the currently active Camera's transformation.
This can be used to force Nodes to draw in the same location regardless of the current camera transformation applied to the scene. This is useful for making permanent fixtures on the screen, such as targeting reticles, visible selection rectangles, and so on.
visible | whether this Node is visible (i.e., rendered) or not. |
void Node::render | ( | ) |
Renders the current Node and all its children.
Usually called once per frame on the root node of the scene graph.
This method calls the protected draw() method on the current Node and each child Node, applying the correct transformations, materials and textures as the children are traversed.
int Node::numChildren | ( | ) | const |
void Node::removeFromParent | ( | ) |
Remove this Node from its parent.
Note that if automatic scene graph management is enabled, then removing a Node from its parent (leaving it with no parent) disconnects the Node from the scene graph, effectively deleting it. The Node will then be queued for deletion at the next possible opportunity.
This can be prevented by re-attaching the node to a new parent, or by calling the retain() method on the Node to increase its reference count (note that release() must be called later to then release the Node).
void Node::reinsert | ( | ) |
Removes a Node from its parent and then re-attaches it.
This method is useful for updating the spatially organised containers of a Node's children. A Node can index its children by their X or Y position, however the X and Y indexing is based on the initial position of the child Node when it was added to its parents. Calling reinsert() on a child Node will update its spatial indexing, putting it in the correct location.
void Node::attachListener | ( | NodeListener * | listener, | |
int | priority = 2 | |||
) |
Attaches a listener to this Node.
A listener responds to all the Signals that a Node provides.
listener | listener to attach. | |
priority | priority of the listener (higher priority listeners are called first). |
void Node::removeListener | ( | NodeListener * | listener | ) |
void Node::applyToAll | ( | boost::function< void(Node *)> | f, | |
bool | parentsFirst = false | |||
) |
Applies a function to the current Node and all its children.
f | function to apply | |
parentsFirst | apply function to parents first, or children first |
Node* Node::parent | ( | ) | const |
Node* Node::child | ( | int | index | ) | const |
Get the child at the specified index.
index | the index of the child to access (from 0 to numChildren()) |
index
Node* Node::findChild | ( | int | id | ) |
Node* Node::findChild | ( | const std::string & | name | ) |
Find the first child in the hierachy of this Node with the specified name.
name | name to search for |
name
(0 if there is no match) void Node::findAllChildren | ( | const std::string & | name, | |
std::vector< Node * > & | children | |||
) |
Find all children in the hierachy of this Node with the specified name.
name | name to search for | |
children | vector of child pointers to fill with matching Nodes |
void Node::setName | ( | const std::string & | name | ) |
const int Node::id | ( | ) | const |
void Node::enableEvents | ( | SceneNode * | scene | ) |
Enables the per-Node event system.
Node based events are events that occur only when input occures inside the Node's geometry. That is, telling a Node to respond to mouse clicks will trigger mouse click events for that Node only when the mouse clicks inside the bounds of the Node.
It is required to pass a SceneNode (of which there is usually one) to the Node when enabling events. This allows the Node to attach itself to the InputSystem used by the SceneNode.
scene | SceneNode to use as event source (usually the root of the scene graph is a scene node, as it contains the active InputSystem. |
void Node::enableMouseDragging | ( | ) |
void Node::respondToEvent | ( | boost::signal< void(int, int, int)> & | event, | |
int | value, | |||
const boost::function< void(int, int)> & | action, | |||
bool | trackEvent = false | |||
) |
Tell a Node to respond to an event.
This is method is used to tell a Node to respond to an event of a given type and value. For example, one can tell a Node to respond to left mouse clicks within its bounds.
The event is given normal priority (InputSystem::PRIORITY_MEDIUM). See below for respondToEvent with priority specification.
//Assume we have some action we wish to trigger called void myAction ( int x, int y ); //Assume we have some InputSystem called input InputSystem input; //Assume we have a root to our scene graph called root, of type SceneNode //Assume that root uses input as its InputSystem SceneNode root; //Connect some events to the myAction function, myAction will only //trigger when these events take place while the mouse is within the //Node's bounds. Node *someNode = new Node(); root.attachChild ( someNode ); someNode->enableEvents ( &root ); //Connect left mouse click: someNode->respondToEvent ( input.MouseClicked, InputSystem::BUTTON_LEFT, boost::bind ( myAction, _1, _2 ) ); //Connect the 'A' key: someNode->respondToEvent ( input.KeyDown, 'A', boost::bind ( myAction, _1, _2 ) );
event | signal of the event to respond to, e.g. InputSystem::MouseClicked | |
value | value of the event, e.g. InputSystem::BUTTON_LEFT, or InputSystem::KEY_UP, or 'a' to respond to the 'a' key. | |
action | function object triggered when the event occurs. The type of the function is void(int,int) where the int arguments are the x and y (world space) location of the mouse. | |
trackEvent | enables mouse tracking for this event, should be set to true for MouseDragged events. |
void Node::respondToEvent | ( | int | priority, | |
boost::signal< void(int, int, int)> & | event, | |||
int | value, | |||
const boost::function< void(int, int)> & | action, | |||
bool | trackEvent = false | |||
) |
Tell a Node to respond to an event with specified priority.
This is method is used to tell a Node to respond to an event of a given type and value. For example, one can tell a Node to respond to left mouse clicks within its bounds.
priority | priority of the event connection (higher priority events will be signalled before lower priority events. See InputSystem::Priority. | |
event | signal of the event to respond to, e.g. InputSystem::MouseClicked | |
value | value of the event, e.g. InputSystem::BUTTON_LEFT, or InputSystem::KEY_UP, or 'a' to respond to the 'a' key. | |
action | function object triggered when the event occurs. The type of the function is void(int,int) where the int arguments are the x and y (world space) location of the mouse. | |
trackEvent | enables mouse tracking for this event, should be set to true for MouseDragged events. |
virtual void Node::draw | ( | ) | [protected, virtual] |
Called when a Node is to be drawn.
Override this method in subclasses to tell a Node how to draw itself on the screen. Drawing should take place in object space (the parent Nodes will apply their own transforms to the rendering stack).
Reimplemented in SceneNode, Circle, Line, Point, Poly, Quad, and Tri.
iterator_by_tag<Tag>::iterator Node::begin | ( | ) | [inline] |
Returns an iterator over the children using the specified tag to describe the ordering of the sequence.
For example:
//Assume we have some node with children, called someNode: Node *someNode; //Access children ordered lexically by name: Node::iterator_by_name nameIter = someNode->begin<Node::by_name>(); //Access children in ascending order by ID: Node::iterator_by_id idIter = someNode->begin<Node::by_id>(); //Access children in ascending order by their world x coordinate: Node::iterator_by_spatial_x xIter = someNode->begin<Node::by_spatial_x>(); //Access children by order of insertion: Node::iterator_by_sequence seqIter = someNode->begin<Node::by_sequence>(); //Note that this is the same as the default iteration type: Node::iterator iter = someNode->begin();
boost::signal<void (Node*) Node::Destroyed) |
boost::signal<void (Node*, Node*) Node::ParentChanged) |
Triggered when the parent of this Node is changed or removed.
Note that the reinsert() method does not trigger a ParentChanged event.
boost::signal<void (Node*) Node::BeforeDraw) |
Triggered when a Node is about to be drawn.
Can be used to do things like set the graphics state.
boost::signal<void (Node*) Node::AfterDraw) |
Triggered after a Node is drawn.
Can be used to do things like restore the graphics state.