Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

Commit

Permalink
Oculus Controller mapping update (#308)
Browse files Browse the repository at this point in the history
Resolving mapping issue originally identified in MRTK where near touch data was not identified and the "Pressed" call was called incorrectly.

Now in the OpenVR / Generic Joystick spec, digital buttons whether as a button or axis are ratified in the Button code, single axis only axis data is handled separately.
  • Loading branch information
SimonDarksideJ authored and StephenHodgson committed Sep 5, 2019
1 parent 9358dbe commit 7f063e1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public OculusTouchOpenVRController(TrackingState trackingState, Handedness contr
new MixedRealityInteractionMapping(1, "Axis1D.PrimaryIndexTrigger", AxisType.SingleAxis, DeviceInputType.Trigger, ControllerMappingLibrary.AXIS_9),
new MixedRealityInteractionMapping(2, "Axis1D.PrimaryIndexTrigger Touch", AxisType.Digital, DeviceInputType.TriggerTouch, KeyCode.JoystickButton14),
new MixedRealityInteractionMapping(3, "Axis1D.PrimaryIndexTrigger Near Touch", AxisType.Digital, DeviceInputType.TriggerNearTouch, ControllerMappingLibrary.AXIS_13),
new MixedRealityInteractionMapping(4, "Axis1D.PrimaryIndexTrigger Press", AxisType.Digital, DeviceInputType.TriggerPress, KeyCode.JoystickButton14),
new MixedRealityInteractionMapping(4, "Axis1D.PrimaryIndexTrigger Press", AxisType.Digital, DeviceInputType.TriggerPress, ControllerMappingLibrary.AXIS_9),
new MixedRealityInteractionMapping(5, "Axis1D.PrimaryHandTrigger", AxisType.SingleAxis, DeviceInputType.Trigger, ControllerMappingLibrary.AXIS_11),
new MixedRealityInteractionMapping(5, "Axis1D.PrimaryHandTrigger Press", AxisType.Digital, DeviceInputType.TriggerPress, KeyCode.JoystickButton4),
new MixedRealityInteractionMapping(6, "Axis2D.PrimaryThumbstick", AxisType.DualAxis, DeviceInputType.ThumbStick, ControllerMappingLibrary.AXIS_1, ControllerMappingLibrary.AXIS_2),
Expand All @@ -54,7 +54,7 @@ public OculusTouchOpenVRController(TrackingState trackingState, Handedness contr
new MixedRealityInteractionMapping(1, "Axis1D.SecondaryIndexTrigger", AxisType.SingleAxis, DeviceInputType.Trigger, ControllerMappingLibrary.AXIS_10),
new MixedRealityInteractionMapping(2, "Axis1D.SecondaryIndexTrigger Touch", AxisType.Digital, DeviceInputType.TriggerTouch, KeyCode.JoystickButton15),
new MixedRealityInteractionMapping(3, "Axis1D.SecondaryIndexTrigger Near Touch", AxisType.Digital, DeviceInputType.TriggerNearTouch, ControllerMappingLibrary.AXIS_14),
new MixedRealityInteractionMapping(4, "Axis1D.SecondaryIndexTrigger Press", AxisType.Digital, DeviceInputType.TriggerPress, KeyCode.JoystickButton15),
new MixedRealityInteractionMapping(4, "Axis1D.SecondaryIndexTrigger Press", AxisType.Digital, DeviceInputType.TriggerPress, ControllerMappingLibrary.AXIS_10),
new MixedRealityInteractionMapping(5, "Axis1D.SecondaryHandTrigger", AxisType.SingleAxis, DeviceInputType.Trigger, ControllerMappingLibrary.AXIS_12),
new MixedRealityInteractionMapping(5, "Axis1D.SecondaryHandTrigger Press", AxisType.Digital, DeviceInputType.TriggerPress, KeyCode.JoystickButton5),
new MixedRealityInteractionMapping(6, "Axis2D.SecondaryThumbstick", AxisType.DualAxis, DeviceInputType.ThumbStick, ControllerMappingLibrary.AXIS_4, ControllerMappingLibrary.AXIS_5),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,24 @@ protected void UpdateButtonData(MixedRealityInteractionMapping interactionMappin
{
Debug.Assert(interactionMapping.AxisType == AxisType.Digital);

var keyButton = Input.GetKey(interactionMapping.KeyCode);

// Update the interaction data source
interactionMapping.BoolData = keyButton;
switch (interactionMapping.InputType)
{
case DeviceInputType.TriggerPress:
interactionMapping.BoolData = Input.GetAxis(interactionMapping.AxisCodeX).Equals(1);
break;
case DeviceInputType.TriggerNearTouch:
case DeviceInputType.ThumbNearTouch:
case DeviceInputType.IndexFingerNearTouch:
case DeviceInputType.MiddleFingerNearTouch:
case DeviceInputType.RingFingerNearTouch:
case DeviceInputType.PinkyFingerNearTouch:
interactionMapping.BoolData = !Input.GetAxis(interactionMapping.AxisCodeX).Equals(0);
break;
default:
interactionMapping.BoolData = Input.GetKey(interactionMapping.KeyCode);
break;
}

// If our value changed raise it.
if (interactionMapping.Changed)
Expand Down Expand Up @@ -123,54 +137,15 @@ protected void UpdateSingleAxisData(MixedRealityInteractionMapping interactionMa
Debug.Assert(interactionMapping.AxisType == AxisType.SingleAxis);

var singleAxisValue = Input.GetAxis(interactionMapping.AxisCodeX);
float defaultValue = 0f;

switch (interactionMapping.InputType)
{
case DeviceInputType.TriggerPress:
case DeviceInputType.ButtonPress:
// Update the interaction data source
defaultValue = 1f;
interactionMapping.BoolData = singleAxisValue.Equals(defaultValue);
break;
case DeviceInputType.TriggerTouch:
case DeviceInputType.TriggerNearTouch:
case DeviceInputType.ThumbNearTouch:
case DeviceInputType.IndexFingerNearTouch:
case DeviceInputType.MiddleFingerNearTouch:
case DeviceInputType.RingFingerNearTouch:
case DeviceInputType.PinkyFingerNearTouch:
// Update the interaction data source
interactionMapping.BoolData = !singleAxisValue.Equals(defaultValue);
break;
case DeviceInputType.Trigger:
// Update the interaction data source
interactionMapping.FloatData = singleAxisValue;

// If our value was updated, raise it.
if (interactionMapping.Updated)
{
// Raise input system Event if it enabled
MixedRealityToolkit.InputSystem?.RaiseOnInputPressed(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction, interactionMapping.FloatData);
}
return;
default:
Debug.LogWarning($"Unhandled Interaction {interactionMapping.Description}");
return;
}
// Update the interaction data source
interactionMapping.FloatData = singleAxisValue;

// If our value was updated, raise it.
if (interactionMapping.Changed)
if (interactionMapping.Updated)
{
// Raise input system Event if it enabled
if (interactionMapping.BoolData)
{
MixedRealityToolkit.InputSystem?.RaiseOnInputDown(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction);
}
else
{
MixedRealityToolkit.InputSystem?.RaiseOnInputUp(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction);
}
MixedRealityToolkit.InputSystem?.RaiseOnInputPressed(InputSource, ControllerHandedness, interactionMapping.MixedRealityInputAction, interactionMapping.FloatData);
}

// If our value was updated, raise it.
Expand Down

0 comments on commit 7f063e1

Please sign in to comment.