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

Commit

Permalink
Initial check in of PR to resolve #247
Browse files Browse the repository at this point in the history
* Controller Type added to IMixedRealityController
* Added new TryGet method to InputSystem (and interface) to Query detected by Type and Hand
* All current controller constructors updated to include type
* All current controller instantiation updated to include type
* Updated Logic for OpenVR to check the input system for detected controllers
* Updated Logic for Oculus to check the input system for detected controllers
* WMR / Lumin unaffected, as they can only ever have one set of detected controllers
  • Loading branch information
SimonDarksideJ committed Jul 20, 2019
1 parent 7649727 commit 5ddafed
Show file tree
Hide file tree
Showing 19 changed files with 112 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,15 @@ public interface IMixedRealityInputSystem : IMixedRealityEventSystem
/// <returns>True, if an <see cref="IMixedRealityController"/> is found.</returns>
bool TryGetController(IMixedRealityInputSource inputSource, out IMixedRealityController controller);

/// <summary>
/// Tried to get a <see cref="IMixedRealityController"/> from the <see cref="DetectedControllers"/> list.
/// </summary>
/// <param name="controllerType">The <see cref="SupportedControllerType"/> of the controller you want to get a reference for.</param>
/// <param name="hand">The <see cref="Handedness"/>of the controller you want to get a reference for.</param>
/// <param name="controller">The <see cref="IMixedRealityController"/> that was found in the list of <see cref="DetectedControllers"/></param>
/// <returns>True, if an <see cref="IMixedRealityController"/> is found.</returns>
bool TryGetController(SupportedControllerType controllerType, Handedness hand, out IMixedRealityController controller);

#endregion IMixedRealityController Utilities

#region Input Events
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ public interface IMixedRealityController
/// </summary>
TrackingState TrackingState { get; }

/// <summary>
/// The known type of the controller that the Input Source is managing, as defined by the XRTK.
/// </summary>
SupportedControllerType ControllerType { get; }

/// <summary>
/// The designated hand that the Input Source is managing, as defined by the SDK / Unity.
/// </summary>
Expand Down Expand Up @@ -64,5 +69,10 @@ public interface IMixedRealityController
/// Mapping definition for this controller, linking the Physical inputs to logical Input System Actions
/// </summary>
MixedRealityInteractionMapping[] Interactions { get; }

