/// <summary> /// Converts an <see cref="OculusApi.Controller"/> mask to a XRTK <see cref="Handedness"/>. /// </summary> /// <param name="controller">Controller mask.</param> /// <returns>Handedness.</returns> public static Handedness ToHandedness(this OculusApi.Controller controller) { switch (controller) { case OculusApi.Controller.LTouch: return(Handedness.Left); case OculusApi.Controller.RTouch: return(Handedness.Right); case OculusApi.Controller.Gamepad: case OculusApi.Controller.Remote: return(Handedness.Both); case OculusApi.Controller.LHand: return(Handedness.Left); case OculusApi.Controller.RHand: return(Handedness.Right); case OculusApi.Controller.Hands: return(Handedness.Both); } Debug.LogWarning($"{controller} does not have a defined controller handedness, falling back to {Handedness.None}"); return(Handedness.None); }
private SupportedControllerType GetCurrentControllerType(OculusApi.Controller controllerMask) { switch (controllerMask) { case OculusApi.Controller.LTouch: case OculusApi.Controller.RTouch: case OculusApi.Controller.Touch: return(SupportedControllerType.OculusTouch); case OculusApi.Controller.Remote: return(SupportedControllerType.OculusRemote); //TODO: Skip OculusGo //case OculusApi.Controller.LTrackedRemote: //case OculusApi.Controller.RTrackedRemote: // Debug.LogError($"{controllerMask} found - assuming Go?"); // return SupportedControllerType.OculusGo; default: break; } Debug.LogWarning($"{controllerMask} does not have a defined controller type, falling back to generic controller type"); return(SupportedControllerType.GenericOpenVR); }
private bool IsTrackedController(OculusApi.Controller controller) { return(controller == OculusApi.Controller.LTouch || controller == OculusApi.Controller.LTrackedRemote || controller == OculusApi.Controller.RTouch || controller == OculusApi.Controller.RTrackedRemote || controller == OculusApi.Controller.Touch); }
private void RaiseSourceDetected(OculusApi.Controller controllerType) { var controller = GetOrAddController(controllerType); if (controller != null) { MixedRealityToolkit.InputSystem?.RaiseSourceDetected(controller.InputSource, controller); } }
private void RaiseSourceLost(OculusApi.Controller activeController) { var controller = GetOrAddController(activeController, false); if (controller != null) { MixedRealityToolkit.InputSystem?.RaiseSourceLost(controller.InputSource, controller); } ActiveControllers.Remove(activeController); }
/// <summary> /// Constructor. /// </summary> /// <param name="trackingState"></param> /// <param name="controllerHandedness"></param> /// <param name="controllerType"></param> /// <param name="nodeType"></param> /// <param name="inputSource"></param> /// <param name="interactions"></param> public BaseOculusController( TrackingState trackingState, Handedness controllerHandedness, OculusApi.Controller controllerType, OculusApi.Node nodeType, IMixedRealityInputSource inputSource = null, MixedRealityInteractionMapping[] interactions = null) : base(trackingState, controllerHandedness, inputSource, interactions) { ControllerType = controllerType; NodeType = nodeType; }
private void RaiseSourceLost(OculusApi.Controller activeController, bool clearFromRegistry = true) { var controller = GetOrAddController(activeController, false); if (controller != null) { MixedRealityToolkit.InputSystem?.RaiseSourceLost(controller.InputSource, controller); RemoveController(controller); } if (clearFromRegistry) { activeControllers.Remove(activeController); } }
private static Type GetCurrentControllerType(OculusApi.Controller controllerMask) { switch (controllerMask) { case OculusApi.Controller.LTouch: case OculusApi.Controller.RTouch: case OculusApi.Controller.Touch: return(typeof(OculusTouchController)); case OculusApi.Controller.Remote: return(typeof(OculusRemoteController)); default: return(null); } }
private BaseOculusController GetOrAddController(OculusApi.Controller controllerMask, bool addController = true) { //If a device is already registered with the ID provided, just return it. if (activeControllers.ContainsKey(controllerMask)) { var controller = activeControllers[controllerMask]; Debug.Assert(controller != null); return(controller); } if (!addController) { return(null); } var controllerType = GetCurrentControllerType(controllerMask); var handedness = controllerMask.ToHandedness(); var nodeType = handedness.ToNode(); BaseOculusController detectedController; try { detectedController = Activator.CreateInstance(controllerType, this, TrackingState.NotTracked, handedness, GetControllerMappingProfile(controllerType, handedness), controllerMask, nodeType) as BaseOculusController; } catch (Exception e) { Debug.LogError($"Failed to create {controllerType.Name} controller!\n{e}"); return(null); } if (detectedController == null) { Debug.LogError($"Failed to create {controllerType.Name} controller!"); return(null); } detectedController.TryRenderControllerModel(); activeControllers.Add(controllerMask, detectedController); AddController(detectedController); return(detectedController); }
private SupportedControllerType GetCurrentControllerType(OculusApi.Controller controllerMask) { switch (controllerMask) { case OculusApi.Controller.LTouch: case OculusApi.Controller.RTouch: case OculusApi.Controller.Touch: return(SupportedControllerType.OculusTouch); case OculusApi.Controller.Remote: return(SupportedControllerType.OculusRemote); case OculusApi.Controller.LTrackedRemote: case OculusApi.Controller.RTrackedRemote: return(SupportedControllerType.OculusGo); } Debug.LogWarning($"{controllerMask} does not have a defined controller type, falling back to generic controller type"); return(SupportedControllerType.GenericOpenVR); }
private BaseOculusController GetOrAddController(OculusApi.Controller controllerMask, bool addController = true) { //If a device is already registered with the ID provided, just return it. if (activeControllers.ContainsKey(controllerMask)) { var controller = activeControllers[controllerMask]; Debug.Assert(controller != null); return(controller); } if (!addController) { return(null); } var currentControllerType = GetCurrentControllerType(controllerMask); Type controllerType = null; switch (currentControllerType) { case SupportedControllerType.OculusTouch: controllerType = typeof(OculusTouchController); break; case SupportedControllerType.OculusGo: controllerType = typeof(OculusGoController); break; case SupportedControllerType.OculusRemote: controllerType = typeof(OculusRemoteController); break; } var controllingHand = Handedness.Any; //Determine Handedness of the current controller switch (controllerMask) { case OculusApi.Controller.LTrackedRemote: case OculusApi.Controller.LTouch: controllingHand = Handedness.Left; break; case OculusApi.Controller.RTrackedRemote: case OculusApi.Controller.RTouch: controllingHand = Handedness.Right; break; case OculusApi.Controller.Touchpad: case OculusApi.Controller.Gamepad: case OculusApi.Controller.Remote: controllingHand = Handedness.Both; break; } var nodeType = OculusApi.Node.None; switch (controllingHand) { case Handedness.Left: nodeType = OculusApi.Node.HandLeft; break; case Handedness.Right: nodeType = OculusApi.Node.HandRight; break; } var pointers = RequestPointers(typeof(BaseOculusController), controllingHand); var inputSource = MixedRealityToolkit.InputSystem?.RequestNewGenericInputSource($"Oculus Controller {controllingHand}", pointers); var detectedController = new BaseOculusController(TrackingState.NotTracked, controllingHand, controllerMask, nodeType, inputSource); if (!detectedController.SetupConfiguration(controllerType)) { // Controller failed to be setup correctly. // Return null so we don't raise the source detected. return(null); } for (int i = 0; i < detectedController.InputSource?.Pointers?.Length; i++) { detectedController.InputSource.Pointers[i].Controller = detectedController; } detectedController.TryRenderControllerModel(controllerType); activeControllers.Add(controllerMask, detectedController); AddController(detectedController); return(detectedController); }
/// <remarks> /// Noticed that the "active" controllers also mark the Tracked state. /// </remarks> private void RefreshDevices() { // override locally derived active and connected controllers if plugin provides more accurate data OculusApi.connectedControllerTypes = OculusApi.GetConnectedControllers(); OculusApi.activeControllerType = OculusApi.GetActiveController(); if (OculusApi.connectedControllerTypes == OculusApi.Controller.None) { return; } if (activeControllers.Count > 0) { var controllers = new OculusApi.Controller[activeControllers.Count]; activeControllers.Keys.CopyTo(controllers, 0); if (lastDeviceList != OculusApi.Controller.None && OculusApi.connectedControllerTypes != lastDeviceList) { for (var i = 0; i < controllers.Length; i++) { var activeController = controllers[i]; switch (activeController) { case OculusApi.Controller.Touch when((OculusApi.Controller.LTouch & OculusApi.connectedControllerTypes) != OculusApi.Controller.LTouch): RaiseSourceLost(OculusApi.Controller.LTouch); break; case OculusApi.Controller.Touch when((OculusApi.Controller.RTouch & OculusApi.connectedControllerTypes) != OculusApi.Controller.RTouch): RaiseSourceLost(OculusApi.Controller.RTouch); break; default: if ((activeController & OculusApi.connectedControllerTypes) != activeController) { RaiseSourceLost(activeController); } break; } } } } for (var i = 0; i < OculusApi.Controllers.Length; i++) { if (OculusApi.ShouldResolveController(OculusApi.Controllers[i].controllerType, OculusApi.connectedControllerTypes)) { if (OculusApi.Controllers[i].controllerType == OculusApi.Controller.Touch) { if (!activeControllers.ContainsKey(OculusApi.Controller.LTouch)) { RaiseSourceDetected(OculusApi.Controller.LTouch); } if (!activeControllers.ContainsKey(OculusApi.Controller.RTouch)) { RaiseSourceDetected(OculusApi.Controller.RTouch); } } else if (!activeControllers.ContainsKey(OculusApi.Controllers[i].controllerType)) { RaiseSourceDetected(OculusApi.Controllers[i].controllerType); } } } lastDeviceList = OculusApi.connectedControllerTypes; }
/// <inheritdoc /> public OculusTouchController(IMixedRealityControllerDataProvider controllerDataProvider, TrackingState trackingState, Handedness controllerHandedness, MixedRealityControllerMappingProfile controllerMappingProfile, OculusApi.Controller controllerType = OculusApi.Controller.None, OculusApi.Node nodeType = OculusApi.Node.None) : base(controllerDataProvider, trackingState, controllerHandedness, controllerMappingProfile, controllerType, nodeType) { }
private static bool IsTrackedController(OculusApi.Controller controller) { return(controller == OculusApi.Controller.Touch || controller == OculusApi.Controller.LTouch || controller == OculusApi.Controller.RTouch); }
/// <inheritdoc /> protected BaseOculusController(IMixedRealityControllerDataProvider controllerDataProvider, TrackingState trackingState, Handedness controllerHandedness, MixedRealityControllerMappingProfile controllerMappingProfile, OculusApi.Controller controllerType = OculusApi.Controller.None, OculusApi.Node nodeType = OculusApi.Node.None) : base(controllerDataProvider, trackingState, controllerHandedness, controllerMappingProfile) { ControllerType = controllerType; NodeType = nodeType; }
private void RefreshDevices() { // override locally derived active and connected controllers if plugin provides more accurate data OculusApi.connectedControllerTypes = (OculusApi.Controller)OculusApi.GetConnectedControllers(); OculusApi.activeControllerType = (OculusApi.Controller)OculusApi.GetActiveController(); //Noticed that the "active" controllers also mark the Tracked state. //Debug.LogError($"Connected =[{OculusApi.connectedControllerTypes}] - Active = [{OculusApi.activeControllerType}]"); if (OculusApi.connectedControllerTypes == OculusApi.Controller.None) { return; } if (ActiveControllers.Count > 0) { OculusApi.Controller[] activeControllers = new OculusApi.Controller[ActiveControllers.Count]; ActiveControllers.Keys.CopyTo(activeControllers, 0); if (lastDeviceList != OculusApi.Controller.None && OculusApi.connectedControllerTypes != lastDeviceList) { foreach (var activeController in activeControllers) { if (activeController == OculusApi.Controller.Touch && ((OculusApi.Controller.LTouch & OculusApi.connectedControllerTypes) != OculusApi.Controller.LTouch)) { RaiseSourceLost(OculusApi.Controller.LTouch); } else if (activeController == OculusApi.Controller.Touch && ((OculusApi.Controller.RTouch & OculusApi.connectedControllerTypes) != OculusApi.Controller.RTouch)) { RaiseSourceLost(OculusApi.Controller.RTouch); } else if ((activeController & OculusApi.connectedControllerTypes) != activeController) { RaiseSourceLost(activeController); } } } } for (var i = 0; i < OculusApi.Controllers.Length; i++) { if (OculusApi.ShouldResolveController(OculusApi.Controllers[i].controllerType, OculusApi.connectedControllerTypes)) { if (OculusApi.Controllers[i].controllerType == OculusApi.Controller.Touch) { if (!ActiveControllers.ContainsKey(OculusApi.Controller.LTouch)) { RaiseSourceDetected(OculusApi.Controller.LTouch); } if (!ActiveControllers.ContainsKey(OculusApi.Controller.RTouch)) { RaiseSourceDetected(OculusApi.Controller.RTouch); } } else if (!ActiveControllers.ContainsKey(OculusApi.Controllers[i].controllerType)) { RaiseSourceDetected(OculusApi.Controllers[i].controllerType); } } } lastDeviceList = OculusApi.connectedControllerTypes; }