HoloLens development Note gesture gesture recognition (basic introduction)

Source: Internet
Author: User

Gesture recognition is one of the important input methods of HoloLens interaction. HoloLens provides the underlying API and high-level API to meet different gesture customization needs. The underlying API gets the position and speed information of the hand, and the high-level API uses the gesture recognizer to identify preset gestures (including, click, double-tap, long-press, Pan, and so on).

Gesture Input Gesture input

This section is used by the Advanced API to identify gestures through the input source. Each gesture corresponds to a sourcekind input source, and most gesture events are system-preset events, and some events provide additional contextual information.

You can use Gesturerecognizer integrated gesture recognition in a few steps:

    1. Creating an Gesturerecognizer instance
    2. Registering the specified gesture type
    3. Subscribe to gesture Events
    4. Start gesture recognition
PrivateGesturerecognizer recognizer; //Use this for initialization    voidStart () {//Creating an Gesturerecognizer instanceRecognizer =NewGesturerecognizer (); //registering the specified gesture typeRecognizer. Setrecognizablegestures (Gesturesettings.tap |gesturesettings.hold); //Subscribe to gesture EventsRecognizer. Holdstartedevent + =recognizer_holdstartedevent; Recognizer. Tappedevent+=recognizer_tappedevent; //Start gesture Recognitionrecognizer.    Startcapturinggestures (); }    Private voidRecognizer_tappedevent (Interactionsourcekind source,intTapcount, Ray Headray) {Debug.Log ("Tap"); }    Private voidrecognizer_holdstartedevent (interactionsourcekind source, Ray Headray) {Debug.Log (" hold"); }    //Update is called once per frame    voidUpdate () {}voidondestory () {recognizer. Tappedevent-=recognizer_tappedevent; Recognizer. Holdstartedevent-=recognizer_holdstartedevent; }

Stop gesture recognition

Recognizer. Stopcapturinggestures ();

Underlying API Interaction Input

The underlying API runs to get more detailed information about the input source, such as its location and speed in the world.

How to handle underlying interaction events

It is easy to use the underlying interaction:

    1. Registering Interactionmanager Events
    2. Handling Events

It's also easy to stop it:

    1. Unregister event

Registering the underlying interaction event

For each of the underlying events you need, you need to register it

interactionmanager.sourcepressed + = interactionmanager_sourcepressed;
Handling underlying interaction events

Once the underlying interaction event is registered, you can get a callback when the event occurs. You can use the time information you get to handle app behavior.

void interactionmanager_sourcepressed (interactionsourcestate state) {    //  The state variable contains the following information:        // Current gaze ray information        // whether the source was       clicked // properties       such as position, speed // Source ID and Source type (hand, voice, controller, or other)}
How to stop an interaction event

When you no longer want to focus on some events, just cancel the time register.

interactionmanager.sourcepressed-= interactionmanager_sourcepressed;
Input source Change events

These events describe the current state of the input source:

    • Detected (will be activated)
    • Lost (deactivation is about to be deactivated)
    • Updates (moving or some states are changing)
    • is pressed (click, button pressed or voice selected)
    • is released (click End, button to release, end of voice check)

Input source Status

Each event will have a interactionsourcestate parameter, which represents the real-time input source state:

    • Whether it is a click state
    • Interactionsourceproperties contains the input source location information Interactionsourcelocation to obtain the current input source location and speed information
    • Gaze ray information to determine whether the user is looking at the target when the event occurs
    • Source type information, including hand, voice, controller, or other types
Sample code
usingUnityEngine.VR.WSA.Input;voidStart () {interactionmanager.sourcedetected+=interactionmanager_sourcedetected; Interactionmanager.sourceupdated+=interactionmanager_sourceupdated; Interactionmanager.sourcelost+=Interactionmanager_sourcelost; Interactionmanager.sourcepressed+=interactionmanager_sourcepressed; Interactionmanager.sourcereleased+=interactionmanager_sourcereleased;}voidOnDestroy () {interactionmanager.sourcedetected-=interactionmanager_sourcedetected; Interactionmanager.sourceupdated-=interactionmanager_sourceupdated; Interactionmanager.sourcelost-=Interactionmanager_sourcelost; Interactionmanager.sourcepressed-=interactionmanager_sourcepressed; Interactionmanager.sourcereleased-=interactionmanager_sourcereleased;}voidinteractionmanager_sourcedetected (interactionsourcestate state) {//Identify the source}voidInteractionmanager_sourcelost (interactionsourcestate state) {//lost Source}voidinteractionmanager_sourceupdated (interactionsourcestate state) {//Source is updated}voidinteractionmanager_sourcepressed (interactionsourcestate state) {//the source was pressed}voidinteractionmanager_sourcereleased (interactionsourcestate state) {//The source is loosened .}

HoloLens development Note gesture gesture recognition (basic introduction)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.