/// <summary>
/// The Controller update method
/// </summary>
void UpdateController();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ public abstract class BaseController : IMixedRealityController
/// <param name="controllerHandedness"></param>
/// <param name="inputSource"></param>
/// <param name="interactions"></param>
protected BaseController(TrackingState trackingState, Handedness controllerHandedness, IMixedRealityInputSource inputSource = null, MixedRealityInteractionMapping[] interactions = null)
protected BaseController(TrackingState trackingState, SupportedControllerType controllerType, Handedness controllerHandedness, IMixedRealityInputSource inputSource = null, MixedRealityInteractionMapping[] interactions = null)
{
TrackingState = trackingState;
ControllerType = controllerType;
ControllerHandedness = controllerHandedness;
InputSource = inputSource;
Interactions = interactions;
Expand Down Expand Up @@ -63,6 +64,9 @@ protected BaseController(TrackingState trackingState, Handedness controllerHande
/// <inheritdoc />
public TrackingState TrackingState { get; protected set; }

/// <inheritdoc />
public SupportedControllerType ControllerType { get; }

/// <inheritdoc />
public Handedness ControllerHandedness { get; }

Expand All @@ -84,6 +88,9 @@ protected BaseController(TrackingState trackingState, Handedness controllerHande
/// <inheritdoc />
public MixedRealityInteractionMapping[] Interactions { get; private set; } = null;

/// <inheritdoc />
public virtual void UpdateController() { }

#endregion IMixedRealityController Implementation

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ namespace XRTK.Providers.Controllers.OpenVR
{
public class GenericOpenVRController : GenericJoystickController
{
public GenericOpenVRController(TrackingState trackingState, Handedness controllerHandedness, IMixedRealityInputSource inputSource = null, MixedRealityInteractionMapping[] interactions = null)
: base(trackingState, controllerHandedness, inputSource, interactions)
public GenericOpenVRController(TrackingState trackingState, SupportedControllerType controllerType, Handedness controllerHandedness, IMixedRealityInputSource inputSource = null, MixedRealityInteractionMapping[] interactions = null)
: base(trackingState, controllerType, controllerHandedness, inputSource, interactions)
{
nodeType = controllerHandedness == Handedness.Left ? XRNode.LeftHand : XRNode.RightHand;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public class OculusGoOpenVRController : GenericOpenVRController
/// <param name="controllerHandedness"></param>
/// <param name="inputSource"></param>
/// <param name="interactions"></param>
public OculusGoOpenVRController(TrackingState trackingState, Handedness controllerHandedness, IMixedRealityInputSource inputSource = null, MixedRealityInteractionMapping[] interactions = null)
: base(trackingState, controllerHandedness, inputSource, interactions)
public OculusGoOpenVRController(TrackingState trackingState, SupportedControllerType controllerType, Handedness controllerHandedness, IMixedRealityInputSource inputSource = null, MixedRealityInteractionMapping[] interactions = null)
: base(trackingState, controllerType, controllerHandedness, inputSource, interactions)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public class OculusRemoteOpenVRController : GenericOpenVRController
/// <param name="controllerHandedness"></param>
/// <param name="inputSource"></param>
/// <param name="interactions"></param>
public OculusRemoteOpenVRController(TrackingState trackingState, Handedness controllerHandedness, IMixedRealityInputSource inputSource = null, MixedRealityInteractionMapping[] interactions = null)
: base(trackingState, controllerHandedness, inputSource, interactions)
public OculusRemoteOpenVRController(TrackingState trackingState, SupportedControllerType controllerType, Handedness controllerHandedness, IMixedRealityInputSource inputSource = null, MixedRealityInteractionMapping[] interactions = null)
: base(trackingState, controllerType, controllerHandedness, inputSource, interactions)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ public class OculusTouchOpenVRController : GenericOpenVRController
/// <param name="controllerHandedness"></param>
/// <param name="inputSource"></param>
/// <param name="interactions"></param>
public OculusTouchOpenVRController(TrackingState trackingState, Handedness controllerHandedness,
IMixedRealityInputSource inputSource = null, MixedRealityInteractionMapping[] interactions = null)
: base(trackingState, controllerHandedness, inputSource, interactions)
public OculusTouchOpenVRController(TrackingState trackingState, SupportedControllerType controllerType, Handedness controllerHandedness, IMixedRealityInputSource inputSource = null, MixedRealityInteractionMapping[] interactions = null)
: base(trackingState, controllerType, controllerHandedness, inputSource, interactions)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using XRTK.Definitions.Devices;
using XRTK.Definitions.Utilities;
using XRTK.Services;
using XRTK.Interfaces.Providers.Controllers;

namespace XRTK.Providers.Controllers.OpenVR
{
Expand All @@ -29,16 +30,8 @@ public OpenVRDataProvider(string name, uint priority, BaseMixedRealityController
#region Controller Utilities

/// <inheritdoc />
protected override GenericJoystickController GetOrAddController(string joystickName)
protected override GenericJoystickController GetOrAddController(string joystickName, bool addController = true)
{
// If a device is already registered with the ID provided, just return it.
if (ActiveControllers.ContainsKey(joystickName))
{
var controller = ActiveControllers[joystickName];
Debug.Assert(controller != null);
return controller;
}

Handedness controllingHand;

if (joystickName.Contains("Left"))
Expand All @@ -54,10 +47,21 @@ protected override GenericJoystickController GetOrAddController(string joystickN
controllingHand = Handedness.None;
}

var currentControllerType = GetCurrentControllerType(joystickName);
// If a device is already registered with the ID provided, just return it.
var supportedControllerType = GetCurrentControllerType(joystickName);

IMixedRealityController controller = null;
if (MixedRealityToolkit.InputSystem.TryGetController(supportedControllerType, controllingHand, out controller))
{
Debug.Assert(controller != null);
return controller as GenericJoystickController;
}

if (!addController) { return null; }

Type controllerType;

switch (currentControllerType)
switch (supportedControllerType)
{
case SupportedControllerType.GenericOpenVR:
controllerType = typeof(GenericOpenVRController);
Expand Down Expand Up @@ -85,8 +89,8 @@ protected override GenericJoystickController GetOrAddController(string joystickN
}

var pointers = RequestPointers(controllerType, controllingHand);
var inputSource = MixedRealityToolkit.InputSystem?.RequestNewGenericInputSource($"{currentControllerType} Controller {controllingHand}", pointers);
var detectedController = Activator.CreateInstance(controllerType, TrackingState.NotTracked, controllingHand, inputSource, null) as GenericOpenVRController;
var inputSource = MixedRealityToolkit.InputSystem?.RequestNewGenericInputSource($"{supportedControllerType} Controller {controllingHand}", pointers);
var detectedController = Activator.CreateInstance(controllerType, TrackingState.NotTracked, supportedControllerType, controllingHand, inputSource, null) as GenericOpenVRController;

if (detectedController == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public class ViveKnucklesOpenVRController : GenericOpenVRController
/// <param name="controllerHandedness"></param>
/// <param name="inputSource"></param>
/// <param name="interactions"></param>
public ViveKnucklesOpenVRController(TrackingState trackingState, Handedness controllerHandedness, IMixedRealityInputSource inputSource = null, MixedRealityInteractionMapping[] interactions = null)
: base(trackingState, controllerHandedness, inputSource, interactions)
public ViveKnucklesOpenVRController(TrackingState trackingState, SupportedControllerType controllerType, Handedness controllerHandedness, IMixedRealityInputSource inputSource = null, MixedRealityInteractionMapping[] interactions = null)
: base(trackingState, controllerType, controllerHandedness, inputSource, interactions)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public class ViveWandOpenVRController : GenericOpenVRController
/// <param name="controllerHandedness"></param>
/// <param name="inputSource"></param>
/// <param name="interactions"></param>
public ViveWandOpenVRController(TrackingState trackingState, Handedness controllerHandedness, IMixedRealityInputSource inputSource = null, MixedRealityInteractionMapping[] interactions = null)
: base(trackingState, controllerHandedness, inputSource, interactions)
public ViveWandOpenVRController(TrackingState trackingState, SupportedControllerType controllerType, Handedness controllerHandedness, IMixedRealityInputSource inputSource = null, MixedRealityInteractionMapping[] interactions = null)
: base(trackingState, controllerType, controllerHandedness, inputSource, interactions)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ public class WindowsMixedRealityOpenVRMotionController : GenericOpenVRController
/// <param name="controllerHandedness"></param>
/// <param name="inputSource"></param>
/// <param name="interactions"></param>
public WindowsMixedRealityOpenVRMotionController(TrackingState trackingState, Handedness controllerHandedness, IMixedRealityInputSource inputSource = null, MixedRealityInteractionMapping[] interactions = null)
: base(trackingState, controllerHandedness, inputSource, interactions)
public WindowsMixedRealityOpenVRMotionController(TrackingState trackingState, SupportedControllerType controllerType, Handedness controllerHandedness, IMixedRealityInputSource inputSource = null, MixedRealityInteractionMapping[] interactions = null)
: base(trackingState, controllerType, controllerHandedness, inputSource, interactions)
{
PointerOffsetAngle = -30f;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ namespace XRTK.Providers.Controllers.UnityInput
{
public class GenericJoystickController : BaseController
{
public GenericJoystickController(TrackingState trackingState, Handedness controllerHandedness, IMixedRealityInputSource inputSource = null, MixedRealityInteractionMapping[] interactions = null)
: base(trackingState, controllerHandedness, inputSource, interactions)
public GenericJoystickController(TrackingState trackingState, SupportedControllerType controllerType, Handedness controllerHandedness, IMixedRealityInputSource inputSource = null, MixedRealityInteractionMapping[] interactions = null)
: base(trackingState, controllerType, controllerHandedness, inputSource, interactions)
{
}

Expand All @@ -34,10 +34,8 @@ public override void SetupDefaultInteractions(Handedness controllerHandedness)
// Generic unity controller's will not have default interactions
}

/// <summary>
/// Update the controller data from Unity's Input Manager
/// </summary>
public virtual void UpdateController()
/// <inheritdoc />
public override void UpdateController()
{
if (!Enabled) { return; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public class MouseController : BaseController
/// <param name="controllerHandedness"></param>
/// <param name="inputSource"></param>
/// <param name="interactions"></param>
public MouseController(TrackingState trackingState, Handedness controllerHandedness, IMixedRealityInputSource inputSource = null, MixedRealityInteractionMapping[] interactions = null)
: base(trackingState, controllerHandedness, inputSource, interactions)
public MouseController(TrackingState trackingState, SupportedControllerType controllerType, Handedness controllerHandedness, IMixedRealityInputSource inputSource = null, MixedRealityInteractionMapping[] interactions = null)
: base(trackingState, controllerType, controllerHandedness, inputSource, interactions)
{
}

Expand Down Expand Up @@ -54,7 +54,7 @@ public override void SetupDefaultInteractions(Handedness controllerHandedness)
/// <summary>
/// Update controller.
/// </summary>
public void Update()
public override void UpdateController()
{
if (!Input.mousePresent) { return; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public override void Enable()
mouseInputSource = MixedRealityToolkit.InputSystem.RequestNewGenericInputSource("Mouse Input", pointers);
}

Controller = new MouseController(TrackingState.NotApplicable, Handedness.Any, mouseInputSource);
Controller = new MouseController(TrackingState.NotApplicable, SupportedControllerType.Mouse, Handedness.Any, mouseInputSource);

if (mouseInputSource != null)
{
Expand All @@ -84,7 +84,7 @@ public override void Update()
{
if (Input.mousePresent && Controller == null) { Enable(); }

Controller?.Update();
Controller?.UpdateController();
}

/// <inheritdoc />
Expand Down
Loading

0 comments on commit 5ddafed

Please sign in to comment.