/// <summary>
        /// Returns the currently pressed buttons on the XInput controller as an array of buttons.
        /// </summary>
        public bool[] GetButtons()
        {
            // Create the array of buttons.
            bool[] buttons = new bool[Enum.GetNames(typeof(ControllerButtonsGeneric)).Length];

            // Get XBOX Buttons
            GamepadButtonFlags buttonFlags = ControllerState.Gamepad.Buttons;

            // Retrieve Controller Button Status.
            buttons[(int)ControllerButtonsGeneric.ButtonA] = buttonFlags.HasFlag(GamepadButtonFlags.A);
            buttons[(int)ControllerButtonsGeneric.ButtonB] = buttonFlags.HasFlag(GamepadButtonFlags.B);
            buttons[(int)ControllerButtonsGeneric.ButtonX] = buttonFlags.HasFlag(GamepadButtonFlags.X);
            buttons[(int)ControllerButtonsGeneric.ButtonY] = buttonFlags.HasFlag(GamepadButtonFlags.Y);

            buttons[(int)ControllerButtonsGeneric.ButtonLs] = buttonFlags.HasFlag(GamepadButtonFlags.LeftThumb);
            buttons[(int)ControllerButtonsGeneric.ButtonRs] = buttonFlags.HasFlag(GamepadButtonFlags.RightThumb);

            buttons[(int)ControllerButtonsGeneric.ButtonLb] = buttonFlags.HasFlag(GamepadButtonFlags.LeftShoulder);
            buttons[(int)ControllerButtonsGeneric.ButtonRb] = buttonFlags.HasFlag(GamepadButtonFlags.RightShoulder);

            buttons[(int)ControllerButtonsGeneric.ButtonBack]  = buttonFlags.HasFlag(GamepadButtonFlags.Back);
            buttons[(int)ControllerButtonsGeneric.ButtonStart] = buttonFlags.HasFlag(GamepadButtonFlags.Start);
            buttons[(int)ControllerButtonsGeneric.ButtonGuide] = false;

            // Return buttons.
            return(buttons);
        }
        internal GameControllerStateDPad(GamepadButtonFlags flags)
        {
            Up    = flags.HasFlag(GamepadButtonFlags.DPadUp);
            Down  = flags.HasFlag(GamepadButtonFlags.DPadDown);
            Left  = flags.HasFlag(GamepadButtonFlags.DPadLeft);
            Right = flags.HasFlag(GamepadButtonFlags.DPadRight);

            AnyInteraction = (int)flags > 0 && (int)flags < 16;
        }
Ejemplo n.º 3
0
 public bool GetBButton(GamepadButtonFlags flags)
 {
     if (flags.HasFlag(GamepadButtonFlags.B)) {
         return true;
     }
     return false;
 }
        /// <summary>
        /// Retrieves the state of all of the axis and buttons of the controller as well as the DPAD state
        /// and retrieves it in a struct format convenient for the modder's use.
        /// </summary>
        /// <returns>Controller inputs as a custom struct.</returns>
        public ControllerInputs GetControllerState()
        {
            // Instantiate an instance of controller inputs.
            ControllerInputs controllerInputs = new ControllerInputs();

            // Check if controller is connected.
            if (Controller.IsConnected)
            {
                // Update the current state of the Joystick/Controller
                ControllerState = Controller.GetState();

                // Retrieve all of the buttons;
                controllerInputs = GetControllerStateButtons(controllerInputs);

                // Retrieve all of the axis.
                controllerInputs = GetControllerStateAxis(controllerInputs);

                // Retrieve DPAD Information
                GamepadButtonFlags buttonFlags = ControllerState.Gamepad.Buttons;

                if (buttonFlags.HasFlag(GamepadButtonFlags.DPadUp))
                {
                    controllerInputs.ControllerButtons.DpadUp = true;
                }
                if (buttonFlags.HasFlag(GamepadButtonFlags.DPadLeft))
                {
                    controllerInputs.ControllerButtons.DpadLeft = true;
                }
                if (buttonFlags.HasFlag(GamepadButtonFlags.DPadRight))
                {
                    controllerInputs.ControllerButtons.DpadRight = true;
                }
                if (buttonFlags.HasFlag(GamepadButtonFlags.DPadDown))
                {
                    controllerInputs.ControllerButtons.DpadDown = true;
                }

                // Retrieve Emulated Keys
                controllerInputs = GetControllerState_EmulatedKeys(controllerInputs, GetButtons());
            }

            // Return to base.
            return(controllerInputs);
        }
