コード例 #1
0
        /// <summary>
        /// Reads the input from the controller.
        /// </summary>
        /// <param name="joystick">The state of the joystick to read input from.</param>
        internal static void ReadInput(JoystickState joystick)
        {
            double brakeAxis = joystick.GetAxis(0);
            double powerAxis = joystick.GetAxis(1);

            foreach (var notch in BrakeNotchMap)
            {
                if (brakeAxis >= GetRangeMin((byte)notch.Key) && brakeAxis <= GetRangeMax((byte)notch.Key))
                {
                    InputTranslator.BrakeNotch = notch.Value;
                }
            }
            foreach (var notch in PowerNotchMap)
            {
                if (powerAxis >= GetRangeMin((byte)notch.Key) && powerAxis <= GetRangeMax((byte)notch.Key))
                {
                    InputTranslator.PowerNotch = notch.Value;
                }
            }

            InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.Select] = joystick.GetButton(ButtonIndex.Select);
            InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.Start]  = joystick.GetButton(ButtonIndex.Start);
            InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.A]      = joystick.GetButton(ButtonIndex.A);
            InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.B]      = joystick.GetButton(ButtonIndex.B);
            InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.C]      = joystick.GetButton(ButtonIndex.C);
            InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.D]      = joystick.GetButton(ButtonIndex.D);

            if (hasDirectionButtons)
            {
                InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.Up]    = (ButtonState)(joystick.GetHat(JoystickHat.Hat0).IsUp ? 1 : 0);
                InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.Down]  = (ButtonState)(joystick.GetHat(JoystickHat.Hat0).IsDown ? 1 : 0);
                InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.Left]  = (ButtonState)(joystick.GetHat(JoystickHat.Hat0).IsLeft ? 1 : 0);
                InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.Right] = (ButtonState)(joystick.GetHat(JoystickHat.Hat0).IsRight ? 1 : 0);
            }
        }
コード例 #2
0
 public GamepadCollectData(JoystickState state)
 {
     {
         XL = state.GetAxis(JoystickAxis.Axis0);
         XR = state.GetAxis(JoystickAxis.Axis3);
         LT = state.GetAxis(JoystickAxis.Axis2);
         RT = state.GetAxis(JoystickAxis.Axis5);
         B  = state.GetButton(JoystickButton.Button1);
         A  = state.GetButton(JoystickButton.Button0);
     }
 }
コード例 #3
0
        public void UpdateState(JoystickState state)
        {
            this.IsConnected = state.IsConnected;

            for (var i = 0; i < this.axes_.Length; ++i)
            {
                var axis = this.axes_[i];
                axis.Value = state.GetAxis(i);
            }

            for (var i = 0; i < this.buttons_.Length; ++i)
            {
                var button = this.buttons_[i];

                var buttonState = state.GetButton(i);
                if (buttonState == OpenTK.Input.ButtonState.Pressed)
                {
                    button.Down();
                }
                else
                {
                    button.Up();
                }
            }
        }
コード例 #4
0
ファイル: NpadController.cs プロジェクト: zpoo32/Ryujinx
        private (short, short) GetStick(ControllerInputId stickInputId)
        {
            if (stickInputId < ControllerInputId.Axis0 || stickInputId > ControllerInputId.Axis5)
            {
                return(0, 0);
            }

            JoystickState jsState = Joystick.GetState(Index);

            int xAxis = stickInputId - ControllerInputId.Axis0;

            float xValue = jsState.GetAxis(xAxis);
            float yValue = 0 - jsState.GetAxis(xAxis + 1); // Invert Y-axis

            return(ApplyDeadzone(new Vector2(xValue, yValue)));
        }
コード例 #5
0
ファイル: LegacyJoystickDriver.cs プロジェクト: noggs/opentk
        public void Poll()
        {
            for (int i = 0; i < 4; i++)
            {
                JoystickCapabilities caps = Joystick.GetCapabilities(i);
                if (caps.IsConnected && joysticks[i].Description == DisconnectedName)
                {
                    // New joystick connected
                    joysticks[i] = new LegacyJoystickDevice(i, caps.AxisCount, caps.ButtonCount);
                    //device.Description = Joystick.GetName(i);
                    joysticks[i].Description = ConnectedName;
                }
                else if (!caps.IsConnected && joysticks[i].Description != DisconnectedName)
                {
                    // Joystick disconnected
                    joysticks[i]             = new LegacyJoystickDevice(i, 0, 0);
                    joysticks[i].Description = DisconnectedName;
                }

                JoystickState state = Joystick.GetState(i);
                for (int axis_index = 0; axis_index < (int)caps.AxisCount; axis_index++)
                {
                    JoystickAxis axis = JoystickAxis.Axis0 + axis_index;
                    joysticks[i].SetAxis(axis, state.GetAxis(axis));
                }
                for (int button_index = 0; button_index < (int)caps.ButtonCount; button_index++)
                {
                    JoystickButton button = JoystickButton.Button0 + button_index;
                    joysticks[i].SetButton(button, state.GetButton(button) == ButtonState.Pressed);
                }
            }
        }
コード例 #6
0
ファイル: OTK_Gamepad.cs プロジェクト: sornerol/BizHawk
 public IEnumerable <Tuple <string, float> > GetFloats()
 {
     for (int pi = 0; pi < 64; pi++)
     {
         yield return(new Tuple <string, float>(pi.ToString(), 10.0f * state.GetAxis(pi)));
     }
 }
コード例 #7
0
        private (short, short) GetStick(ControllerInputId stickXInputId, ControllerInputId stickYInputId, float deadzone)
        {
            if (stickXInputId < ControllerInputId.Axis0 || stickXInputId > ControllerInputId.Axis5 ||
                stickYInputId < ControllerInputId.Axis0 || stickYInputId > ControllerInputId.Axis5)
            {
                return(0, 0);
            }

            JoystickState jsState = Joystick.GetState(_config.Index);

            int xAxis = stickXInputId - ControllerInputId.Axis0;
            int yAxis = stickYInputId - ControllerInputId.Axis0;

            float xValue = jsState.GetAxis(xAxis);
            float yValue = -jsState.GetAxis(yAxis); // Invert Y-axis

            return(ApplyDeadzone(new Vector2(xValue, yValue), deadzone));
        }
コード例 #8
0
ファイル: Controller.cs プロジェクト: senapp/senappGameEngine
        public Vector2 GetAxis(int xAxisIndex, int yAxisIndex)
        {
            var x = joystick.GetAxis(xAxisIndex);
            var y = joystick.GetAxis(yAxisIndex);

            float nX = 0;
            float nY = 0;

            if (x > ControllerManager.JOYSTICK_MIN || x < -ControllerManager.JOYSTICK_MIN)
            {
                nX = x;
            }
            if (y > ControllerManager.JOYSTICK_MIN || y < -ControllerManager.JOYSTICK_MIN)
            {
                nY = y;
            }

            return(new Vector2(nX, nY));
        }
