gvr:: GestureApi
#include <gvr_gesture.h>
This is a convenience C++ wrapper for the Gesture C API.
Summary
This wrapper strategy prevents ABI compatibility issues between compilers by ensuring that the interface between client code and the implementation code in libgvr_gesture.so is a pure C interface. The translation from C++ calls to C calls provided by this wrapper runs entirely in the client's binary and is compiled by the client's compiler.
If you are using multiple controllers, you will need to create multiple GestureApi objects, one for each controller.
Methods in this class are only documented insofar as the C++ wrapping logic is concerned; for information about the method itself, please refer to the corresponding function in the C API.
Example API usage:
Initialization:
GestureApi gesture_api;
Usage:
// Get the controller state from client ControllerState* controller_state = ... // Detect the gestures. gesture_api.Update(controller_state); // Get the number of detected gestures int num_gestures = gesture_api.GetGestureCount(); for (int i = 0; i < num_gestures; i ++) { Gesture* gesture_ptr = gesture_api.GetGesture(i); switch (gesture_api.GetGestureType(gesture_ptr)) { case GVR_GESTURE_SWIPE: // Handle swipe gesture. break; case GVR_GESTURE_SCROLL_START: // Handle the start of a sequence of scroll gestures. break; case GVR_GESTURE_SCROLL_UPDATE: // Handle an update in a sequence of scroll gestures. break; case GVR_GESTURE_SCROLL_END: // Handle the end of a sequence of scroll gestures. break; default: // Unexpected gesture type. break; } }
Inheritance
Inherits from: gvr::WrapperBase< gvr_gesture_context, gvr_gesture_context_destroy >
Constructors and Destructors |
|
---|---|
GestureApi()
Creates a GestureApi object.
|
Public functions |
|
---|---|
GetButtonLongPress(const ControllerState *controller_state, ControllerButton button) const
|
bool
Returns whether long press on the given controller button is detected.
|
GetDisplacement(const Gesture *gesture) const
|
Returns gesture displacement.
|
GetGesture(int index) const
|
const Gesture *
Returns the gesture at given index.
|
GetGestureCount() const
|
int
Returns the number of gestures detected.
|
GetGestureDirection(const Gesture *gesture) const
|
Returns the direction of current gesture.
|
GetGestureType(const Gesture *gesture) const
|
Returns the type of the given gesture.
|
GetVelocity(const Gesture *gesture) const
|
Returns gesture velocity.
|
Restart()
|
void
Restarts gesture detection.
|
Update(const ControllerState *controller_state)
|
void
Updates gesture context based on current controller state.
|
Public functions
GestureApi
GestureApi()
Creates a GestureApi object.
It is properly initialized and can handle gesture detection immediately.
GetButtonLongPress
bool GetButtonLongPress( const ControllerState *controller_state, ControllerButton button ) const
Returns whether long press on the given controller button is detected.
For more information, see gvr_get_button_long_press().
GetDisplacement
gvr_vec2f GetDisplacement( const Gesture *gesture ) const
Returns gesture displacement.
For more information, see gvr_gesture_get_displacement().
GetGesture
const Gesture * GetGesture( int index ) const
Returns the gesture at given index.
For more information, see gvr_gesture_get().
GetGestureCount
int GetGestureCount() const
Returns the number of gestures detected.
For more information, see gvr_gesture_get_count().
GetGestureDirection
GestureDirection GetGestureDirection( const Gesture *gesture ) const
Returns the direction of current gesture.
For more information, see gvr_gesture_get_direction().
GetGestureType
GestureType GetGestureType( const Gesture *gesture ) const
Returns the type of the given gesture.
For more information, see gvr_gesture_get_type().
GetVelocity
gvr_vec2f GetVelocity( const Gesture *gesture ) const
Returns gesture velocity.
For more information, see gvr_gesture_get_velocity().
Update
void Update( const ControllerState *controller_state )
Updates gesture context based on current controller state.
For more information, see gvr_gesture_update().