Ejemplo n.º 5
0
        private void CheckButton(GamepadButtonFlags button, GamepadButtonFlags newFlags, ref bool flagToTrigger)
        {
            GamepadButtonFlags lastFlags = lastState.Gamepad.Buttons;

            if (newFlags.HasFlag(button))
            {
                if (!lastFlags.HasFlag(button))
                {
                    flagToTrigger = true;
                }
            }
        }
Ejemplo n.º 6
0
        internal GameControllerStateButtons(GamepadButtonFlags flags, GameController controller)
        {
            _buttonFlags     = flags;
            _lastButtonFlags = controller._lastPressedButtons;

            X = flags.HasFlag(GamepadButtonFlags.X);
            Y = flags.HasFlag(GamepadButtonFlags.Y);
            A = flags.HasFlag(GamepadButtonFlags.A);
            B = flags.HasFlag(GamepadButtonFlags.B);

            LB = flags.HasFlag(GamepadButtonFlags.LeftShoulder);
            RB = flags.HasFlag(GamepadButtonFlags.RightShoulder);

            LeftThumb  = flags.HasFlag(GamepadButtonFlags.LeftThumb);
            RightThumb = flags.HasFlag(GamepadButtonFlags.RightThumb);

            Start = flags.HasFlag(GamepadButtonFlags.Start);
            Back  = flags.HasFlag(GamepadButtonFlags.Back);

            AnyInteraction = (int)flags >= 16;
        }