コード例 #9
0
ファイル: Controller.Zuiki.cs プロジェクト: zbx1425/OpenBVE
        /// <summary>
        /// Reads the input from the controller.
        /// </summary>
        internal override void ReadInput()
        {
            JoystickState joystick   = Joystick.GetState(joystickIndex);
            double        handleAxis = Math.Round(joystick.GetAxis(1), 4);

            for (int i = 0; i < brakeBytes.Length; i += 2)
            {
                // Each notch uses two bytes, minimum value and maximum value
                if (handleAxis >= GetAxisValue(brakeBytes[i]) && handleAxis <= GetAxisValue(brakeBytes[i + 1]))
                {
                    if (brakeBytes.Length == i + 2)
                    {
                        // Last notch should be Emergency
                        InputTranslator.BrakeNotch = InputTranslator.BrakeNotches.Emergency;
                    }
                    else
                    {
                        // Regular brake notch
                        InputTranslator.BrakeNotch = (InputTranslator.BrakeNotches)(i / 2);
                    }
                    break;
                }
                InputTranslator.BrakeNotch = InputTranslator.BrakeNotches.Released;
            }
            for (int i = 0; i < powerBytes.Length; i += 2)
            {
                // Each notch uses two bytes, minimum value and maximum value
                if (handleAxis >= GetAxisValue(powerBytes[i]) && handleAxis <= GetAxisValue(powerBytes[i + 1]))
                {
                    InputTranslator.PowerNotch = (InputTranslator.PowerNotches)(i / 2);
                    break;
                }
                InputTranslator.PowerNotch = InputTranslator.PowerNotches.N;
            }

            InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.Select] = joystick.GetButton(buttonIndex[(int)InputTranslator.ControllerButton.Select]);
            InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.Start]  = joystick.GetButton(buttonIndex[(int)InputTranslator.ControllerButton.Start]);
            InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.A]      = joystick.GetButton(buttonIndex[(int)InputTranslator.ControllerButton.A]);
            InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.B]      = joystick.GetButton(buttonIndex[(int)InputTranslator.ControllerButton.B]);
            InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.C]      = joystick.GetButton(buttonIndex[(int)InputTranslator.ControllerButton.C]);
            InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.D]      = joystick.GetButton(buttonIndex[(int)InputTranslator.ControllerButton.D]);
            InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.LDoor]  = joystick.GetButton(buttonIndex[(int)InputTranslator.ControllerButton.LDoor]);
            InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.RDoor]  = joystick.GetButton(buttonIndex[(int)InputTranslator.ControllerButton.RDoor]);

            InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.Up]    = (ButtonState)(joystick.GetHat(JoystickHat.Hat0).IsUp ? 1 : 0);
            InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.Down]  = (ButtonState)(joystick.GetHat(JoystickHat.Hat0).IsDown ? 1 : 0);
            InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.Left]  = (ButtonState)(joystick.GetHat(JoystickHat.Hat0).IsLeft ? 1 : 0);
            InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.Right] = (ButtonState)(joystick.GetHat(JoystickHat.Hat0).IsRight ? 1 : 0);
        }
コード例 #10
0
        public bool GetAxis(int joystick, ref JoystickAxis axis, params JoystickAxis[] excludeAxis)
        {
            for (int i = 0; i < numJoysticks; ++i)
            {
                if (IsConnected(i))
                {
                    JoystickState state = Joystick.GetState(i);
                    foreach (JoystickAxis enumVal in Enum.GetValues(typeof(JoystickAxis)))
                    {
                        bool greaterThan0 = Math.Abs(state.GetAxis(enumVal)) > GetDeadzone(joystick);
                        bool lessThan1    = 1.0 - Math.Abs(state.GetAxis(enumVal)) > GetDeadzone(joystick);

                        if (greaterThan0 && lessThan1)
                        {
                            bool cont = false;
                            foreach (JoystickAxis exclude in excludeAxis)
                            {
                                if (exclude == enumVal)
                                {
                                    cont = true;
                                    break;
                                }
                            }
                            if (cont)
                            {
                                continue;
                            }

                            axis = enumVal;
                            return(true);
                        }
                    }
                }
            }
            return(false);
        }
コード例 #11
0
ファイル: NpadController.cs プロジェクト: zpoo32/Ryujinx
        private bool IsActivated(JoystickState joystickState, ControllerInputId controllerInputId)
        {
            if (controllerInputId <= ControllerInputId.Button20)
            {
                return(joystickState.IsButtonDown((int)controllerInputId));
            }
            else if (controllerInputId <= ControllerInputId.Axis5)
            {
                int axis = controllerInputId - ControllerInputId.Axis0;

                return(joystickState.GetAxis(axis) > TriggerThreshold);
            }
            else if (controllerInputId <= ControllerInputId.Hat2Right)
            {
                int hat = (controllerInputId - ControllerInputId.Hat0Up) / 4;

                int baseHatId = (int)ControllerInputId.Hat0Up + (hat * 4);

                JoystickHatState hatState = joystickState.GetHat((JoystickHat)hat);

                if (hatState.IsUp && ((int)controllerInputId % baseHatId == 0))
                {
                    return(true);
                }
                if (hatState.IsDown && ((int)controllerInputId % baseHatId == 1))
                {
                    return(true);
                }
                if (hatState.IsLeft && ((int)controllerInputId % baseHatId == 2))
                {
                    return(true);
                }
                if (hatState.IsRight && ((int)controllerInputId % baseHatId == 3))
                {
                    return(true);
                }
            }

            return(false);
        }
コード例 #12
0
ファイル: Controller.Classic.cs プロジェクト: zbx1425/OpenBVE
        /// <summary>
        /// Reads the input from the controller.
        /// </summary>
        internal override void ReadInput()
        {
            JoystickState    joystick   = Joystick.GetState(joystickIndex);
            PowerNotchesEnum powerNotch = PowerNotchesEnum.None;
            BrakeNotchesEnum brakeNotch = BrakeNotchesEnum.None;

            powerNotch = joystick.IsButtonDown(ButtonIndex.Power1) ? powerNotch | PowerNotchesEnum.Power1 : powerNotch & ~PowerNotchesEnum.Power1;
            brakeNotch = joystick.IsButtonDown(ButtonIndex.Brake1) ? brakeNotch | BrakeNotchesEnum.Brake1 : brakeNotch & ~BrakeNotchesEnum.Brake1;
            brakeNotch = joystick.IsButtonDown(ButtonIndex.Brake2) ? brakeNotch | BrakeNotchesEnum.Brake2 : brakeNotch & ~BrakeNotchesEnum.Brake2;
            brakeNotch = joystick.IsButtonDown(ButtonIndex.Brake3) ? brakeNotch | BrakeNotchesEnum.Brake3 : brakeNotch & ~BrakeNotchesEnum.Brake3;
            brakeNotch = joystick.IsButtonDown(ButtonIndex.Brake4) ? brakeNotch | BrakeNotchesEnum.Brake4 : brakeNotch & ~BrakeNotchesEnum.Brake4;

            if (UsesAxis)
            {
                // The adapter uses an axis to map the direction buttons.
                // This is the case of some PlayStation adapters.
                powerNotch = joystick.GetAxis(AxisIndex) < -0.5 ? powerNotch | PowerNotchesEnum.Power2 : powerNotch & ~PowerNotchesEnum.Power2;
                powerNotch = joystick.GetAxis(AxisIndex) > 0.5 ? powerNotch | PowerNotchesEnum.Power3 : powerNotch & ~PowerNotchesEnum.Power3;
            }
            else if (UsesHat)
            {
                // The adapter uses the hat to map the direction buttons.
                // This is the case of some PlayStation adapters.
                powerNotch = joystick.GetHat((JoystickHat)HatIndex).IsLeft ? powerNotch | PowerNotchesEnum.Power2 : powerNotch & ~PowerNotchesEnum.Power2;
                powerNotch = joystick.GetHat((JoystickHat)HatIndex).IsRight ? powerNotch | PowerNotchesEnum.Power3 : powerNotch & ~PowerNotchesEnum.Power3;
            }
            else
            {
                // The adapter maps the direction buttons to independent buttons.
                powerNotch = joystick.IsButtonDown(ButtonIndex.Power2) ? powerNotch | PowerNotchesEnum.Power2 : powerNotch & ~PowerNotchesEnum.Power2;
                powerNotch = joystick.IsButtonDown(ButtonIndex.Power3) ? powerNotch | PowerNotchesEnum.Power3 : powerNotch & ~PowerNotchesEnum.Power3;
            }

            if ((UsesHat || UsesAxis) && powerNotch == PowerNotchesEnum.P4)
            {
                // Hack for adapters using a hat/axis where pressing left and right simultaneously reports only left being pressed
                if (InputTranslator.PreviousPowerNotch < InputTranslator.PowerNotches.P3)
                {
                    InputTranslator.PowerNotch = InputTranslator.PowerNotches.N;
                }
                else
                {
                    InputTranslator.PowerNotch = InputTranslator.PowerNotches.P4;
                }
            }
            else if ((UsesHat || UsesAxis) && powerNotch == PowerNotchesEnum.Transition)
            {
                // Hack for adapters using a hat/axis where pressing left and right simultaneously reports nothing being pressed, the same as the transition state
                // Has the side effect of the power notch jumping P1>N>P2, but it is barely noticeable unless moving the handle very slowly
                if (InputTranslator.PreviousPowerNotch < InputTranslator.PowerNotches.P2)
                {
                    InputTranslator.PowerNotch = InputTranslator.PowerNotches.N;
                }
            }
            else if (powerNotch != PowerNotchesEnum.Transition)
            {
                // Set notch only if it is not a transition
                InputTranslator.PowerNotch = PowerNotchMap[powerNotch];
            }
            if (brakeNotch != BrakeNotchesEnum.Transition && (brakeNotch == BrakeNotchesEnum.Emergency || brakeNotch >= BrakeNotchesEnum.B8))
            {
                // Set notch only if it is not a transition nor an unmarked notch
                InputTranslator.BrakeNotch = BrakeNotchMap[brakeNotch];
            }
            InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.Select] = joystick.GetButton(ButtonIndex.Select);
            InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.Start]  = joystick.GetButton(ButtonIndex.Start);
            InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.A]      = joystick.GetButton(ButtonIndex.A);
            InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.B]      = joystick.GetButton(ButtonIndex.B);
            InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.C]      = joystick.GetButton(ButtonIndex.C);
        }
