Skip to content

Commit

Permalink
Implement Grip Pose Input action for Oculus Touch controllers (#713)
Browse files Browse the repository at this point in the history
* Add grip pose to default open vr mappings

* Implement raising grip pose in OTouch OpenVR

* Add grip pose offset

* Move grip pose offset to BaseController

Co-authored-by: Stephen Hodgson <hodgson.designs@gmail.com>
  • Loading branch information
FejZa and StephenHodgson committed Dec 16, 2020
1 parent b446455 commit 0f0b4a0
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 8 deletions.
20 changes: 20 additions & 0 deletions Editor/Data/EditorWindowOptions.json
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,10 @@
{
"x": -24.0,
"y": 220.0
},
{
"x": -20.0,
"y": 321.0
}
],
"IsLabelFlipped": [
Expand All @@ -584,6 +588,7 @@
false,
true,
true,
true,
true
]
},
Expand Down Expand Up @@ -662,6 +667,10 @@
{
"x": 440.0,
"y": 220.0
},
{
"x": 440.0,
"y": 323.0
}
],
"IsLabelFlipped": [
Expand All @@ -682,6 +691,7 @@
true,
false,
false,
false,
false
]
},
Expand Down Expand Up @@ -756,6 +766,10 @@
{
"x": 440.0,
"y": 220.0
},
{
"x": 440.0,
"y": 322.0
}
],
"IsLabelFlipped": [
Expand All @@ -775,6 +789,7 @@
false,
true,
false,
false,
false
]
},
Expand Down Expand Up @@ -853,6 +868,10 @@
{
"x": -68.0,
"y": 220.0
},
{
"x": -20.0,
"y": 322.0
}
],
"IsLabelFlipped": [
Expand All @@ -873,6 +892,7 @@
false,
true,
true,
true,
true
]
},
Expand Down
6 changes: 6 additions & 0 deletions Runtime/Providers/Controllers/BaseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ protected BaseController(IMixedRealityControllerDataProvider controllerDataProvi
/// </summary>
public virtual MixedRealityInteractionMapping[] DefaultRightHandedInteractions { get; } = new MixedRealityInteractionMapping[0];

/// <summary>
/// Local offset from the controller position defining where the grip pose is.
/// The grip pose may be used to attach things to the controller when grabbing objects.
/// </summary>
protected virtual MixedRealityPose GripPoseOffset => MixedRealityPose.ZeroIdentity;

#region IMixedRealityController Implementation

/// <inheritdoc />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,12 +201,12 @@ protected void UpdateControllerData(XRNodeState state)
IsRotationAvailable = state.TryGetRotation(out CurrentControllerRotation);

// Devices are considered tracked if we receive position OR rotation data from the sensors.
TrackingState = (IsPositionAvailable || IsRotationAvailable) ? Definitions.Devices.TrackingState.Tracked : Definitions.Devices.TrackingState.NotTracked;
TrackingState = (IsPositionAvailable || IsRotationAvailable) ? TrackingState.Tracked : TrackingState.NotTracked;
}
else
{
// The input source does not support tracking.
TrackingState = Definitions.Devices.TrackingState.NotApplicable;
TrackingState = TrackingState.NotApplicable;
}

CurrentControllerPose.Position = CurrentControllerPosition;
Expand All @@ -218,7 +218,7 @@ protected void UpdateControllerData(XRNodeState state)
MixedRealityToolkit.InputSystem?.RaiseSourceTrackingStateChanged(InputSource, this, TrackingState);
}