Ejemplo n.º 7
0
            //public int searchid(int[] arr, int id)
            //{
            //    for (int i = 0; i < arr.Length; ++i)
            //    {
            //        if (arr[i] == id) return i;
            //    }
            //    return -1;
            //}

            public void Checkstate(Controller controller, Joystick stickk)
            {
                State state = controller.GetState();
                GamepadButtonFlags gamepadButtonFlags = state.Gamepad.Buttons;

                stateChanged     = false;
                DstateChanged    = false;
                BstateChanged    = false;
                BindstateChanged = false;

                JoystickState state1 = new JoystickState();

                state1  = stickk.GetCurrentState();
                buttons = state1.GetButtons();
                zValue  = state1.Z;
                //Console.WriteLine(zValue);

                mem = Dup;
                if (gamepadButtonFlags.HasFlag(GamepadButtonFlags.DPadUp))
                {
                    Dup = true;
                }
                else
                {
                    Dup = false;
                }
                if (mem != Dup)
                {
                    stateChanged = true; DstateChanged = true;
                }

                mem = Ddown;
                if (gamepadButtonFlags.HasFlag(GamepadButtonFlags.DPadDown))
                {
                    Ddown = true;
                }
                else
                {
                    Ddown = false;
                }
                if (mem != Ddown)
                {
                    stateChanged = true; DstateChanged = true;
                }

                mem = Dleft;
                if (gamepadButtonFlags.HasFlag(GamepadButtonFlags.DPadLeft))
                {
                    Dleft = true;
                }
                else
                {
                    Dleft = false;
                }
                if (mem != Dleft)
                {
                    stateChanged = true; DstateChanged = true;
                }

                mem = Dright;
                if (gamepadButtonFlags.HasFlag(GamepadButtonFlags.DPadRight))
                {
                    Dright = true;
                }
                else
                {
                    Dright = false;
                }
                if (mem != Dright)
                {
                    stateChanged = true; DstateChanged = true;
                }

                if (ids[9] != -1)
                {
                    mem = three;//9
                    //if (gamepadButtonFlags.HasFlag(GamepadButtonFlags.A)) three = true;
                    if (buttons[ids[9]])
                    {
                        three = true;
                    }
                    else
                    {
                        three = false;
                    }
                    if (mem != three)
                    {
                        stateChanged = true; BstateChanged = true;
                    }
                }

                if (ids[10] != -1)
                {
                    mem = four; //10
                                //if (gamepadButtonFlags.HasFlag(GamepadButtonFlags.B)) four = true;
                    if (buttons[ids[10]])
                    {
                        four = true;
                    }
                    else
                    {
                        four = false;
                    }
                    if (mem != four)
                    {
                        stateChanged = true; BstateChanged = true;
                    }
                }

                if (ids[7] != -1)
                {
                    mem = one; //7
                               //if (gamepadButtonFlags.HasFlag(GamepadButtonFlags.X)) one = true;
                    if (buttons[ids[7]])
                    {
                        one = true;
                    }
                    else
                    {
                        one = false;
                    }
                    if (mem != one)
                    {
                        stateChanged = true; BstateChanged = true;
                    }
                }

                if (ids[8] != -1)
                {
                    mem = two; //8
                               //if (gamepadButtonFlags.HasFlag(GamepadButtonFlags.Y)) two = true;
                    if (buttons[ids[8]])
                    {
                        two = true;
                    }
                    else
                    {
                        two = false;
                    }
                    if (mem != two)
                    {
                        stateChanged = true; BstateChanged = true;
                    }
                }

                for (int i = 0; i < 7; ++i)
                {
                    if (ids[i] == -1)
                    {
                        continue;
                    }

                    mem = binds[i];

                    if (ids[i] == 50)
                    {
                        if (zValue >= 50)
                        {
                            binds[i] = true;
                        }
                        else
                        {
                            binds[i] = false;
                        }
                    }
                    else if (ids[i] == -50)
                    {
                        if (zValue <= -50)
                        {
                            binds[i] = true;
                        }
                        else
                        {
                            binds[i] = false;
                        }
                    }
                    else
                    {
                        if (buttons[ids[i]] == true)
                        {
                            binds[i] = true;
                        }
                        else
                        {
                            binds[i] = false;
                        }
                    }
                    //Console.WriteLine(binds[i] + " " + i);

                    if (mem != binds[i])
                    {
                        stateChanged = true; BstateChanged = true;
                    }
                }
            }
