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( C++ | Java | .NET ) is the base class for gesture events. It contains the state of the gesture: BEGIN, DELTA or END.
SoGestureRecognizer( C++ | Java | .NET ) 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( C++ | Java | .NET ), 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:
SoRotateGestureRecognizer( C++ | Java | .NET ) releases an SoRotateGestureEvent( C++ | Java | .NET ) event when two fingers are touching the screen and one of them, at least, is moving. getRotation() gets the angle between the current fingers position and the initial one (after the second DOWN event). getPosition() gets the center of rotation which is the mi-point between fingers. getDeltaScaleFactor() gets the ratio between the current fingers distance and the previous one.
The BEGIN event is sent when the second finger is put down. As long as one finger, at least, moves on the screen, DELTA events will be generated. Finally, when one finger is lifted, the END event is released.
SoDoubleTapGestureRecognizer( C++ | Java | .NET ) releases an SoDoubleTapGestureEvent( C++ | Java | .NET ) event when only one finger taps two times the screen according to time and space restrictions which are configurable:
Maximum tap duration.
Radius of the circle in which a finger has to stay.
The SoLongTapGestureEvent( C++ | Java | .NET ) message is generated by SoLongTapGestureRecognizer( C++ | Java | .NET ) when one finger touches the screen without moving more than a given period of time. This event contains the duration of the fulfilled long tap. Events are sent under some space and time conditions which are configurable:
Maximum tap duration.
Elapsed time between taps.
Radius of the circle in which a finger has to stay.
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( C++ | Java | .NET ), 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);