public void LoadState() { // Get the slimdx game pad state SlimDX.XInput.Gamepad state = controller.GetState().Gamepad; // Updated button values A = ((state.Buttons & GamepadButtonFlags.A) == GamepadButtonFlags.A); B = ((state.Buttons & GamepadButtonFlags.B) == GamepadButtonFlags.B); X = ((state.Buttons & GamepadButtonFlags.X) == GamepadButtonFlags.X); Y = ((state.Buttons & GamepadButtonFlags.Y) == GamepadButtonFlags.Y); Start = ((state.Buttons & GamepadButtonFlags.Start) == GamepadButtonFlags.Start); Back = ((state.Buttons & GamepadButtonFlags.Back) == GamepadButtonFlags.Back); DPad.Up = ((state.Buttons & GamepadButtonFlags.DPadUp) == GamepadButtonFlags.DPadUp); DPad.Down = ((state.Buttons & GamepadButtonFlags.DPadDown) == GamepadButtonFlags.DPadDown); DPad.Left = ((state.Buttons & GamepadButtonFlags.DPadLeft) == GamepadButtonFlags.DPadLeft); DPad.Right = ((state.Buttons & GamepadButtonFlags.DPadRight) == GamepadButtonFlags.DPadRight); LeftBumper = ((state.Buttons & GamepadButtonFlags.LeftShoulder) == GamepadButtonFlags.LeftShoulder); RightBumper = ((state.Buttons & GamepadButtonFlags.RightShoulder) == GamepadButtonFlags.RightShoulder); // Update trigger values if (state.LeftTrigger > SlimDX.XInput.Gamepad.GamepadTriggerThreshold) { LeftTrigger = state.LeftTrigger / 255.0; } else { LeftTrigger = 0; } if (state.RightTrigger > SlimDX.XInput.Gamepad.GamepadTriggerThreshold) { RightTrigger = state.RightTrigger / 255.0; } else { RightTrigger = 0; } // Update thumbstick values Thumbsticks.Left.Click = ((state.Buttons & GamepadButtonFlags.LeftThumb) == GamepadButtonFlags.LeftThumb); Thumbsticks.Right.Click = ((state.Buttons & GamepadButtonFlags.RightThumb) == GamepadButtonFlags.RightThumb); Vector2 leftStick = new Vector2(state.LeftThumbX, state.LeftThumbY).Normalize( SlimDX.XInput.Gamepad.GamepadLeftThumbDeadZone); Vector2 rightStick = new Vector2(state.RightThumbX, state.RightThumbY).Normalize(SlimDX.XInput.Gamepad .GamepadRightThumbDeadZone); Thumbsticks.Left.X = leftStick.X; Thumbsticks.Left.Y = leftStick.Y; Thumbsticks.Right.X = rightStick.X; Thumbsticks.Right.Y = rightStick.Y; }
////////////////////////////////////////////////////////////////////// // ////////////////////////////////////////////////////////////////////// private int getGamepadInput(Xbox360Controller.Gamepad360 g) { SlimDX.XInput.Gamepad gamepadState = g.Controller.GetState().Gamepad; // Shoulders if ((gamepadState.Buttons & GamepadButtonFlags.LeftShoulder) != 0) { return((int)GamepadButtonFlags.LeftShoulder); } if ((gamepadState.Buttons & GamepadButtonFlags.RightShoulder) != 0) { return((int)GamepadButtonFlags.LeftShoulder); } // Buttons if ((gamepadState.Buttons & GamepadButtonFlags.Start) != 0) { return((int)GamepadButtonFlags.Start); } if ((gamepadState.Buttons & GamepadButtonFlags.Back) != 0) { return((int)GamepadButtonFlags.Back); } if ((gamepadState.Buttons & GamepadButtonFlags.A) != 0) { return((int)GamepadButtonFlags.A); } if ((gamepadState.Buttons & GamepadButtonFlags.B) != 0) { return((int)GamepadButtonFlags.B); } if ((gamepadState.Buttons & GamepadButtonFlags.X) != 0) { return((int)GamepadButtonFlags.X); } if ((gamepadState.Buttons & GamepadButtonFlags.Y) != 0) { return((int)GamepadButtonFlags.Y); } // D-Pad if ((gamepadState.Buttons & GamepadButtonFlags.DPadUp) != 0) { return((int)GamepadButtonFlags.DPadUp); } if ((gamepadState.Buttons & GamepadButtonFlags.DPadDown) != 0) { return((int)GamepadButtonFlags.DPadDown); } if ((gamepadState.Buttons & GamepadButtonFlags.DPadLeft) != 0) { return((int)GamepadButtonFlags.DPadLeft); } if ((gamepadState.Buttons & GamepadButtonFlags.DPadRight) != 0) { return((int)GamepadButtonFlags.DPadRight); } return(0); /* * // Thumbsticks * LeftStick = new ThumbstickState( * Normalize(gamepadState.LeftThumbX, gamepadState.LeftThumbY, Gamepad.GamepadLeftThumbDeadZone), * (gamepadState.Buttons & GamepadButtonFlags.LeftThumb) != 0); * RightStick = new ThumbstickState( * Normalize(gamepadState.RightThumbX, gamepadState.RightThumbY, Gamepad.GamepadRightThumbDeadZone), * (gamepadState.Buttons & GamepadButtonFlags.RightThumb) != 0); * // Triggers * if (gamepadState.LeftTrigger / (float)byte.MaxValue != 0.0 ) * { * return (int)-1; * } * if (gamepadState.RightTrigger / (float)byte.MaxValue != 0.0 ) * { * return (int)-1; * } * */ }