Ejemplo n.º 8
0
        public static GamePadCapabilities GetCapabilities(PlayerIndex playerIndex)
        {
            Controller controller = GamePad.GetController(playerIndex);

            if (!controller.IsConnected)
            {
                return(new GamePadCapabilities());
            }
            SharpDX.XInput.Capabilities capabilities        = controller.GetCapabilities(DeviceQueryType.Any);
            GamePadCapabilities         gamePadCapabilities = new GamePadCapabilities();

            switch (capabilities.SubType)
            {
            case DeviceSubType.Gamepad:
                gamePadCapabilities.GamePadType = GamePadType.GamePad;
                break;

            case DeviceSubType.Wheel:
                gamePadCapabilities.GamePadType = GamePadType.Wheel;
                break;

            case DeviceSubType.ArcadeStick:
                gamePadCapabilities.GamePadType = GamePadType.ArcadeStick;
                break;

            case DeviceSubType.DancePad:
                gamePadCapabilities.GamePadType = GamePadType.DancePad;
                break;

            case DeviceSubType.Guitar:
                gamePadCapabilities.GamePadType = GamePadType.Guitar;
                break;

            case DeviceSubType.DrumKit:
                gamePadCapabilities.GamePadType = GamePadType.DrumKit;
                break;

            default:
                gamePadCapabilities.GamePadType = GamePadType.Unknown;
                break;
            }
            Gamepad            gamepad            = capabilities.Gamepad;
            GamepadButtonFlags gamepadButtonFlags = gamepad.Buttons;

            gamePadCapabilities.HasAButton             = gamepadButtonFlags.HasFlag((Enum)GamepadButtonFlags.A);
            gamePadCapabilities.HasBackButton          = gamepadButtonFlags.HasFlag((Enum)GamepadButtonFlags.Back);
            gamePadCapabilities.HasBButton             = gamepadButtonFlags.HasFlag((Enum)GamepadButtonFlags.B);
            gamePadCapabilities.HasBigButton           = false;
            gamePadCapabilities.HasDPadDownButton      = gamepadButtonFlags.HasFlag((Enum)GamepadButtonFlags.DPadDown);
            gamePadCapabilities.HasDPadLeftButton      = gamepadButtonFlags.HasFlag((Enum)GamepadButtonFlags.DPadLeft);
            gamePadCapabilities.HasDPadRightButton     = gamepadButtonFlags.HasFlag((Enum)GamepadButtonFlags.DPadLeft);
            gamePadCapabilities.HasDPadUpButton        = gamepadButtonFlags.HasFlag((Enum)GamepadButtonFlags.DPadUp);
            gamePadCapabilities.HasLeftShoulderButton  = gamepadButtonFlags.HasFlag((Enum)GamepadButtonFlags.LeftShoulder);
            gamePadCapabilities.HasLeftStickButton     = gamepadButtonFlags.HasFlag((Enum)GamepadButtonFlags.LeftThumb);
            gamePadCapabilities.HasRightShoulderButton = gamepadButtonFlags.HasFlag((Enum)GamepadButtonFlags.RightShoulder);
            gamePadCapabilities.HasRightStickButton    = gamepadButtonFlags.HasFlag((Enum)GamepadButtonFlags.RightThumb);
            gamePadCapabilities.HasStartButton         = gamepadButtonFlags.HasFlag((Enum)GamepadButtonFlags.Start);
            gamePadCapabilities.HasXButton             = gamepadButtonFlags.HasFlag((Enum)GamepadButtonFlags.X);
            gamePadCapabilities.HasYButton             = gamepadButtonFlags.HasFlag((Enum)GamepadButtonFlags.Y);
            gamePadCapabilities.HasRightTrigger        = (int)gamepad.LeftTrigger > 0;
            gamePadCapabilities.HasRightXThumbStick    = (int)gamepad.RightThumbX != 0;
            gamePadCapabilities.HasRightYThumbStick    = (int)gamepad.RightThumbY != 0;
            gamePadCapabilities.HasLeftTrigger         = (int)gamepad.LeftTrigger > 0;
            gamePadCapabilities.HasLeftXThumbStick     = (int)gamepad.LeftThumbX != 0;
            gamePadCapabilities.HasLeftYThumbStick     = (int)gamepad.LeftThumbY != 0;
            gamePadCapabilities.HasLeftVibrationMotor  = (int)capabilities.Vibration.LeftMotorSpeed > 0;
            gamePadCapabilities.HasRightVibrationMotor = (int)capabilities.Vibration.RightMotorSpeed > 0;
            gamePadCapabilities.IsConnected            = controller.IsConnected;
            gamePadCapabilities.HasVoiceSupport        = capabilities.Flags.HasFlag((Enum)CapabilityFlags.VoiceSupported);
            return(gamePadCapabilities);
        }
Ejemplo n.º 9
0
 public void Update(GamepadButtonFlags flags)
 {
     IsDown = flags.HasFlag(SharpDXButton);
 }
