示例#1
0
    private void UpdateInput()
    {
        if (_playerActionMap != null)
        {
            Vector2 input = new Vector2(_playerActionMap.V.PollAxis(WingsuitAction.LookHorizontal),
                                        _playerActionMap.V.PollAxis(WingsuitAction.LookVertical));
            _input = InputUtilities.CircularizeInput(input);

            _mouseLook = _playerActionMap.V.PollButton(WingsuitAction.ActivateMouseLook) == ButtonState.Pressed;
        }
    }
示例#2
0
    void Update()
    {
//        if (Input.GetKeyDown(KeyCode.R)) {
//            Debug.Log("Recentering...");
//            Valve.VR.OpenVR.System.ResetSeatedZeroPose();
//        }
        if (_controllerList.ControllerIndices.Count > 0)
        {
            var controllerIndex = _controllerList.ControllerIndices[0];

            var controller = SteamVR_Controller.Input(controllerIndex);
            //var rotation = controller.transform.rot;

            _pitch = 0f;
            _roll  = 0f;

            // TODO This provides spatial input for pilot pitch/roll
            // We don't use it at the moment because it sucks
            // What we want is a direct mapping from absolute rotation on the vive controller
            // to absolute position of the pilot.
            //            var touchClick = controller.GetTouch(EVRButtonId.k_EButton_SteamVR_Touchpad);
            //            var touchClickDown = controller.GetTouchDown(EVRButtonId.k_EButton_SteamVR_Touchpad);
            //            if (touchClickDown) {
            //                _neutralRotation = controller.transform.rot;
            //            }
            //            if (touchClick && _neutralRotation.HasValue && controller.hasTracking) {
            //                //var localRotation = Quaternion.Inverse(_neutralRotation.Value) * controller.transform.rot;
            ////                Debug.Log("controller rotation: " + rotation.eulerAngles
            ////                    + " local rotation: " + localRotation.eulerAngles
            ////                    + " has tracking: " + controller.hasTracking
            ////                    + " touch click: " + touchClickDown);
            //
            //                Vector3 baseForward = _neutralRotation.Value * Vector3.forward;
            //                Vector3 baseRight = _neutralRotation.Value * Vector3.right;
            //                Vector3 viveForward = rotation * Vector3.forward;
            //                Vector3 viveRight = rotation * Vector3.right;
            //
            //                _pitch = -GetAxis(viveForward, baseForward, baseRight);
            //                _roll = GetAxis(viveRight, baseRight, baseForward);
            //
            //                //                pitch *= 1f - Mathf.Abs(Vector3.Dot(viveForward, baseRight));
            //            }

            var touchAxis = controller.GetAxis(EVRButtonId.k_EButton_SteamVR_Touchpad);
            touchAxis = Adapters.ApplyDeadzone(0.16f, touchAxis);
            touchAxis = InputUtilities.CircularizeInput(touchAxis);
            touchAxis = MathUtils.ScaleQuadratically(touchAxis, 2f);

            _pitch = touchAxis.y;
            _roll  = touchAxis.x;

            Debug.Log("pitch " + _pitch + ", roll " + _roll);
        }
    }
示例#3
0
            private static InputMap <WingsuitAction, float> CreateControllerAxisInput(
                InputSourceMapping <WingsuitAction> inputMapping, InputSettings inputSettings, Peripherals.ControllerPeripheral peripheral)
            {
                var controllerAxisSourceMap = peripheral.Axes;

                var inputWithJoystickAxisSource = inputMapping.ApplyMapping(controllerAxisSourceMap, Adapters.MergeAxes);

                // Circularize input of pitch and roll if both are mapped to a joystick
                if (new [] { WingsuitAction.PitchUp, WingsuitAction.PitchDown, WingsuitAction.RollLeft, WingsuitAction.RollRight }.All(inputWithJoystickAxisSource.Keys.Contains))
                {
                    var            pitchUp           = inputWithJoystickAxisSource.Source[WingsuitAction.PitchUp];
                    var            pitchDown         = inputWithJoystickAxisSource.Source[WingsuitAction.PitchDown];
                    var            rollLeft          = inputWithJoystickAxisSource.Source[WingsuitAction.RollLeft];
                    var            rollRight         = inputWithJoystickAxisSource.Source[WingsuitAction.RollRight];
                    Func <Vector2> circularizedInput = () => InputUtilities.CircularizeInput(new Vector2(rollRight() - rollLeft(), pitchUp() - pitchDown()));
                    inputWithJoystickAxisSource = inputWithJoystickAxisSource.Source
                                                  .SetItem(WingsuitAction.PitchUp, () => Adapters.FilterPositiveInput(circularizedInput().y))
                                                  .SetItem(WingsuitAction.PitchDown, () => Adapters.Abs(Adapters.FilterNegativeInput(circularizedInput().y)))
                                                  .SetItem(WingsuitAction.RollLeft, () => Adapters.Abs(Adapters.FilterNegativeInput(circularizedInput().x)))
                                                  .SetItem(WingsuitAction.RollRight, () => Adapters.FilterPositiveInput(circularizedInput().x))
                                                  .ToInputMap();
                }
                // Scale all pitch, roll and yaw input of a joystick
                inputWithJoystickAxisSource = inputWithJoystickAxisSource.Adapt <WingsuitAction, float, float>((id, pollFn) => {
                    if (PilotBodyMovementActions.Contains(id))
                    {
                        return(pollFn.Adapt <float, float>(i => MathUtils.ScaleQuadratically(i, inputSettings.InputGamma)));
                    }
                    else if (PilotArmMovementActions.Contains(id))
                    {
                        return(pollFn.Adapt <float, float>(i => MathUtils.ScaleQuadratically(i, 2)));
                    }
                    return(pollFn);
                });
                return(inputWithJoystickAxisSource);
            }