コード例 #13
0
        public void Poll()
        {
            for (int i = 0; i < 4; i++)
            {
                JoystickCapabilities caps = Joystick.GetCapabilities(i);
                if (caps.IsConnected && joysticks[i].Description == DisconnectedName)
                {
                    // New joystick connected
                    joysticks[i] = new LegacyJoystickDevice(
                        i,
                        caps.AxisCount + 2 * caps.HatCount,
                        caps.ButtonCount);
                    //device.Description = Joystick.GetName(i);
                    joysticks[i].Description = ConnectedName;
                }
                else if (!caps.IsConnected && joysticks[i].Description != DisconnectedName)
                {
                    // Joystick disconnected
                    joysticks[i]             = new LegacyJoystickDevice(i, 0, 0);
                    joysticks[i].Description = DisconnectedName;
                }

                JoystickState state = Joystick.GetState(i);
                for (int axis_index = 0; axis_index < caps.AxisCount; axis_index++)
                {
                    JoystickAxis axis = JoystickAxis.Axis0 + axis_index;
                    joysticks[i].SetAxis(axis, state.GetAxis(axis));
                }
                for (int button_index = 0; button_index < caps.ButtonCount; button_index++)
                {
                    JoystickButton button = JoystickButton.Button0 + button_index;
                    joysticks[i].SetButton(button, state.GetButton(button) == ButtonState.Pressed);
                }
                for (int hat_index = 0; hat_index < caps.HatCount; hat_index++)
                {
                    // LegacyJoystickDriver report hats as pairs of axes
                    // Make sure we have enough axes left for this mapping
                    int axis_index = caps.AxisCount + 2 * hat_index;
                    if (axis_index < JoystickState.MaxAxes)
                    {
                        JoystickHat      hat       = JoystickHat.Hat0 + hat_index;
                        JoystickHatState hat_state = state.GetHat(hat);
                        JoystickAxis     axis      = JoystickAxis.Axis0 + axis_index;
                        float            x         = 0;
                        float            y         = 0;
                        if (hat_state.IsDown)
                        {
                            y--;
                        }
                        if (hat_state.IsUp)
                        {
                            y++;
                        }
                        if (hat_state.IsLeft)
                        {
                            x--;
                        }
                        if (hat_state.IsRight)
                        {
                            x++;
                        }

                        joysticks[i].SetAxis(axis, x);
                        joysticks[i].SetAxis(axis + 1, y);
                    }
                }
            }
        }
コード例 #14
0
 internal override double GetAxis(int axis)
 {
     return(state.GetAxis(axis));
 }
コード例 #15
0
 double GetPitch(JoystickState state) => state.GetAxis(3) * Math.PI;
コード例 #16
0
 double GetYaw(JoystickState state) => state.GetAxis(4) * Math.PI;
コード例 #17
0
 double GetTBAcc(JoystickState state) => state.GetAxis(7);
コード例 #18
0
        public IEnumerable <Tuple <string, float> > GetFloats()
        {
            if (MappedGamePad)
            {
                // automapping identified - use OpenTKGamePad
                yield return(new Tuple <string, float>("LeftThumbX", ConstrainFloatInput(state.ThumbSticks.Left.X)));

                yield return(new Tuple <string, float>("LeftThumbY", ConstrainFloatInput(state.ThumbSticks.Left.Y)));

                yield return(new Tuple <string, float>("RightThumbX", ConstrainFloatInput(state.ThumbSticks.Right.X)));

                yield return(new Tuple <string, float>("RightThumbY", ConstrainFloatInput(state.ThumbSticks.Right.Y)));

                yield return(new Tuple <string, float>("LeftTrigger", ConstrainFloatInput(state.Triggers.Left)));

                yield return(new Tuple <string, float>("RightTrigger", ConstrainFloatInput(state.Triggers.Right)));

                yield break;
            }
            else
            {
                // use Joystick
                yield return(new Tuple <string, float>("X", ConstrainFloatInput(jState.GetAxis(0))));

                yield return(new Tuple <string, float>("Y", ConstrainFloatInput(jState.GetAxis(1))));

                yield return(new Tuple <string, float>("Z", ConstrainFloatInput(jState.GetAxis(2))));

                yield return(new Tuple <string, float>("W", ConstrainFloatInput(jState.GetAxis(3))));

                yield return(new Tuple <string, float>("V", ConstrainFloatInput(jState.GetAxis(4))));

                yield return(new Tuple <string, float>("S", ConstrainFloatInput(jState.GetAxis(5))));

                yield return(new Tuple <string, float>("Q", ConstrainFloatInput(jState.GetAxis(6))));

                yield return(new Tuple <string, float>("P", ConstrainFloatInput(jState.GetAxis(7))));

                yield return(new Tuple <string, float>("N", ConstrainFloatInput(jState.GetAxis(8))));

                for (var i = 9; i < 64; i++)
                {
                    var j = i;
                    yield return(new Tuple <string, float>($"Axis{j.ToString()}", ConstrainFloatInput(jState.GetAxis(j))));
                }

                yield break;
            }
        }
