Node Class Reference
[Nodes]

The main class of Scene2D. Nodes are used to represent objects in the scene, and can be animated, selected, and respond to events. More...

#include <Node.h>

Inheritance diagram for Node:

Inheritance graph
[legend]
Collaboration diagram for Node:

Collaboration graph
[legend]

List of all members.

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
Methods used to manipulate the spatial and geometric properties of a Node.

See also:
Spatial


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.

See also:
TextureState, MaterialState


TextureStatetexture ()
 Returns the current TextureState.
MaterialStatematerial ()
 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
Methods used to manipulate a Node's children and listen for events.

See also:
NodeListener


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.
Nodeparent () const
 Get the parent of the current Node.
Nodechild (int index) const
 Get the child at the specified index.
NodefindChild (int id)
 Find the Node in the hierarchy of this node with the specified ID.
NodefindChild (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
Signals triggered by Node events.

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...


Detailed Description

The main class of Scene2D. Nodes are used to represent objects in the scene, and can be animated, selected, and respond to events.

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.

See also:
Managed, Spatial

Member Typedef Documentation

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

See also:
std::pair

typedef iterator_by_tag<by_id>::iterator Node::iterator_by_id

Provides an iterator ordered by Node id.

See also:
Node::id()

typedef iterator_by_tag<by_name>::iterator Node::iterator_by_name

Provides an iterator ordered by Node name.

See also:
Node::name()

typedef const_iterator_by_tag<by_id>::iterator Node::const_iterator_by_id

Provides a const iterator ordered by Node id.

See also:
Node::id()

typedef const_iterator_by_tag<by_name>::iterator Node::const_iterator_by_name

Provides a const iterator ordered by Node name.

See also:
Node::name()


Constructor & Destructor Documentation

Node::Node (  ) 

Default constructor.

Constructs a Node with a unique ID but no name.

Node::Node ( const std::string &  name  ) 

Constructs a Node with a unique ID and name.

The name is not required to be unique. The name can be used to look up the Node in the scene graph by name.

See also:
findChild ( const std::string& name ), findAllChildren ( const std::string& name, std::vector<Node*>& children )

Node::Node ( const Node node  ) 

Copy constructor.

Node the copy constructed Nodes still have a unique ID.


Member Function Documentation

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.

See also:
Vector2f
Parameters:
points vector of points to append to.

Reimplemented in Shape.

virtual extents_t Node::extents (  )  const [virtual]

Returns the bounding box of the current Node in object space.

See also:
extents_t

virtual Vector2f Node::worldToObject ( const Vector2f world  )  const [virtual]

Returns object space coordinates of the given world space point.

See also:
Vector2f
Parameters:
world a point in world space
Returns:
the object space coordinates of world

Reimplemented in OrthoCamera.

virtual Vector2f Node::objectToWorld ( const Vector2f object  )  const [virtual]

Returns world space coordinates of the given object space point.

See also:
Vector2f
Parameters:
object a point in object space
Returns:
the world space coordinates of 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.

See also:
Spatial::localTranslation(), Vector2f
Returns:
the world translation 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.

See also:
Spatial::localRotation()
Returns:
the world rotation 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).

See also:
Vector2f, InsidePolygon
Parameters:
point the world space location of the point to test
Returns:
whether the point is contained inside the Node's polygon

TextureState& Node::texture (  )  [inline]

Returns the current TextureState.

Returns:
the current TextureState

MaterialState& Node::material (  )  [inline]

Returns the current MaterialState.

Returns:
the current MaterialState

virtual void Node::setTexture ( const TextureState texState  )  [virtual]

Sets the current TextureState.

Parameters:
texState TextureState to copy into this Node's TextureState

virtual void Node::setMaterial ( const MaterialState matState  )  [virtual]

Sets the current MaterialState.

Parameters:
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:

 myNode->material().colour.r = r
 myNode->material().colour.g = g
 myNode->material().colour.b = b

Parameters:
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  ) 

Sets the visibility of this Node.

Note that this only sets the visibility of the current Node and does not affect the visibility of its children.

Parameters:
visible whether this Node is visible (i.e., rendered) or not.

bool Node::visible (  )  [inline]

Gets the visibility of this Node.

Returns:
whether this Node is visible

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.

See also:
SceneNode, Camera
Parameters:
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.

See also:
draw()

int Node::numChildren (  )  const

Returns the number of children under this Node.

Returns:
number of children under this Node.

void Node::attachChild ( Node s  ) 

Attaches a child to this Node.

Parameters:
s child to attach.

void Node::attachChild ( Node s  ) 

Attaches a child to this Node.

Parameters:
s child to attach.

void Node::removeChild ( Node s  ) 

Remove a child from this Node.

Parameters:
s child to remove.

void Node::removeChild ( Node s  ) 

Remove a child from this Node.

Parameters:
s child to remove.

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

See also:
Managed

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.

See also:
NodeListener
Parameters:
listener listener to attach.
priority priority of the listener (higher priority listeners are called first).

void Node::removeListener ( NodeListener listener  ) 

Removes a listener from this Node.

See also:
NodeListener
Parameters:
listener listener to remove.

void Node::applyToAll ( boost::function< void(Node *)>  f,
bool  parentsFirst = false 
)

Applies a function to the current Node and all its children.

See also:
boost::function
Parameters:
f function to apply
parentsFirst apply function to parents first, or children first

Node* Node::parent (  )  const

Get the parent of the current Node.

Returns:
the Node's parent, or 0 if the Node has no parent.

Node* Node::child ( int  index  )  const

Get the child at the specified index.

Parameters:
index the index of the child to access (from 0 to numChildren())
Returns:
the child at index

Node* Node::findChild ( int  id  ) 

Find the Node in the hierarchy of this node with the specified ID.

Parameters:
id Node id to search for
Returns:
the Node that has id if it exists (0 otherwise)

Node* Node::findChild ( const std::string &  name  ) 

Find the first child in the hierachy of this Node with the specified name.

Parameters:
name name to search for
Returns:
the first node which matches 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.

Parameters:
name name to search for
children vector of child pointers to fill with matching Nodes

const std::string& Node::name (  )  const

Gets the name of the Node.

Returns:
the name of the Node.

void Node::setName ( const std::string &  name  ) 

Changes the name of the Node.

Parameters:
name new name to set

const int Node::id (  )  const

Gets the unique ID of the Node.

Returns:
Node's unique ID

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.

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

Enables dragging of Nodes.

This is required to properly respond to mouse dragging events, because occasionally the cursor may extend outside the boundaries of a Node. This method forces the Node to track the mouse cursor during drag events.

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.

See also:
InputSystem, boost::signal, boost::function, boost::bind
Example usage:
 //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 ) );                  

Parameters:
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.

See also:
InputSystem, boost::signal, boost::function, boost::bind
Parameters:
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.

template<typename Tag>
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();                        


Member Data Documentation

boost::signal<void (Node*) Node::Destroyed)

Triggered when a Node is Destroyed.

Triggered when a Node is destroyed but before it is removed from the scene graph completely, so responders to this signal can access the parents or children of a Node.

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.


The documentation for this class was generated from the following file:

Generated on Fri Feb 22 15:56:21 2008 for Scene2D by  doxygen 1.5.5