jtth jtth - 2 years ago 98
C# Question

Hololens Navigation using tap and hold gesture bug?

Using the InputManager prefab from the HoloToolkit asset and implementation code the user can tap and hold on a given object and then move their hand left or right (along the x-plane) to rotate the object along the Y axis or up and down (along the y-plane) to rotate the object on the X axis.

However there appears to be a bug. If the users gaze comes off the object, the rotation stops immediately until the users gaze returns to the object. Is this the intended functionality? If so, how does one preserve the current object being changed via the navigation gesture and allow it to continue being manipulated until the users hand leaves the FOV or the user releases the tap and hold gesture?

Goal is to utilize the tap and hold gesture but not require the users gaze to be locked onto the object during the entirety of them rotating it. This is quite difficult with small or awkwardly shaped objects.

Implementation code:

[Tooltip("Controls speed of rotation.")]
public float RotationSensitivity = 2.0f;

private float rotationFactorX, rotationFactorY;

public void OnNavigationStarted(NavigationEventData eventData)
Debug.Log("Navigation started");
public void OnNavigationUpdated(NavigationEventData eventData)
rotationFactorX = eventData.CumulativeDelta.x * RotationSensitivity;

rotationFactorY = eventData.CumulativeDelta.y * RotationSensitivity;

//control structure to prevent dual axis movement
if (System.Math.Abs(eventData.CumulativeDelta.x) > System.Math.Abs(eventData.CumulativeDelta.y))
//rotate focusedObject along Y-axis
transform.Rotate(new Vector3(0, -1 * rotationFactorX, 0));
//rotate focusedObject along X-axis
transform.Rotate(new Vector3(-1 * rotationFactorY, 0, 0));
public void OnNavigationCompleted(NavigationEventData eventData)
Debug.Log("Navigation completed");
public void OnNavigationCanceled(NavigationEventData eventData)
Debug.Log("Navigation canceled");

Answer Source

You need to call these methods:

    NavigationRecognizer = new GestureRecognizer();
    NavigationRecognizer.TappedEvent += NavigationRecognizer_TappedEvent;

This is for a tapped event, but doing the other gesutres is simple as adding the event callback for them and using an | OR selector on the SetRecognizableGestures() call. e.g.

    NavigationRecognizer.SetRecognizableGestures(GestureSettings.Tap | GestureSettings.NavigationX);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download