#include <Leap.h>
The Controller class is your main interface to the Leap Motion Controller.
Create an instance of this Controller class to access frames of tracking data and configuration information. Frame data can be polled at any time using the Controller::frame() function. Call frame() or frame(0) to get the most recent frame. Set the history parameter to a positive integer to access previous frames. A controller stores up to 60 frames in its frame history.
Polling is an appropriate strategy for applications which already have an intrinsic update loop, such as a game. You can also add an instance of a subclass of Leap::Listener to the controller to handle events as they occur. The Leap dispatches events to the listener upon initialization and exiting, on connection changes, and when a new frame of tracking data is available. When these events occur, the controller object invokes the appropriate callback function defined in your subclass of Listener.
To access frames of tracking data as they become available:
When an instance of a Listener subclass is added to a Controller object, it calls the Listener::onInit() function when the listener is ready for use. When a connection is established between the controller and the Leap, the controller calls the Listener::onConnect() function. At this point, your application will start receiving frames of data. The controller calls the Listener::onFrame() function each time a new frame is available. If the controller loses its connection with the Leap software or device for any reason, it calls the Listener::onDisconnect() function. If the listener is removed from the controller or the controller is destroyed, it calls the Listener::onExit() function. At that point, unless the listener is added to another controller again, it will no longer receive frames of tracking data.
The Controller object is multithreaded and calls the Listener functions on its own thread, not on an application thread.
Public Member Functions | |
Controller (ControllerImplementation *) | |
LEAP_EXPORT | Controller () |
virtual LEAP_EXPORT | ~Controller () |
LEAP_EXPORT | Controller (Listener &listener) |
LEAP_EXPORT bool | isConnected () const |
LEAP_EXPORT bool | hasFocus () const |
LEAP_EXPORT bool | addListener (Listener &listener) |
LEAP_EXPORT bool | removeListener (Listener &listener) |
LEAP_EXPORT Frame | frame (int history=0) const |
LEAP_EXPORT Config | config () const |
LEAP_EXPORT ScreenList | locatedScreens () const |
LEAP_EXPORT ScreenList | calibratedScreens () const |
LEAP_EXPORT void | enableGesture (Gesture::Type type, bool enable=true) const |
LEAP_EXPORT bool | isGestureEnabled (Gesture::Type type) const |
Additional Inherited Members | |
![]() | |
class SharedObject * | m_object |
![]() | |
LEAP_EXPORT | Interface (void *owner) |
LEAP_EXPORT | Interface (Implementation *reference, void *owner) |
LEAP_EXPORT | Interface (const Interface &rhs) |
LEAP_EXPORT Interface & | operator= (const Interface &rhs) |
virtual LEAP_EXPORT | ~Interface () |
template<typename T > | |
T * | get () const |
Leap::Controller::Controller | ( | ControllerImplementation * | ) |
LEAP_EXPORT Leap::Controller::Controller | ( | ) |
Constructs a Controller object.
When creating a Controller object, you may optionally pass in a reference to an instance of a subclass of Leap::Listener. Alternatively, you may add a listener using the Controller::addListener() function.
|
virtual |
LEAP_EXPORT Leap::Controller::Controller | ( | Listener & | listener | ) |
Constructs a Controller object.
When creating a Controller object, you may optionally pass in a reference to an instance of a subclass of Leap::Listener. Alternatively, you may add a listener using the Controller::addListener() function.
listener | An instance of Leap::Listener implementing the callback functions for the Leap events you want to handle in your application. |
LEAP_EXPORT bool Leap::Controller::addListener | ( | Listener & | listener | ) |
Adds a listener to this Controller.
The Controller dispatches Leap events to each associated listener. The order in which listener callback functions are invoked is arbitrary. If you pass a listener to the Controller's constructor function, it is automatically added to the list and can be removed with the Controller::removeListener() function.
listener | A subclass of Leap::Listener implementing the callback functions for the Leap events you want to handle in your application. |
LEAP_EXPORT ScreenList Leap::Controller::calibratedScreens | ( | ) | const |
Deprecated. Use Controller::locatedScreens() instead.
LEAP_EXPORT Config Leap::Controller::config | ( | ) | const |
LEAP_EXPORT void Leap::Controller::enableGesture | ( | Gesture::Type | type, |
bool | enable = true |
||
) | const |
Enables or disables reporting of a specified gesture type.
By default, all gesture types are disabled. When disabled, gestures of the disabled type are never reported and will not appear in the frame gesture list.
As a performance optimization, only enable recognition for the types of movements that you use in your application.
type | The type of gesture to enable or disable. Must be a member of the Gesture::Type enumeration. |
enable | True, to enable the specified gesture type; False, to disable. |
LEAP_EXPORT Frame Leap::Controller::frame | ( | int | history = 0 | ) | const |
Returns a frame of tracking data from the Leap. Use the optional history parameter to specify which frame to retrieve. Call frame() or frame(0) to access the most recent frame; call frame(1) to access the previous frame, and so on. If you use a history value greater than the number of stored frames, then the controller returns an invalid frame.
history | The age of the frame to return, counting backwards from the most recent frame (0) into the past and up to the maximum age (59). |
LEAP_EXPORT bool Leap::Controller::hasFocus | ( | ) | const |
Reports whether this application is the focused, foreground application.
Only the foreground application receives tracking information from the Leap Motion Controller.
LEAP_EXPORT bool Leap::Controller::isConnected | ( | ) | const |
Reports whether this Controller is connected to the Leap device.
When you first create a Controller object, isConnected() returns false. After the controller finishes initializing and connects to the Leap, isConnected() will return true.
You can either handle the onConnect event using a Listener instance or poll the isConnected() function if you need to wait for your application to be connected to the Leap before performing some other operation.
LEAP_EXPORT bool Leap::Controller::isGestureEnabled | ( | Gesture::Type | type | ) | const |
Reports whether the specified gesture type is enabled.
LEAP_EXPORT ScreenList Leap::Controller::locatedScreens | ( | ) | const |
The list of screens whose positions have been identified by using the Leap application Screen Locator.
The list always contains at least one entry representing the default screen. If the user has not registered the location of this default screen, then the coordinates, directions, and other values reported by the functions in its Screen object will not be accurate. Other monitor screens only appear in the list if their positions have been registered using the Leap Screen Locator.
A Screen object represents the position and orientation of a display monitor screen within the Leap coordinate system. For example, if the screen location is known, you can get Leap coordinates for the bottom-left corner of the screen. Registering the screen location also allows the Leap to calculate the point on the screen at which a finger or tool is pointing.
A user can run the Screen Locator tool from the Leap application Settings window. Avoid assuming that a screen location is known or that an existing position is still correct. The registered position is only valid as long as the relative position of the Leap device and the monitor screen remain constant.
LEAP_EXPORT bool Leap::Controller::removeListener | ( | Listener & | listener | ) |
Remove a listener from the list of listeners that will receive Leap events. A listener must be removed if its lifetime is shorter than the controller to which it is listening.
listener | The listener to remove. |