private IEnumerator WhileTouchingTouchpadAxis0(uint deviceIndex, Hand hand, short coroutineId) { var vr = OpenVR.System; var state = new VRControllerState_t(); var size = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(VRControllerState_t)); var dir = new Direction(); bool started = false; Vector2 anchorPos = Vector2.zero; Direction anchorDir = new Direction(); while (vr.GetControllerState(deviceIndex, ref state, size)) { var pos = ControllerAxisToVector2(state.rAxis0); if (started) { var deltaPos = pos; float magnitude = 0; dir = GetLargestVectorDirection(deltaPos, ref magnitude); Debug.Log("Hand " + hand.ToString() + " Dir " + dir + " Magnitude " + magnitude); if (magnitude >= 0.25) { anchorPos = pos; anchorDir = dir; var btn = new DirectionActionsPress(hand, DirectionAction.D1, dir, true); DirectionActionPress.Send(btn); // Wait long enough for ED to recieve any keypresses // yield return KeyboardInterface.WaitForKeySent(); } else { var btn = new DirectionActionsPress(hand, DirectionAction.D1, anchorDir, false); DirectionActionUnpress.Send(btn); } } else { started = true; anchorPos = pos; anchorDir = dir; } yield return(null); if (trackpadTouchingCoroutineId[hand] != coroutineId) { Debug.Log("Hand " + hand.ToString() + " Dir " + dir + " Stop"); var btn = new DirectionActionsPress(hand, DirectionAction.D1, dir, false); DirectionActionUnpress.Send(btn); yield break; } } Debug.LogWarningFormat("Failed to get controller state for device {0}", deviceIndex); }
private IEnumerator WhileTouchingTouchpadAxis0(uint deviceIndex, Hand hand, short coroutineId) { var vr = OpenVR.System; var state = new VRControllerState_t(); var size = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(VRControllerState_t)); bool started = false; Vector2 anchorPos = Vector2.zero; while (vr.GetControllerState(deviceIndex, ref state, size)) { var pos = ControllerAxisToVector2(state.rAxis0); if (started) { var deltaPos = pos - anchorPos; float magnitude = 0; Direction dir = GetLargestVectorDirection(deltaPos, ref magnitude); if (magnitude >= trackpadDirectionInterval) { anchorPos = pos; var btn = new DirectionActionsPress(hand, DirectionAction.D2, dir, true); DirectionActionPress.Send(btn); yield return(new WaitForSecondsRealtime(0.05f)); new DirectionActionsPress(hand, DirectionAction.D2, dir, false); DirectionActionUnpress.Send(btn); } } else { started = true; anchorPos = pos; } yield return(null); if (trackpadTouchingCoroutineId[hand] != coroutineId) { yield break; } } Debug.LogWarningFormat("Failed to get controller state for device {0}", deviceIndex); }
public static bool DirectionActionsPressComparator(DirectionActionsPress pEv, DirectionActionsPress uEv) { return(uEv.hand == pEv.hand && uEv.button == pEv.button && uEv.direction == pEv.direction); }
void OnButtonPress(VREvent_t ev) { ButtonPress btn; var hand = GetHandForDevice(ev.trackedDeviceIndex); var button = (EVRButtonId)ev.data.controller.button; if (button == triggerButton) { btn = new ButtonPress(hand, Button.Trigger, true); TriggerPress.Send(btn); } if (button == grabButton) { btn = new ButtonPress(hand, Button.Grab, true); GrabPress.Send(btn); } if (button == menuButton) { btn = new ButtonPress(hand, Button.Menu, true); MenuPress.Send(btn); } if (basicBtnActions.ContainsKey(button)) { var btnAction = basicBtnActions[button]; var press = new ButtonActionsPress(hand, btnAction, true); ButtonActionPress.Send(press); } if (button == EVRButtonId.k_EButton_SteamVR_Touchpad) { var vr = OpenVR.System; // For now this only handles the SteamVR Touchpad // In the future Joysticks and small WMR touchpads should be supported // Though it's probably easiest to switch to get the SteamVR Input API working to replace this first var err = ETrackedPropertyError.TrackedProp_Success; var axisTypeInt = vr.GetInt32TrackedDeviceProperty(ev.trackedDeviceIndex, ETrackedDeviceProperty.Prop_Axis0Type_Int32, ref err); if (err == ETrackedPropertyError.TrackedProp_Success) { var axisType = (EVRControllerAxisType)axisTypeInt; if (axisType == EVRControllerAxisType.k_eControllerAxis_TrackPad) { var state = new VRControllerState_t(); var size = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(VRControllerState_t)); if (vr.GetControllerState(ev.trackedDeviceIndex, ref state, size)) { var axis = ControllerAxisToVector2(state.rAxis0); float magnitude = 0; Direction dir = GetLargestVectorDirection(axis, ref magnitude); if (magnitude > trackpadCenterButtonRadius) { // Directional button press var dirBtn = new DirectionActionsPress(hand, DirectionAction.D1, dir, true); DirectionActionPress.Send(dirBtn); UnpressTouchpadHandler = () => { var dirBtnUnpress = new DirectionActionsPress(hand, DirectionAction.D1, dir, false); DirectionActionUnpress.Send(dirBtnUnpress); }; } else { // Center button press var press = new ButtonActionsPress(hand, BtnAction.D1, true); ButtonActionPress.Send(press); UnpressTouchpadHandler = () => { var unpress = new ButtonActionsPress(hand, BtnAction.D1, false); ButtonActionUnpress.Send(unpress); }; } } } } } }
private UnpressHandlerDelegate <DirectionActionsPress> OnDirectionPress(DirectionActionsPress pEv) { var unpress = NavigateDirection(pEv.direction, pEv.button); return((DirectionActionsPress uEv) => unpress()); }