Ejemplo n.º 10
0
        /// <summary>
        /// Handler stavu gamepadu
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void gamepadHandle(object sender, EventArgs e)
        {
            if (enabled)
            {
                try {
                    State stateNow             = gamepad.GetState();
                    GamepadButtonFlags buttons = stateNow.Gamepad.Buttons;

                    if (state.moveDown != buttons.HasFlag(GamepadButtonFlags.Y) && buttonMoveDownObserver != null)
                    {
                        buttonMoveDownObserver(buttons.HasFlag(GamepadButtonFlags.Y));
                        state.moveDown = buttons.HasFlag(GamepadButtonFlags.Y);
                    }

                    if (state.moveUp != buttons.HasFlag(GamepadButtonFlags.A) && buttonMoveUpObserver != null)
                    {
                        buttonMoveUpObserver(buttons.HasFlag(GamepadButtonFlags.A));
                        state.moveUp = buttons.HasFlag(GamepadButtonFlags.A);
                    }

                    if (state.narrow != buttons.HasFlag(GamepadButtonFlags.X) && buttonNarrowObserver != null)
                    {
                        buttonNarrowObserver(buttons.HasFlag(GamepadButtonFlags.X));
                        state.narrow = buttons.HasFlag(GamepadButtonFlags.X);
                    }

                    if (state.widen != buttons.HasFlag(GamepadButtonFlags.B) && buttonWidenObserver != null)
                    {
                        buttonWidenObserver(buttons.HasFlag(GamepadButtonFlags.B));
                        state.widen = buttons.HasFlag(GamepadButtonFlags.B);
                    }

                    if (state.defaultPosition != buttons.HasFlag(GamepadButtonFlags.Start) && buttonDefaultPositionObserver != null)
                    {
                        buttonDefaultPositionObserver(buttons.HasFlag(GamepadButtonFlags.Start));
                        state.defaultPosition = buttons.HasFlag(GamepadButtonFlags.Start);
                    }

                    if (state.rotateRight != buttons.HasFlag(GamepadButtonFlags.RightShoulder) && buttonRotateRightObserver != null)
                    {
                        buttonRotateRightObserver(buttons.HasFlag(GamepadButtonFlags.RightShoulder));
                        state.rotateRight = buttons.HasFlag(GamepadButtonFlags.RightShoulder);
                    }

                    if (state.rotateLeft != buttons.HasFlag(GamepadButtonFlags.LeftShoulder) && buttonRotateLeftObserver != null)
                    {
                        buttonRotateLeftObserver(buttons.HasFlag(GamepadButtonFlags.LeftShoulder));
                        state.rotateLeft = buttons.HasFlag(GamepadButtonFlags.LeftShoulder);
                    }

                    if (state.stop != buttons.HasFlag(GamepadButtonFlags.Back) && buttonStopObserver != null)
                    {
                        buttonStopObserver(buttons.HasFlag(GamepadButtonFlags.Back));
                        state.stop = buttons.HasFlag(GamepadButtonFlags.Back);
                    }

                    if (state.tiltFront != buttons.HasFlag(GamepadButtonFlags.DPadUp) && buttonTiltFrontObserver != null)
                    {
                        buttonTiltFrontObserver(buttons.HasFlag(GamepadButtonFlags.DPadUp));
                        state.tiltFront = buttons.HasFlag(GamepadButtonFlags.DPadUp);
                    }

                    if (state.tiltBack != buttons.HasFlag(GamepadButtonFlags.DPadDown) && buttonTiltBackObserver != null)
                    {
                        buttonTiltBackObserver(buttons.HasFlag(GamepadButtonFlags.DPadDown));
                        state.tiltBack = buttons.HasFlag(GamepadButtonFlags.DPadDown);
                    }

                    if (state.tiltLeft != buttons.HasFlag(GamepadButtonFlags.DPadLeft) && buttonTiltLeftObserver != null)
                    {
                        buttonTiltLeftObserver(buttons.HasFlag(GamepadButtonFlags.DPadLeft));
                        state.tiltLeft = buttons.HasFlag(GamepadButtonFlags.DPadLeft);
                    }

                    if (state.tiltRight != buttons.HasFlag(GamepadButtonFlags.DPadRight) && buttonTiltRightObserver != null)
                    {
                        buttonTiltRightObserver(buttons.HasFlag(GamepadButtonFlags.DPadRight));
                        state.tiltRight = buttons.HasFlag(GamepadButtonFlags.DPadRight);
                    }

                    if ((Math.Abs(state.stickDirectMoveX - stateNow.Gamepad.LeftThumbX) > sensitivityJoystick || Math.Abs(state.stickDirectMoveY - stateNow.Gamepad.LeftThumbY) > sensitivityJoystick) && stickDirectMoveObserver != null)
                    {
                        state.stickDirectMoveX = stateNow.Gamepad.LeftThumbX;
                        state.stickDirectMoveY = stateNow.Gamepad.LeftThumbY;
                        int x = MathLibrary.changeScale(state.stickDirectMoveX, -32768, 32767, -100, 100);
                        int y = MathLibrary.changeScale(state.stickDirectMoveY, 32767, -32768, -100, 100);
                        if (Math.Abs(x) < sensitivityJoystick && Math.Abs(y) < sensitivityJoystick)
                        {
                            x = 0;
                            y = 0;
                        }
                        stickDirectMoveObserver(x, y);
                    }

                    if ((Math.Abs(state.stickMoveX - stateNow.Gamepad.RightThumbX) > sensitivityJoystick || Math.Abs(state.stickMoveY - stateNow.Gamepad.RightThumbY) > sensitivityJoystick) && stickMoveObserver != null)
                    {
                        state.stickMoveX = stateNow.Gamepad.RightThumbX;
                        state.stickMoveY = stateNow.Gamepad.RightThumbY;
                        int x = MathLibrary.changeScale(state.stickMoveX, -32768, 32767, -100, 100);
                        int y = MathLibrary.changeScale(state.stickMoveY, 32767, -32768, -100, 100);
                        if (Math.Abs(x) < sensitivityJoystick && Math.Abs(y) < sensitivityJoystick)
                        {
                            x = 0;
                            y = 0;
                        }
                        stickMoveObserver(x, y);
                    }

                    if ((Math.Abs(state.frontNarrow - stateNow.Gamepad.LeftTrigger) > sensitivityAnalogButtons) && frontNarrowObserver != null)
                    {
                        state.frontNarrow = stateNow.Gamepad.LeftTrigger;
                        int frontNarrow = MathLibrary.changeScale(state.frontNarrow, 0, 255, 0, 100);
                        if (state.frontNarrow < sensitivityAnalogButtons)
                        {
                            frontNarrow = 0;
                        }
                        frontNarrowObserver(frontNarrow);
                    }

                    if ((Math.Abs(state.backNarrow - stateNow.Gamepad.RightTrigger) > sensitivityAnalogButtons) && backNarrowObserver != null)
                    {
                        state.backNarrow = stateNow.Gamepad.RightTrigger;
                        int backNarrow = MathLibrary.changeScale(state.backNarrow, 0, 255, 0, 100);
                        if (state.backNarrow < sensitivityAnalogButtons)
                        {
                            backNarrow = 0;
                        }
                        backNarrowObserver(backNarrow);
                    }
                }
                catch (XInputException)
                {
                    periodicChecker.Dispose();
                    errorObserver();
                }
            }
        }