コード例 #19
0
        static unsafe void Main(string[] args)
        {
            bool list     = false;
            bool dump     = false; //show state and controller name
            int  index    = 0;     //current device
            bool checkold = true;  //compare last state
            bool axis     = false; //due to bad calibration axis can report data all the time


            for (int i = 0; i < args.Length; ++i)
            {
                string arg = args[i];

                if (arg == "-l" || arg == "--list")
                {
                    list = true;
                }
                else if (arg == "--no-check-state")
                {
                    checkold = false;
                }
                else if (arg == "-a" || arg == "--axis")
                {
                    axis = true;
                }
                else if (arg == "-i" || arg == "--index")
                {
                    if (i + 1 >= args.Length)
                    {
                        Logger.Error?.Print(LogClass.Application, $"Invalid option '{arg}'");

                        continue;
                    }

                    string i = args[++i];
                    index = Int32.Parse(i);
                }
                else if (arg == "-d" || arg == "--debug")
                {
                    dump = true;
                }
                else
                {
                    index = Int32.Parse(arg);
                }
            }

            NativeWindowSettings nativeSettings = NativeWindowSettings.Default;

            nativeSettings.Size            = new Vector2i(1280, 720);
            nativeSettings.Title           = "Game";
            nativeSettings.WindowState     = WindowState.Normal;
            nativeSettings.WindowBorder    = WindowBorder.Resizable;
            nativeSettings.NumberOfSamples = 4;

            GameWindow gameWindow = new GameWindow(GameWindowSettings.Default, nativeSettings);

            if (list)
            {
                for (int i = 0; i < gameWindow.JoystickStates.Count; i++)
                {
                    JoystickState state = gameWindow.JoystickStates[i];
                    if (dump)
                    {
                        Console.WriteLine($"testing {index} {state}");
                    }

                    if (state != null)
                    {
                        var name = GLFW.GetJoystickName(i);

                        Console.WriteLine($"Controller/{i} ({name})");
                    }
                }
                gameWindow.ProcessEvents();
                return;
            }

            while (true)
            {
                JoystickState state = gameWindow.JoystickStates[index];
                if (dump)
                {
                    Console.WriteLine($"Controller/{index} ({state})");
                }

                if (state != null)
                {
                    GLFW.GetJoystickHatsRaw(index, out var hatCount);
                    GLFW.GetJoystickAxesRaw(index, out var axisCount);
                    GLFW.GetJoystickButtonsRaw(index, out var buttonCount);
                    var name = GLFW.GetJoystickName(index);

                    Console.WriteLine($"Controller/{index} ({name})");
                    if (list)
                    {
                        continue;
                    }
                    Console.WriteLine($"{hatCount} {axisCount} {buttonCount}");
                    for (int j = 0; j < hatCount; j++)
                    {
                        Console.WriteLine($"hat{j}: {state.GetHat(j)}");
                    }

                    for (int j = 0; j < axisCount; j++)
                    {
                        Console.WriteLine($"axis{j}: {state.GetAxis(j)}");
                    }

                    for (int j = 0; j < buttonCount; j++)
                    {
                        if (state.IsButtonDown(j))
                        {
                            Console.WriteLine($"button {j}: down");
                        }
                    }
                }
                //Thread.Sleep(2000);
                gameWindow.ProcessEvents();
                if (list)
                {
                    break;
                }
            }
        }
コード例 #20
0
        private void updateDevice(ref JoystickCapabilities caps, ref JoystickState state, ref JoystickState defaultState)
        {
            for (int i = 0; i < JoyKey.Count; i++)
            {
                buttons[i] = false;
            }
            List <Keys> Current = new List <Keys>(JoyKey.Count);

            for (int i = 0; i < caps.ButtonCount; i++)
            {
                if (state.IsButtonDown((JoystickButton)((int)JoystickButton.Button0 + i)))
                {
                    buttons[i] = true;
                    Current.Add((Keys)((int)JoyKey.Button0 + i));
                }
            }

            for (int i = 0; i < caps.AxisCount; i++)
            {
                JoystickAxis axis             = (JoystickAxis)(i + (int)JoystickAxis.Axis0);
                float        axisState        = state.GetAxis(axis);
                float        defaultAxisState = defaultState.GetAxis(axis);

                // find the dead zone base value by rounding the default state to the nearest deadZoneRound
                float deadZoneBase = (float)Math.Round(defaultAxisState / deadZoneRound) * deadZoneRound;

                // the min/max input thresholds are a fractional value between the deadZoneBase value and the min/max value
                float inputThresholdMin = deadZoneBase + (-1 - deadZoneBase) * inputThresholdFraction;
                float inputThresholdMax = deadZoneBase + (1 - deadZoneBase) * inputThresholdFraction;

                if (Math.Abs(axisState - deadZoneBase) < deadZone)
                {
                }
                else if (axisState < inputThresholdMin)
                {
                    int key = (int)JoyKey.AxisXMin + i * 2;
                    buttons[key - (int)JoyKey.Button0] = true;
                    Current.Add((Keys)key);
                }
                else if (axisState > inputThresholdMax)
                {
                    int key = (int)JoyKey.AxisXMin + i * 2 + 1;
                    buttons[key - (int)JoyKey.Button0] = true;
                    Current.Add((Keys)key);
                }
            }

            // WORKAROUND: HatCount is incorrectly reported as 0 for XInput controllers, so always try at least 1 hat
            for (int i = 0; i < Math.Max(1, caps.HatCount); i++)
            {
                JoystickHatState hatState = state.GetHat((JoystickHat)(i + (int)JoystickHat.Hat0));
                if (hatState.IsUp)
                {
                    int key = (int)JoyKey.Hat0U + i * 4;
                    buttons[key - (int)JoyKey.Button0] = true;
                    Current.Add((Keys)key);
                }
                if (hatState.IsRight)
                {
                    int key = (int)JoyKey.Hat0U + i * 4 + 1;
                    buttons[key - (int)JoyKey.Button0] = true;
                    Current.Add((Keys)key);
                }
                if (hatState.IsDown)
                {
                    int key = (int)JoyKey.Hat0U + i * 4 + 2;
                    buttons[key - (int)JoyKey.Button0] = true;
                    Current.Add((Keys)key);
                }
                if (hatState.IsLeft)
                {
                    int key = (int)JoyKey.Hat0U + i * 4 + 3;
                    buttons[key - (int)JoyKey.Button0] = true;
                    Current.Add((Keys)key);
                }
            }

            if (OnButtonDown != null)
            {
                if (Current.Count > 0)
                {
                    OnButtonDown(null, Current);
                }
            }
            if (OnButtonPressed != null)
            {
                List <Keys> down = new List <Keys>(JoyKey.Count);
                for (int i = 0; i < JoyKey.Count; i++)
                {
                    // release
                    if (lastButtons[i] && !buttons[i])
                    {
                        down.Add((Keys)((int)JoyKey.Button0 + i));
                    }
                }
                if (down.Count > 0)
                {
                    OnButtonPressed(null, down);
                }
            }
            LastKeyDown.Clear();
            LastKeyDown.AddRange(KeyDown);
            KeyDown.Clear();
            KeyDown.AddRange(Current);
            buttons.CopyTo(lastButtons, 0);
        }
