11.5. SoGestureEvent and SoGestureRecognizer

Every touch manager has a list of gesture recognizers that release events when a gesture is recognized. By default, the list is empty and recognizers must be added to release corresponding events. These classes are described in the next part.

A gesture is a series of touch events beginning with a DOWN event and ending with an UP event. Some Open Inventor objects can analyze this series and release events if gestures are identified. For every gesture there is a recognizer and the associated event. A recognized gesture is a series of gesture events starting with a BEGIN event. It is updated by DELTA event and terminated by END event.

SoGestureEvent SoGestureEvent SoGestureEvent is the base class for gesture events. It contains the state of the gesture: BEGIN, DELTA or END.

SoGestureRecognizer SoGestureRecognizer SoGestureRecognizer is the abstract base class for all recognizers and contains only one virtual function: SoEvent* recognize(SoEvent*). Each recognizer has its own event to release derived from SoGestureEvent SoGestureEvent SoGestureEvent , so you can add your own recognizer with its own associated event.

This gesture recognition is totally independent to multi-touch so, for example, gesture recognizers can be implemented to recognized gestures from other devices.

Open Inventor suggests three gestures:

Double tap, long tap, zoom and rotate gestures

Figure 11.2.  Double tap, long tap, zoom and rotate gestures



For every tap gesture, you can edit, with setLimitationCircle(int), the radius of the circle in which the finger has to stay to consider the gesture. For example, a double tap is not generated if you tap too far away from the position of the first tap.

Only one tap gesture can be recognized at a time.

To use the SoGestureRecognizer SoGestureRecognizer SoGestureRecognizer , first, you have to register the device in the render area. Then, you have to add the recognizers you want in the recognizers list.

Example 11.2.  Add a recognizer

SoWinTouchScreen touchScreenDevice(appWindow);
myRenderArea->registerDevice(&touchScreenDevice);
SoScaleGestureRecognizer scaleRecognizer;
touchScreenDevice.getTouchManager().addRecognizer(&scaleRecognizer);


Like other events, you write a callback to use the released event.

Example 11.3.  Gesture callback

SoEventCallback *myEventCB = new SoEventCallback;
myEventCB->addEventCallback(SoScaleGestureEvent::getClassTypeId(), myScaleCB, myRenderArea->getSceneManager()->getSceneGraph());
root->addChild(myEventCB);