Ejemplo n.º 11
0
 private static ButtonState ConvertToButtonState(GamepadButtonFlags buttonFlags, GamepadButtonFlags desiredButton)
 {
   return buttonFlags.HasFlag((Enum) desiredButton) ? ButtonState.Pressed : ButtonState.Released;
 }
Ejemplo n.º 12
0
        void TimerTick(object sender, EventArgs e)
        {
            //DisplayControllerInformation();

            var state = gameController.GetState();

            //Console.WriteLine("LEFT THUMB X:{0}, Y:{1}", state.Gamepad.LeftThumbX, state.Gamepad.LeftThumbY);
            //Console.WriteLine("RIGHT THUMB X:{0}, Y:{1}", state.Gamepad.RightThumbX, state.Gamepad.RightThumbY);
            //Console.WriteLine("TRIGGGERS LEFT:{0}, RIGHT:{1}", state.Gamepad.LeftTrigger, state.Gamepad.RightTrigger);
            //Console.WriteLine("BUTTONS: " + state.Gamepad.Buttons);

            // Can't really test this right now, my controller's thumb is broken... XD
            //BRobot.Point dir = new BRobot.Point(
            //    RemapThumb(state.Gamepad.LeftThumbX, 10000, 32767),
            //    RemapThumb(state.Gamepad.LeftThumbY, 10000, 32767),
            //    RemapThumb(state.Gamepad.RightThumbY, 10000, 32767)
            //);
            //dir.Scale(relSpeed);

            //var speed = dir.Length();
            //if (speed > 0)
            //{
            //    Console.WriteLine("--> Moving {0}", dir);
            //    arm.SetVelocity(speed);
            //    arm.Move(dir);
            //}
            //else
            //{
            //    Console.WriteLine("idle");
            //}

            // A really simple and fast implementation to create a direction vector
            // for the next issued movement based on button pressed states.
            // This queues a ton of Frames on the robot, would be much better
            // implemented when the queue raises events demanding new targets.
            // Directions are assuming a human controller facing the robot frontally.

            Rot r = new Rot();
            GamepadButtonFlags buttons = state.Gamepad.Buttons;

            //// Create direction vector based on buttons
            //if (buttons.HasFlag(GamepadButtonFlags.DPadRight))
            //    dir.Y = 1;
            //else if (buttons.HasFlag(GamepadButtonFlags.DPadLeft))
            //    dir.Y = -1;
            //else
            //    dir.Y = 0;

            //if (buttons.HasFlag(GamepadButtonFlags.DPadUp))
            //    dir.X = 1;
            //else if (buttons.HasFlag(GamepadButtonFlags.DPadDown))
            //    dir.X = -1;
            //else
            //    dir.X = 0;

            //if (buttons.HasFlag(GamepadButtonFlags.Y))
            //    dir.Z = 1;
            //else if (buttons.HasFlag(GamepadButtonFlags.A))
            //    dir.Z = -1;
            //else
            //    dir.Z = 0;

            if (buttons.HasFlag(GamepadButtonFlags.Back))
            {
                firstPersonMode = !firstPersonMode;
                if (firstPersonMode)
                {
                    arm.Coordinates("local");
                }
                else
                {
                    arm.Coordinates("global");
                }
                Console.WriteLine("COordinatesMode: " + arm.Coordinates());
            }

            if (buttons.HasFlag(GamepadButtonFlags.Start))
            {
                DebugStates();
            }

            dir.X = NormalizeThumb(state.Gamepad.LeftThumbY, 10000, 32767);
            dir.Y = NormalizeThumb(state.Gamepad.LeftThumbX, 10000, 32767);
            dir.Z = NormalizeThumb(state.Gamepad.LeftTrigger, 25, 255) - NormalizeThumb(state.Gamepad.RightTrigger, 25, 255);

            double rotZ = NormalizeThumb(state.Gamepad.RightThumbX, 10000, 32767);

            r = new Rot(Vec.ZAxis, 0.5 * incDist * rotZ);
            double rotY = NormalizeThumb(state.Gamepad.RightThumbY, 10000, 32767);

            r.Multiply(new Rot(Vec.YAxis, -0.5 * incDist * rotY));
            // Issue a move command to the robot accordingly (or not)
            if (dir.Length() > 0)
            {
                //dir.Normalize();
                dir.Scale(incDist);

                Console.WriteLine("  --> Moving and rotating {0} {1}", dir, r);
                //arm.Transform(r, dir);
                arm.Move(dir);
            }
            else if (r.W < 1)
            {
                Console.WriteLine("  --> Rotating {0}", r);
                arm.Rotate(r);
            }
            else
            {
                //Console.WriteLine("Idle...");
            }
        }
Ejemplo n.º 13
0
 public bool this[GamepadButtonFlags flags, bool once = false] => _buttonFlags.HasFlag(flags) && !(once && _lastButtonFlags.HasFlag(flags));
Ejemplo n.º 14
0
 public bool GetDPadLeftButton(GamepadButtonFlags flags)
 {
     if (flags.HasFlag(GamepadButtonFlags.DPadLeft))
     {
         return true;
     }
     return false;
 }
Ejemplo n.º 15
0
 public bool GetRightThumbDownButton(GamepadButtonFlags flags)
 {
     if (flags.HasFlag(GamepadButtonFlags.RightThumb))
     {
         return true;
     }
     return false;
 }
Ejemplo n.º 16
0
 public bool GetRightShoulderButton(GamepadButtonFlags flags)
 {
     if (flags.HasFlag(GamepadButtonFlags.RightShoulder)) {
         return true;
     }
     return false;
 }