コード例 #21
0
        public void tポーリング(bool bWindowがアクティブ中, bool bバッファ入力有効)
        {
            #region [ bButtonフラグ初期化 ]
            for (int i = 0; i < 256; i++)
            {
                this.bButtonPushDown[i] = false;
                this.bButtonPullUp[i]   = false;
            }
            #endregion

            if (bWindowがアクティブ中)
            {
                this.list入力イベント.Clear();                                        // #xxxxx 2012.6.11 yyagi; To optimize, I removed new();


                #region [ 入力 ]
                //-----------------------------
                JoystickState ButtonState = Joystick.GetState(ID);
                if (ButtonState.IsConnected)
                {
                    #region [ X軸- ]
                    //-----------------------------
                    if (ButtonState.GetAxis(0) < -0.5)
                    {
                        if (this.bButtonState[0] == false)
                        {
                            STInputEvent ev = new STInputEvent()
                            {
                                nKey       = 0,
                                b押された      = true,
                                nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻ms,                                 // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。
                            };
                            this.list入力イベント.Add(ev);

                            this.bButtonState[0]    = true;
                            this.bButtonPushDown[0] = true;
                        }
                    }
                    else
                    {
                        if (this.bButtonState[0] == true)
                        {
                            STInputEvent ev = new STInputEvent()
                            {
                                nKey       = 0,
                                b押された      = false,
                                nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻ms,                                 // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。
                            };
                            this.list入力イベント.Add(ev);

                            this.bButtonState[0]  = false;
                            this.bButtonPullUp[0] = true;
                        }
                    }
                    //-----------------------------
                    #endregion
                    #region [ X軸+ ]
                    //-----------------------------
                    if (ButtonState.GetAxis(0) > 0.5)
                    {
                        if (this.bButtonState[1] == false)
                        {
                            STInputEvent ev = new STInputEvent()
                            {
                                nKey       = 1,
                                b押された      = true,
                                nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻ms,                                 // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。
                            };
                            this.list入力イベント.Add(ev);

                            this.bButtonState[1]    = true;
                            this.bButtonPushDown[1] = true;
                        }
                    }
                    else
                    {
                        if (this.bButtonState[1] == true)
                        {
                            STInputEvent event7 = new STInputEvent()
                            {
                                nKey       = 1,
                                b押された      = false,
                                nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻ms,                                 // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。
                            };
                            this.list入力イベント.Add(event7);

                            this.bButtonState[1]  = false;
                            this.bButtonPullUp[1] = true;
                        }
                    }
                    //-----------------------------
                    #endregion
                    #region [ Y軸- ]
                    //-----------------------------
                    if (ButtonState.GetAxis(1) < -0.5)
                    {
                        if (this.bButtonState[2] == false)
                        {
                            STInputEvent ev = new STInputEvent()
                            {
                                nKey       = 2,
                                b押された      = true,
                                nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻ms,                                 // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。
                            };
                            this.list入力イベント.Add(ev);

                            this.bButtonState[2]    = true;
                            this.bButtonPushDown[2] = true;
                        }
                    }
                    else
                    {
                        if (this.bButtonState[2] == true)
                        {
                            STInputEvent ev = new STInputEvent()
                            {
                                nKey       = 2,
                                b押された      = false,
                                nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻ms,                                 // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。
                            };
                            this.list入力イベント.Add(ev);

                            this.bButtonState[2]  = false;
                            this.bButtonPullUp[2] = true;
                        }
                    }
                    //-----------------------------
                    #endregion
                    #region [ Y軸+ ]
                    //-----------------------------
                    if (ButtonState.GetAxis(1) > 0.5)
                    {
                        if (this.bButtonState[3] == false)
                        {
                            STInputEvent ev = new STInputEvent()
                            {
                                nKey       = 3,
                                b押された      = true,
                                nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻ms,                                 // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。
                            };
                            this.list入力イベント.Add(ev);

                            this.bButtonState[3]    = true;
                            this.bButtonPushDown[3] = true;
                        }
                    }
                    else
                    {
                        if (this.bButtonState[3] == true)
                        {
                            STInputEvent ev = new STInputEvent()
                            {
                                nKey       = 3,
                                b押された      = false,
                                nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻ms,                                 // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。
                            };
                            this.list入力イベント.Add(ev);

                            this.bButtonState[3]  = false;
                            this.bButtonPullUp[3] = true;
                        }
                    }
                    //-----------------------------
                    #endregion
                    #region [ Z軸- ]
                    //-----------------------------
                    if (ButtonState.GetAxis(2) < -0.5)
                    {
                        if (this.bButtonState[4] == false)
                        {
                            STInputEvent ev = new STInputEvent()
                            {
                                nKey       = 4,
                                b押された      = true,
                                nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻ms,                                 // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。
                            };
                            this.list入力イベント.Add(ev);

                            this.bButtonState[4]    = true;
                            this.bButtonPushDown[4] = true;
                        }
                    }
                    else
                    {
                        if (this.bButtonState[4] == true)
                        {
                            STInputEvent ev = new STInputEvent()
                            {
                                nKey       = 4,
                                b押された      = false,
                                nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻ms,                                 // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。
                            };
                            this.list入力イベント.Add(ev);

                            this.bButtonState[4]  = false;
                            this.bButtonPullUp[4] = true;
                        }
                    }
                    //-----------------------------
                    #endregion
                    #region [ Z軸+ ]
                    //-----------------------------
                    if (ButtonState.GetAxis(2) > 0.5)
                    {
                        if (this.bButtonState[5] == false)
                        {
                            STInputEvent ev = new STInputEvent()
                            {
                                nKey       = 5,
                                b押された      = true,
                                nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻ms,                                 // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。
                            };
                            this.list入力イベント.Add(ev);

                            this.bButtonState[5]    = true;
                            this.bButtonPushDown[5] = true;
                        }
                    }
                    else
                    {
                        if (this.bButtonState[5] == true)
                        {
                            STInputEvent event15 = new STInputEvent()
                            {
                                nKey       = 5,
                                b押された      = false,
                                nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻ms,                                 // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。
                            };
                            this.list入力イベント.Add(event15);

                            this.bButtonState[5]  = false;
                            this.bButtonPullUp[5] = true;
                        }
                    }
                    //-----------------------------
                    #endregion
                    #region [ Z軸回転- ]
                    //-----------------------------
                    if (ButtonState.GetAxis(3) < -0.5)
                    {
                        if (this.bButtonState[6] == false)
                        {
                            STInputEvent ev = new STInputEvent()
                            {
                                nKey       = 6,
                                b押された      = true,
                                nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻ms,                                 // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。
                            };
                            this.list入力イベント.Add(ev);

                            this.bButtonState[6]    = true;
                            this.bButtonPushDown[6] = true;
                        }
                    }
                    else
                    {
                        if (this.bButtonState[4] == true)
                        {
                            STInputEvent ev = new STInputEvent()
                            {
                                nKey       = 6,
                                b押された      = false,
                                nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻ms,                                 // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。
                            };
                            this.list入力イベント.Add(ev);

                            this.bButtonState[6]  = false;
                            this.bButtonPullUp[6] = true;
                        }
                    }
                    //-----------------------------
                    #endregion
                    #region [ Z軸回転+ ]
                    //-----------------------------
                    if (ButtonState.GetAxis(3) > 0.5)
                    {
                        if (this.bButtonState[7] == false)
                        {
                            STInputEvent ev = new STInputEvent()
                            {
                                nKey       = 7,
                                b押された      = true,
                                nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻ms,                                 // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。
                            };
                            this.list入力イベント.Add(ev);

                            this.bButtonState[7]    = true;
                            this.bButtonPushDown[7] = true;
                        }
                    }
                    else
                    {
                        if (this.bButtonState[7] == true)
                        {
                            STInputEvent event15 = new STInputEvent()
                            {
                                nKey       = 7,
                                b押された      = false,
                                nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻ms,                                 // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。
                            };
                            this.list入力イベント.Add(event15);

                            this.bButtonState[7]  = false;
                            this.bButtonPullUp[7] = true;
                        }
                    }
                    //-----------------------------
                    #endregion
                    #region [ Button ]
                    //-----------------------------
                    bool bIsButtonPressedReleased = false;
                    for (int j = 0; j < 128; j++)
                    {
                        if (this.bButtonState[8 + j] == false && ButtonState.IsButtonDown(j))
                        {
                            STInputEvent item = new STInputEvent()
                            {
                                nKey       = 8 + j,
                                b押された      = true,
                                nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻ms,                                 // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。
                            };
                            this.list入力イベント.Add(item);

                            this.bButtonState[8 + j]    = true;
                            this.bButtonPushDown[8 + j] = true;
                            bIsButtonPressedReleased    = true;
                        }
                        else if (this.bButtonState[8 + j] == true && !ButtonState.IsButtonDown(j))
                        {
                            STInputEvent item = new STInputEvent()
                            {
                                nKey       = 8 + j,
                                b押された      = false,
                                nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻ms,                                 // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。
                            };
                            this.list入力イベント.Add(item);

                            this.bButtonState[8 + j]  = false;
                            this.bButtonPullUp[8 + j] = true;
                            bIsButtonPressedReleased  = true;
                        }
                    }
                    //-----------------------------
                    #endregion
                    // #24341 2011.3.12 yyagi: POV support
                    #region [ POV HAT 4/8way (only single POV switch is supported)]
                    JoystickHatState hatState = ButtonState.GetHat(JoystickHat.Hat0);

                    for (int nWay = 0; nWay < 8; nWay++)
                    {
                        if (hatState.Position == (OpenTK.Input.HatPosition)nWay + 1)
                        {
                            if (this.bButtonState[8 + 128 + nWay] == false)
                            {
                                STInputEvent stevent = new STInputEvent()
                                {
                                    nKey       = 8 + 128 + nWay,
                                    b押された      = true,
                                    nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻ms,                                     // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。
                                };
                                this.list入力イベント.Add(stevent);

                                this.bButtonState[stevent.nKey]    = true;
                                this.bButtonPushDown[stevent.nKey] = true;
                            }
                            bIsButtonPressedReleased = true;
                        }
                    }
                    if (bIsButtonPressedReleased == false)                     // #xxxxx 2011.12.3 yyagi 他のボタンが何も押され/離されてない=POVが離された
                    {
                        int nWay = 0;
                        for (int i = 8 + 0x80; i < 8 + 0x80 + 8; i++)
                        {                                                                   // 離されたボタンを調べるために、元々押されていたボタンを探す。
                            if (this.bButtonState[i] == true)                               // DirectInputを直接いじるならこんなことしなくて良いのに、あぁ面倒。
                            {                                                               // この処理が必要なために、POVを1個しかサポートできない。無念。
                                nWay = i;
                                break;
                            }
                        }
                        if (nWay != 0)
                        {
                            STInputEvent stevent = new STInputEvent()
                            {
                                nKey       = nWay,
                                b押された      = false,
                                nTimeStamp = CSound管理.rc演奏用タイマ.nシステム時刻ms,                                 // 演奏用タイマと同じタイマを使うことで、BGMと譜面、入力ずれを防ぐ。
                            };
                            this.list入力イベント.Add(stevent);

                            this.bButtonState[nWay]  = false;
                            this.bButtonPullUp[nWay] = true;
                        }
                    }
                    #endregion
                    //-----------------------------
                    #endregion
                }
            }
        }
