#include <Controller.h>
Public Member Functions | |
Controller (Node *node) | |
virtual void | update (float delta) |
virtual void | onActivate () |
virtual void | onDeactivate () |
virtual bool | isActive () |
Node * | node () const |
Public Attributes | |
boost::signal< void(Controller *) | Destroyed ) |
Friends | |
class | InputSystem |
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.
// 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
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.
node | Node object to control |
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.
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.
Node* Controller::node | ( | ) | const [inline] |
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*)
.