Controller Class Reference
[Controllers]

Controllers provide a base class for controlling Node objects in the scene graph. More...

#include <Controller.h>

Inheritance diagram for Controller:

Inheritance graph
[legend]
Collaboration diagram for Controller:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 Controller (Node *node)
virtual void update (float delta)
virtual void onActivate ()
virtual void onDeactivate ()
virtual bool isActive ()
Nodenode () const

Public Attributes

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

Friends

class InputSystem


Detailed Description

Controllers provide a base class for controlling Node objects in the scene graph.

Controllers respond to user input when they are added to an InputSystem (and if they are active), using the InputListener interface.

Users can subclass the Controller class to create, for example, a Controller which controls a Node using the keyboard directional keys. An example of such a controller is given below.

Controllers are Managed objects, if automatic scene graph management is enabled then Controller objects will be deleted automatically when the Node assigned to the Controller is deleted. When Controllers are deleted they are automatically removed from the InputSystem they are assigned to.

See also:
Node, InputSystem, InputListener, ActivationSystem, WASDController
Example Controller:
 // Controller example, moves object 
 // up when the up arrow is pressed.
   
 class UpController : public Controller
 {
     UpController ( Node* node )
       : Controller(node)
     {
         //Controllers are required to have a constructor
         //which accepts a Node parameter
     }

     void keyUp ( int key, int x, int y )
     {
         node()->localTranslation().y += 5.0f;
     }
 };

Example usage:

 //Assume this is our InputSystem linked to some windowing system
 InputSystem input; 

 Node *myNode = new Node ( "Some Node" );

 UpController *up_controller = new UpController ( myNode );

 input.addController ( up_controller );

 //We can then call myNode->render() 
 //or attach myNode to our scene graph somewhere

Constructor & Destructor Documentation

Controller::Controller ( Node node  )  [inline]

Constructs a new Controller controlling the specified Node.

Note: subclasses of Controller must provide a constructor which either accepts a Node, or constructs the base class Controller with some Node.

Parameters:
node Node object to control


Member Function Documentation

virtual void Controller::update ( float  delta  )  [inline, virtual]

Received every 'tick' of the game or application.

Most of the time the update method will be where the manipulation of the Node occurs.

Parameters:
delta Time since last time-step

virtual void Controller::onActivate (  )  [inline, virtual]

Received when the Controller is activated by the input system. Unless a Controller is quite complicated and requires some special behaviour on deactivation or activation, most of the time the default implementation is sufficient.

virtual void Controller::onDeactivate (  )  [inline, virtual]

Received when the Controller is deactivated by the input system. Unless a Controller is quite complicated and requires some special behaviour on deactivation or activation, most of the time the default implementation is sufficient.

virtual bool Controller::isActive (  )  [inline, virtual]

Returns whether the Controller is currently active. If overriding the onActivate and onDeactivate methods, this method will also need to be overridden.

This method, for example, could be used to deactivate a Controller when a Node moves off the screen.

Returns:
whether the Controller is currently active

Node* Controller::node (  )  const [inline]

Gets the Node controlled by this Controller.

Returns:
the Node controlled by this Controller.


Member Data Documentation

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

Signal called when this controller is destroyed. Users can connect to this signal to receive notification of when the Controller is destroyed.

The slot type for this signal is void(Controller*).


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

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