コード例 #22
0
        public IEnumerable <Tuple <string, float> > GetFloats()
        {
            if (_gamePadCapabilities.HasValue && _gamePadCapabilities.Value.IsMapped)
            {
                // automapping identified - use OpenTK.Input.GamePad class
                yield return(new Tuple <string, float>("LeftThumbX", SetBounds(state.ThumbSticks.Left.X)));

                yield return(new Tuple <string, float>("LeftThumbY", SetBounds(state.ThumbSticks.Left.Y)));

                yield return(new Tuple <string, float>("RightThumbX", SetBounds(state.ThumbSticks.Right.X)));

                yield return(new Tuple <string, float>("RightThumbY", SetBounds(state.ThumbSticks.Right.Y)));

                yield return(new Tuple <string, float>("LeftTrigger", SetBounds(state.Triggers.Left)));

                yield return(new Tuple <string, float>("RightTrigger", SetBounds(state.Triggers.Right)));

                yield break;
            }
            else
            {
                // use OpenTK.Input.Joystick class
                yield return(new Tuple <string, float>("X", SetBounds(jState.GetAxis(0))));

                yield return(new Tuple <string, float>("Y", SetBounds(jState.GetAxis(1))));

                yield return(new Tuple <string, float>("Z", SetBounds(jState.GetAxis(2))));

                yield return(new Tuple <string, float>("W", SetBounds(jState.GetAxis(3))));

                yield return(new Tuple <string, float>("V", SetBounds(jState.GetAxis(4))));

                yield return(new Tuple <string, float>("S", SetBounds(jState.GetAxis(5))));

                yield return(new Tuple <string, float>("Q", SetBounds(jState.GetAxis(6))));

                yield return(new Tuple <string, float>("P", SetBounds(jState.GetAxis(7))));

                yield return(new Tuple <string, float>("N", SetBounds(jState.GetAxis(8))));

                for (int i = 9; i < 64; i++)
                {
                    int j = i;
                    yield return(new Tuple <string, float>(string.Format("Axis{0}", j.ToString()), SetBounds(jState.GetAxis(j))));
                }

                yield break;
            }
        }
コード例 #23
0
        public void Update()
        {
            for (int i = 0; i < curKeysDown.Length; ++i)
            {
                prevKeysDown[i] = curKeysDown[i];
                curKeysDown[i]  = game.Keyboard[(Key)i];
            }
            for (int i = 0; i < curMouseDown.Length; ++i)
            {
                prevMouseDown[i] = curMouseDown[i];
                curMouseDown[i]  = game.Mouse[(MouseButton)i];
            }
            mousePosition.X = game.Mouse.X;
            mousePosition.Y = game.Mouse.Y;
            mouseDeltaPos.X = ((float)game.Mouse.XDelta) / ((float)game.ClientSize.Width);
            mouseDeltaPos.Y = ((float)game.Mouse.YDelta) / ((float)game.ClientSize.Height);

            for (int i = 0; i < numJoysticks; ++i)
            {
                if (IsConnected(i))
                {
                    JoystickState state = Joystick.GetState(i);

                    for (int j = 0; j < curJoyDown[i].Buttons.Length; ++j)
                    {
                        prevJoyDown[i].Buttons[j] = curJoyDown[i].Buttons[j];
                        curJoyDown[i].Buttons[j]  = joyMapping[i].HasButtons[j] ? state.GetButton(joyMapping[i].Buttons[j]) == ButtonState.Pressed : false;
                    }
                    prevJoyDown[i].LeftAxis.X  = curJoyDown[i].LeftAxis.X;
                    prevJoyDown[i].LeftAxis.Y  = curJoyDown[i].LeftAxis.Y;
                    prevJoyDown[i].RightAxis.X = curJoyDown[i].RightAxis.X;
                    prevJoyDown[i].RightAxis.Y = curJoyDown[i].RightAxis.Y;

                    curJoyDown[i].LeftAxis.X  = joyMapping[i].HasLeftAxisX ? state.GetAxis(joyMapping[i].LeftAxisX) : 0.0f;
                    curJoyDown[i].LeftAxis.Y  = joyMapping[i].HasLeftAxisY ? state.GetAxis(joyMapping[i].LeftAxisY) : 0.0f;
                    curJoyDown[i].RightAxis.X = joyMapping[i].HasRightAxisX ? state.GetAxis(joyMapping[i].RightAxisX) : 0.0f;
                    curJoyDown[i].RightAxis.Y = joyMapping[i].HasRightAxisY ? state.GetAxis(joyMapping[i].RightAxisY) : 0.0f;

                    if (curJoyDown[i].LeftAxis.X > 0.0f && curJoyDown[i].LeftAxis.X < joyDeadZone[i])
                    {
                        curJoyDown[i].LeftAxis.X = 0.0f;
                    }
                    else if (curJoyDown[i].LeftAxis.X <0.0f && curJoyDown[i].LeftAxis.X> -joyDeadZone[i])
                    {
                        curJoyDown[i].LeftAxis.X = 0.0f;
                    }

                    if (curJoyDown[i].LeftAxis.Y > 0.0f && curJoyDown[i].LeftAxis.Y < joyDeadZone[i])
                    {
                        curJoyDown[i].LeftAxis.Y = 0.0f;
                    }
                    else if (curJoyDown[i].LeftAxis.Y <0.0f && curJoyDown[i].LeftAxis.Y> -joyDeadZone[i])
                    {
                        curJoyDown[i].LeftAxis.Y = 0.0f;
                    }

                    if (curJoyDown[i].RightAxis.X > 0.0f && curJoyDown[i].RightAxis.X < joyDeadZone[i])
                    {
                        curJoyDown[i].RightAxis.X = 0.0f;
                    }
                    else if (curJoyDown[i].RightAxis.X <0.0f && curJoyDown[i].RightAxis.X> -joyDeadZone[i])
                    {
                        curJoyDown[i].RightAxis.X = 0.0f;
                    }

                    if (curJoyDown[i].RightAxis.Y > 0.0f && curJoyDown[i].RightAxis.Y < joyDeadZone[i])
                    {
                        curJoyDown[i].RightAxis.Y = 0.0f;
                    }
                    else if (curJoyDown[i].RightAxis.Y <0.0f && curJoyDown[i].RightAxis.Y> -joyDeadZone[i])
                    {
                        curJoyDown[i].RightAxis.Y = 0.0f;
                    }
                }
            }
        }
