public void CanConvertBetweeenDirectionalPadAndPov( int pov, bool up, bool down, bool left, bool right ) { GamePadDPad dpad = new GamePadDPad( up ? ButtonState.Pressed : ButtonState.Released, down ? ButtonState.Pressed : ButtonState.Released, left ? ButtonState.Pressed : ButtonState.Released, right ? ButtonState.Pressed : ButtonState.Released ); Assert.AreEqual(pov, ExtendedGamePadState.PovFromDpad(dpad)); Assert.AreEqual(dpad, ExtendedGamePadState.DpadFromPov(pov)); }
/// <summary> /// Initializes a new extended game pad state from a standard game pad state /// </summary> /// <param name="gamePadState"> /// Standard game pad state the extended game pad state is initialized from /// </param> public ExtendedGamePadState(ref GamePadState gamePadState) { // Axes { this.AvailableAxes = ExtendedAxes.X | ExtendedAxes.Y | ExtendedAxes.RotationX | ExtendedAxes.RotationY; this.X = gamePadState.ThumbSticks.Left.X; this.Y = gamePadState.ThumbSticks.Left.Y; this.Z = 0.0f; this.VelocityX = this.VelocityY = this.VelocityZ = 0.0f; this.AccelerationX = this.AccelerationY = this.AccelerationZ = 0.0f; this.ForceX = this.ForceY = this.ForceZ = 0.0f; this.RotationX = gamePadState.ThumbSticks.Right.X; this.RotationY = gamePadState.ThumbSticks.Right.Y; this.RotationZ = 0.0f; this.AngularVelocityX = this.AngularVelocityY = this.AngularVelocityZ = 0.0f; this.AngularAccelerationX = 0.0f; this.AngularAccelerationY = 0.0f; this.AngularAccelerationZ = 0.0f; this.TorqueX = this.TorqueY = this.TorqueZ = 0.0f; } // Buttons { this.ButtonCount = 11; this.buttonState1 = (gamePadState.IsButtonDown(Buttons.A) ? 1UL : 0UL) | (gamePadState.IsButtonDown(Buttons.B) ? 2UL : 0UL) | (gamePadState.IsButtonDown(Buttons.X) ? 4UL : 0UL) | (gamePadState.IsButtonDown(Buttons.Y) ? 8UL : 0UL) | (gamePadState.IsButtonDown(Buttons.LeftShoulder) ? 16UL : 0UL) | (gamePadState.IsButtonDown(Buttons.RightShoulder) ? 32UL : 0UL) | (gamePadState.IsButtonDown(Buttons.Back) ? 64UL : 0UL) | (gamePadState.IsButtonDown(Buttons.Start) ? 128UL : 0UL) | (gamePadState.IsButtonDown(Buttons.LeftStick) ? 256UL : 0UL) | (gamePadState.IsButtonDown(Buttons.RightStick) ? 512UL : 0UL) | (gamePadState.IsButtonDown(Buttons.BigButton) ? 1024UL : 0UL); this.buttonState2 = 0; } // Sliders { this.AvailableSliders = ExtendedSliders.Slider1 | ExtendedSliders.Slider2; this.Slider1 = gamePadState.Triggers.Left; this.Slider2 = gamePadState.Triggers.Right; this.VelocitySlider1 = this.VelocitySlider2 = 0.0f; this.AccelerationSlider1 = this.AccelerationSlider2 = 0.0f; this.ForceSlider1 = this.ForceSlider2 = 0.0f; } // PoVs { this.PovCount = 1; this.Pov1 = ExtendedGamePadState.PovFromDpad(gamePadState.DPad); this.Pov2 = -1; this.Pov3 = -1; this.Pov4 = -1; } }
/// <summary>Updates the state of all buttons in the mask</summary> /// <param name="buttonMask">Mask of buttons that will be updated</param> /// <param name="state">New state the buttons will assume</param> private void updateButtonStates(Buttons buttonMask, bool state) { if ((buttonMask & Buttons.A) == Buttons.A) { enforceButtonCountAtLeast(1); this.buttonStates[0] = state; } if ((buttonMask & Buttons.B) == Buttons.B) { enforceButtonCountAtLeast(2); this.buttonStates[1] = state; } if ((buttonMask & Buttons.X) == Buttons.X) { enforceButtonCountAtLeast(3); this.buttonStates[2] = state; } if ((buttonMask & Buttons.Y) == Buttons.Y) { enforceButtonCountAtLeast(4); this.buttonStates[3] = state; } if ((buttonMask & Buttons.LeftShoulder) == Buttons.LeftShoulder) { enforceButtonCountAtLeast(5); this.buttonStates[4] = state; } if ((buttonMask & Buttons.RightShoulder) == Buttons.RightShoulder) { enforceButtonCountAtLeast(6); this.buttonStates[5] = state; } if ((buttonMask & Buttons.Back) == Buttons.Back) { enforceButtonCountAtLeast(7); this.buttonStates[6] = state; } if ((buttonMask & Buttons.Start) == Buttons.Start) { enforceButtonCountAtLeast(8); this.buttonStates[7] = state; } if ((buttonMask & Buttons.LeftStick) == Buttons.LeftStick) { enforceButtonCountAtLeast(9); this.buttonStates[8] = state; } if ((buttonMask & Buttons.RightStick) == Buttons.RightStick) { enforceButtonCountAtLeast(10); this.buttonStates[9] = state; } if ((buttonMask & Buttons.BigButton) == Buttons.BigButton) { enforceButtonCountAtLeast(11); this.buttonStates[10] = state; } if ((buttonMask & Buttons.DPadUp) == Buttons.DPadUp) { GamePadDPad dpad = ExtendedGamePadState.DpadFromPov(this.povStates[0]); this.povStates[0] = ExtendedGamePadState.PovFromDpad( new GamePadDPad(ButtonState.Pressed, dpad.Down, dpad.Left, dpad.Right) ); } if ((buttonMask & Buttons.DPadDown) == Buttons.DPadDown) { GamePadDPad dpad = ExtendedGamePadState.DpadFromPov(this.povStates[0]); this.povStates[0] = ExtendedGamePadState.PovFromDpad( new GamePadDPad(dpad.Up, ButtonState.Pressed, dpad.Left, dpad.Right) ); } if ((buttonMask & Buttons.DPadLeft) == Buttons.DPadLeft) { GamePadDPad dpad = ExtendedGamePadState.DpadFromPov(this.povStates[0]); this.povStates[0] = ExtendedGamePadState.PovFromDpad( new GamePadDPad(dpad.Up, dpad.Down, ButtonState.Pressed, dpad.Right) ); } if ((buttonMask & Buttons.DPadRight) == Buttons.DPadRight) { GamePadDPad dpad = ExtendedGamePadState.DpadFromPov(this.povStates[0]); this.povStates[0] = ExtendedGamePadState.PovFromDpad( new GamePadDPad(dpad.Up, dpad.Down, dpad.Left, ButtonState.Pressed) ); } }