if (TrackingState == Definitions.Devices.TrackingState.Tracked && LastControllerPose != CurrentControllerPose)
if (TrackingState == TrackingState.Tracked && LastControllerPose != CurrentControllerPose)
{
if (IsPositionAvailable && IsRotationAvailable)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using UnityEngine;
using XRTK.Extensions;
using XRTK.Definitions.Controllers;
using XRTK.Definitions.Devices;
using XRTK.Definitions.Utilities;
Expand All @@ -17,9 +18,7 @@ public class OculusTouchOpenVRController : GenericOpenVRController

/// <inheritdoc />
public OculusTouchOpenVRController(IMixedRealityControllerDataProvider controllerDataProvider, TrackingState trackingState, Handedness controllerHandedness, MixedRealityControllerMappingProfile controllerMappingProfile)
: base(controllerDataProvider, trackingState, controllerHandedness, controllerMappingProfile)
{
}
: base(controllerDataProvider, trackingState, controllerHandedness, controllerMappingProfile) { }

/// <inheritdoc />
public override MixedRealityInteractionMapping[] DefaultLeftHandedInteractions => new[]
Expand All @@ -41,7 +40,8 @@ public OculusTouchOpenVRController(IMixedRealityControllerDataProvider controlle
new MixedRealityInteractionMapping("Button.Three Touch", AxisType.Digital, DeviceInputType.ButtonPress, KeyCode.JoystickButton12),
new MixedRealityInteractionMapping("Button.Four Touch", AxisType.Digital, DeviceInputType.ButtonPress, KeyCode.JoystickButton13),
new MixedRealityInteractionMapping("Touch.PrimaryThumbRest Touch", AxisType.Digital, DeviceInputType.ThumbTouch, KeyCode.JoystickButton18),
new MixedRealityInteractionMapping("Touch.PrimaryThumbRest Near Touch", AxisType.Digital, DeviceInputType.ThumbNearTouch, ControllerMappingLibrary.AXIS_17)
new MixedRealityInteractionMapping("Touch.PrimaryThumbRest Near Touch", AxisType.Digital, DeviceInputType.ThumbNearTouch, ControllerMappingLibrary.AXIS_17),
new MixedRealityInteractionMapping("Grip Pose", AxisType.SixDof, DeviceInputType.SpatialGrip)
};

/// <inheritdoc />
Expand All @@ -63,7 +63,36 @@ public OculusTouchOpenVRController(IMixedRealityControllerDataProvider controlle
new MixedRealityInteractionMapping("Button.One Touch", AxisType.Digital, DeviceInputType.ButtonPress, KeyCode.JoystickButton10),
new MixedRealityInteractionMapping("Button.Two Touch", AxisType.Digital, DeviceInputType.ButtonPress, KeyCode.JoystickButton11),
new MixedRealityInteractionMapping("Touch.SecondaryThumbRest Touch", AxisType.Digital, DeviceInputType.ThumbTouch, KeyCode.JoystickButton19),
new MixedRealityInteractionMapping("Touch.SecondaryThumbRest Near Touch", AxisType.Digital, DeviceInputType.ThumbNearTouch, ControllerMappingLibrary.AXIS_18)
new MixedRealityInteractionMapping("Touch.SecondaryThumbRest Near Touch", AxisType.Digital, DeviceInputType.ThumbNearTouch, ControllerMappingLibrary.AXIS_18),
new MixedRealityInteractionMapping("Grip Pose", AxisType.SixDof, DeviceInputType.SpatialGrip)
};

public override void UpdateController()
{
base.UpdateController();

if (TrackingState == TrackingState.Tracked)
{
for (int i = 0; i < Interactions?.Length; i++)
{
var interactionMapping = Interactions[i];
switch (interactionMapping.InputType)
{
case DeviceInputType.SpatialGrip:
UpdateSpatialGripData(interactionMapping);
interactionMapping.RaiseInputAction(InputSource, ControllerHandedness);
break;
}
}
}
}

private void UpdateSpatialGripData(MixedRealityInteractionMapping interactionMapping)
{
Debug.Assert(interactionMapping.AxisType == AxisType.SixDof);
interactionMapping.PoseData = new MixedRealityPose(
CurrentControllerPose.Position + GripPoseOffset.Position,
Quaternion.Euler(CurrentControllerPose.Rotation.eulerAngles + GripPoseOffset.Rotation.eulerAngles));
}
}
}

0 comments on commit 0f0b4a0

Please sign in to comment.