コード例 #24
0
        /// <summary>
        /// Reads the input from the controller.
        /// </summary>
        internal override void ReadInput()
        {
            JoystickState joystick  = Joystick.GetState(joystickIndex);
            double        brakeAxis = Math.Round(joystick.GetAxis(0), 4);
            double        powerAxis = Math.Round(joystick.GetAxis(1), 4);

            for (int i = 0; i < brakeBytes.Length; i += 2)
            {
                // Each notch uses two bytes, minimum value and maximum value
                if (brakeAxis >= GetAxisValue(brakeBytes[i]) && brakeAxis <= GetAxisValue(brakeBytes[i + 1]))
                {
                    if (brakeBytes.Length == i + 2)
                    {
                        // Last notch should be Emergency
                        InputTranslator.BrakeNotch = InputTranslator.BrakeNotches.Emergency;
                    }
                    else
                    {
                        // Regular brake notch
                        InputTranslator.BrakeNotch = (InputTranslator.BrakeNotches)(i / 2);
                    }
                    break;
                }
            }
            for (int i = 0; i < powerBytes.Length; i += 2)
            {
                // Each notch uses two bytes, minimum value and maximum value
                if (powerAxis >= GetAxisValue(powerBytes[i]) && powerAxis <= GetAxisValue(powerBytes[i + 1]))
                {
                    InputTranslator.PowerNotch = (InputTranslator.PowerNotches)(i / 2);
                    break;
                }
            }

            InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.Select] = joystick.GetButton(buttonIndex[(int)InputTranslator.ControllerButton.Select]);
            InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.Start]  = joystick.GetButton(buttonIndex[(int)InputTranslator.ControllerButton.Start]);
            InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.A]      = joystick.GetButton(buttonIndex[(int)InputTranslator.ControllerButton.A]);
            InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.B]      = joystick.GetButton(buttonIndex[(int)InputTranslator.ControllerButton.B]);
            InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.C]      = joystick.GetButton(buttonIndex[(int)InputTranslator.ControllerButton.C]);
            InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.D]      = joystick.GetButton(buttonIndex[(int)InputTranslator.ControllerButton.D]);
            InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.LDoor]  = joystick.GetButton(buttonIndex[(int)InputTranslator.ControllerButton.LDoor]);
            InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.RDoor]  = joystick.GetButton(buttonIndex[(int)InputTranslator.ControllerButton.RDoor]);

            if (Buttons.HasFlag(ControllerButtons.DPad))
            {
                if (comboDpad)
                {
                    // On some controllers, check for Select+A/B/C/D combo
                    bool dPadUp    = Convert.ToBoolean(joystick.GetButton(buttonIndex[(int)InputTranslator.ControllerButton.Select])) && Convert.ToBoolean(joystick.GetButton(buttonIndex[(int)InputTranslator.ControllerButton.D]));
                    bool dPadDown  = Convert.ToBoolean(joystick.GetButton(buttonIndex[(int)InputTranslator.ControllerButton.Select])) && Convert.ToBoolean(joystick.GetButton(buttonIndex[(int)InputTranslator.ControllerButton.B]));
                    bool dPadLeft  = Convert.ToBoolean(joystick.GetButton(buttonIndex[(int)InputTranslator.ControllerButton.Select])) && Convert.ToBoolean(joystick.GetButton(buttonIndex[(int)InputTranslator.ControllerButton.A]));
                    bool dPadRight = Convert.ToBoolean(joystick.GetButton(buttonIndex[(int)InputTranslator.ControllerButton.Select])) && Convert.ToBoolean(joystick.GetButton(buttonIndex[(int)InputTranslator.ControllerButton.C]));
                    bool dPadAny   = dPadUp || dPadDown || dPadLeft || dPadRight;
                    InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.Up]    = (ButtonState)(dPadUp ? 1 : 0);
                    InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.Down]  = (ButtonState)(dPadDown ? 1 : 0);
                    InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.Left]  = (ButtonState)(dPadLeft ? 1 : 0);
                    InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.Right] = (ButtonState)(dPadRight ? 1 : 0);
                    // Disable original buttons if necessary
                    InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.Select] = InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.Select] ^ (ButtonState)(dPadAny ? 1 : 0);
                    InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.A]      = InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.A] ^ (ButtonState)(dPadLeft ? 1 : 0);
                    InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.B]      = InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.B] ^ (ButtonState)(dPadDown ? 1 : 0);
                    InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.C]      = InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.C] ^ (ButtonState)(dPadRight ? 1 : 0);
                    InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.D]      = InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.D] ^ (ButtonState)(dPadUp ? 1 : 0);
                }
                else
                {
                    // On other controllers, read the first hat
                    InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.Up]    = (ButtonState)(joystick.GetHat(JoystickHat.Hat0).IsUp ? 1 : 0);
                    InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.Down]  = (ButtonState)(joystick.GetHat(JoystickHat.Hat0).IsDown ? 1 : 0);
                    InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.Left]  = (ButtonState)(joystick.GetHat(JoystickHat.Hat0).IsLeft ? 1 : 0);
                    InputTranslator.ControllerButtons[(int)InputTranslator.ControllerButton.Right] = (ButtonState)(joystick.GetHat(JoystickHat.Hat0).IsRight ? 1 : 0);
                }
            }
        }
コード例 #25
0
        private string GetAxisText(JoystickAxis axis)
        {
            var axisValue = _currentState.GetAxis(axis);

            return(string.Format("{0}={1}", axis, axisValue));
        }
コード例 #26
0
 double GetLRAcc(JoystickState state) => state.GetAxis(2);
コード例 #27
0
        public void UpdateInputState()
        {
            JoystickState state = Joystick.GetState(0);

            if (state.IsConnected)
            {
                if (false)
                {
                    Console.WriteLine(@"axis0={0}", state.GetAxis(JoystickAxis.Axis0)); // side to side
                    Console.WriteLine(@"axis1={0}", state.GetAxis(JoystickAxis.Axis1)); // forward back
                    Console.WriteLine(@"axis2={0}", state.GetAxis(JoystickAxis.Axis2)); // knob
                    Console.WriteLine(@"axis3={0}", state.GetAxis(JoystickAxis.Axis3)); // z-rotation
                    Console.WriteLine(@"axis4={0}", state.GetAxis(JoystickAxis.Axis4));
                    Console.WriteLine(@"axis5={0}", state.GetAxis(JoystickAxis.Axis5));
                    Console.WriteLine(@"axis6={0}", state.GetAxis(JoystickAxis.Axis6));
                    Console.WriteLine(@"axis7={0}", state.GetAxis(JoystickAxis.Axis7));

                    Console.WriteLine(@"button0={0}", state.GetButton(JoystickButton.Button0));
                    Console.WriteLine(@"button1={0}", state.GetButton(JoystickButton.Button1));
                    Console.WriteLine(@"button2={0}", state.GetButton(JoystickButton.Button2));
                    Console.WriteLine(@"button3={0}", state.GetButton(JoystickButton.Button3));
                    Console.WriteLine(@"button4={0}", state.GetButton(JoystickButton.Button4));
                    Console.WriteLine(@"button5={0}", state.GetButton(JoystickButton.Button5));
                    Console.WriteLine(@"button6={0}", state.GetButton(JoystickButton.Button6));
                    Console.WriteLine(@"button7={0}", state.GetButton(JoystickButton.Button7));
                    Console.WriteLine(@"button8={0}", state.GetButton(JoystickButton.Button8));
                    Console.WriteLine(@"button9={0}", state.GetButton(JoystickButton.Button9));
                    Console.WriteLine(@"button10={0}", state.GetButton(JoystickButton.Button10)); // hat up
                    Console.WriteLine(@"button11={0}", state.GetButton(JoystickButton.Button11)); // hat left
                    Console.WriteLine(@"button12={0}", state.GetButton(JoystickButton.Button12)); // hat right
                    Console.WriteLine(@"button13={0}", state.GetButton(JoystickButton.Button13)); // hat down
                    Console.WriteLine(@"button14={0}", state.GetButton(JoystickButton.Button14));
                    Console.WriteLine(@"button15={0}", state.GetButton(JoystickButton.Button15));

                    Console.ReadKey();
                }

                var x       = state.GetAxis(JoystickAxis.Axis0); // used for rotating up
                var y       = state.GetAxis(JoystickAxis.Axis1);
                var z       = state.GetAxis(JoystickAxis.Axis3);
                var forward = state.GetAxis(JoystickAxis.Axis2);

                var strafeUp    = state.GetButton(JoystickButton.Button10) == OpenTK.Input.ButtonState.Pressed;
                var strafeLeft  = state.GetButton(JoystickButton.Button11) == OpenTK.Input.ButtonState.Pressed;
                var strafeRight = state.GetButton(JoystickButton.Button12) == OpenTK.Input.ButtonState.Pressed;
                var strafeDown  = state.GetButton(JoystickButton.Button13) == OpenTK.Input.ButtonState.Pressed;
                var reset       = state.GetButton(JoystickButton.Button8) == OpenTK.Input.ButtonState.Pressed;
                var goSlow      = state.GetButton(JoystickButton.Button1) == OpenTK.Input.ButtonState.Pressed;
                var goFast      = state.GetButton(JoystickButton.Button3) == OpenTK.Input.ButtonState.Pressed;

                if (Math.Abs(forward) > 0.1f)
                {
                    MoveForward(-forward * WalkSpeed);
                }

                if (Math.Abs(x) > 0.1f)
                {
                    RotateUp(x);
                }

                if (strafeUp || strafeDown ||
                    strafeRight ||
                    strafeLeft)
                {
                    var strafeX = strafeLeft ? StrafeSpeed : strafeRight ? -StrafeSpeed : 0f;
                    var strafeY = strafeUp ? StrafeSpeed : strafeDown ? -StrafeSpeed : 0f;
                    Strafe(strafeX, strafeY);
                }

                if (z > 0.05f || z < -0.05f || y > 0.05f || y < -0.05f)
                {
                    //Console.Out.WriteLine("x="+z+" y="+z);
                    Rotate(z * RotateSpeed, y * RotateSpeed);
                }

                if (reset)
                {
                    Reset();
                }

                if (!_lastGoSlow && goSlow)
                {
                    SlowDown();
                }
                if (!_lastGoFast && goFast)
                {
                    SpeedUp();
                }
                _lastGoSlow = goSlow;
                _lastGoFast = goFast;
            }

            if (false) // this.Focused || GraphicsWindow.Focused)
            {
                //DirectInput.KeyboardState ks = keyboardDevice.GetCurrentKeyboardState();
                //float m = 1f;
                //if (ks[DirectInput.Key.LeftShift]) m = 10f;
                //if (ks[DirectInput.Key.W]) camera.MoveForward(m);
                //if (ks[DirectInput.Key.S]) camera.MoveForward(-m);
                //if (ks[DirectInput.Key.A]) camera.Strafe(-m, 0f);
                //if (ks[DirectInput.Key.D]) camera.Strafe(m, 0f);
                //if (ks[DirectInput.Key.E]) camera.Strafe(0f, m);
                //if (ks[DirectInput.Key.C]) camera.Strafe(0f, -m);
                //if (ks[DirectInput.Key.P]) camera.describe();
            }
        }
コード例 #28
0
 double GetFBAcc(JoystickState state) => (-1) * state.GetAxis(6);
コード例 #29
0
ファイル: ControllerWindow.cs プロジェクト: valx76/Ryujinx
        private static bool IsAnyButtonPressed(out ControllerInputId pressedButton, int index, double triggerThreshold)
        {
            JoystickState        joystickState        = Joystick.GetState(index);
            JoystickCapabilities joystickCapabilities = Joystick.GetCapabilities(index);

            //Buttons
            for (int i = 0; i != joystickCapabilities.ButtonCount; i++)
            {
                if (joystickState.IsButtonDown(i))
                {
                    Enum.TryParse($"Button{i}", out pressedButton);

                    return(true);
                }
            }

            //Axis
            for (int i = 0; i != joystickCapabilities.AxisCount; i++)
            {
                if (joystickState.GetAxis(i) > 0.5f && joystickState.GetAxis(i) > triggerThreshold)
                {
                    Enum.TryParse($"Axis{i}", out pressedButton);

                    return(true);
                }
            }

            //Hats
            for (int i = 0; i != joystickCapabilities.HatCount; i++)
            {
                JoystickHatState hatState = joystickState.GetHat((JoystickHat)i);
                string           pos      = null;

                if (hatState.IsUp)
                {
                    pos = "Up";
                }
                if (hatState.IsDown)
                {
                    pos = "Down";
                }
                if (hatState.IsLeft)
                {
                    pos = "Left";
                }
                if (hatState.IsRight)
                {
                    pos = "Right";
                }
                if (pos == null)
                {
                    continue;
                }

                Enum.TryParse($"Hat{i}{pos}", out pressedButton);

                return(true);
            }

            pressedButton = ControllerInputId.Unbound;

            return(false);
        }
コード例 #30
0
 double GetRoll(JoystickState state) => (-1) * state.GetAxis(5) * Math.PI;