コード例 #1
0
 public GamePadState(bool isConnected, uint packet, GamePadButtons buttons, GamePadDPad dpad, GamePadThumbSticks sticks, GamePadTriggers triggers)
 {
     this.isConnected  = isConnected;
     this.buttons      = buttons;
     this.thumbSticks  = sticks;
     this.triggers     = triggers;
     this.dPad         = dpad;
     this.packetNumber = packet;
 }
コード例 #2
0
ファイル: GamePad.cs プロジェクト: ErikUggeldahl/GGJ15
        internal GamePadState(bool isConnected, RawState rawState, GamePadDeadZone deadZone)
        {
            this.isConnected = isConnected;

            if (!isConnected)
            {
                rawState.dwPacketNumber        = 0;
                rawState.Gamepad.dwButtons     = 0;
                rawState.Gamepad.bLeftTrigger  = 0;
                rawState.Gamepad.bRightTrigger = 0;
                rawState.Gamepad.sThumbLX      = 0;
                rawState.Gamepad.sThumbLY      = 0;
                rawState.Gamepad.sThumbRX      = 0;
                rawState.Gamepad.sThumbRY      = 0;
            }

            packetNumber = rawState.dwPacketNumber;
            buttons      = new GamePadButtons(
                (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.Start) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.Back) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.LeftThumb) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.RightThumb) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.LeftShoulder) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.RightShoulder) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.A) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.B) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.X) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.Y) != 0 ? ButtonState.Pressed : ButtonState.Released
                );
            dPad = new GamePadDPad(
                (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.DPadUp) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.DPadDown) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.DPadLeft) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.DPadRight) != 0 ? ButtonState.Pressed : ButtonState.Released
                );

            switch (deadZone)
            {
            case GamePadDeadZone.IndependentAxes:
                rawState.Gamepad.sThumbLX = ThumbStickDeadZoneIndependantAxes(rawState.Gamepad.sThumbLX, (short)Imports.Constants.LeftStickDeadZone);
                rawState.Gamepad.sThumbLY = ThumbStickDeadZoneIndependantAxes(rawState.Gamepad.sThumbLY, (short)Imports.Constants.LeftStickDeadZone);
                rawState.Gamepad.sThumbRX = ThumbStickDeadZoneIndependantAxes(rawState.Gamepad.sThumbRX, (short)Imports.Constants.RightStickDeadZone);
                rawState.Gamepad.sThumbRY = ThumbStickDeadZoneIndependantAxes(rawState.Gamepad.sThumbRY, (short)Imports.Constants.RightStickDeadZone);
                break;
            }

            thumbSticks = new GamePadThumbSticks(
                new GamePadThumbSticks.StickValue(
                    rawState.Gamepad.sThumbLX < 0 ? rawState.Gamepad.sThumbLX / 32768.0f : rawState.Gamepad.sThumbLX / 32767.0f,
                    rawState.Gamepad.sThumbLY < 0 ? rawState.Gamepad.sThumbLY / 32768.0f : rawState.Gamepad.sThumbLY / 32767.0f),
                new GamePadThumbSticks.StickValue(
                    rawState.Gamepad.sThumbRX < 0 ? rawState.Gamepad.sThumbRX / 32768.0f : rawState.Gamepad.sThumbRX / 32767.0f,
                    rawState.Gamepad.sThumbRY < 0 ? rawState.Gamepad.sThumbRY / 32768.0f : rawState.Gamepad.sThumbRY / 32767.0f)
                );
            triggers = new GamePadTriggers(rawState.Gamepad.bLeftTrigger / 255.0f, rawState.Gamepad.bRightTrigger / 255.0f);
        }
コード例 #3
0
ファイル: GamePad.cs プロジェクト: VividCoder/SpaceRPG
        internal GamePadState(bool isConnected, RawState rawState, GamePadDeadZone deadZone)
        {
            this.isConnected = isConnected;

            if (!isConnected)
            {
                rawState.dwPacketNumber        = 0;
                rawState.Gamepad.wButtons      = 0;
                rawState.Gamepad.bLeftTrigger  = 0;
                rawState.Gamepad.bRightTrigger = 0;
                rawState.Gamepad.sThumbLX      = 0;
                rawState.Gamepad.sThumbLY      = 0;
                rawState.Gamepad.sThumbRX      = 0;
                rawState.Gamepad.sThumbRY      = 0;
            }

            packetNumber = rawState.dwPacketNumber;
            buttons      = new GamePadButtons(
                (rawState.Gamepad.wButtons & (uint)ButtonsConstants.Start) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.wButtons & (uint)ButtonsConstants.Back) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.wButtons & (uint)ButtonsConstants.LeftThumb) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.wButtons & (uint)ButtonsConstants.RightThumb) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.wButtons & (uint)ButtonsConstants.LeftShoulder) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.wButtons & (uint)ButtonsConstants.RightShoulder) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.wButtons & (uint)ButtonsConstants.Guide) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.wButtons & (uint)ButtonsConstants.A) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.wButtons & (uint)ButtonsConstants.B) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.wButtons & (uint)ButtonsConstants.X) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.wButtons & (uint)ButtonsConstants.Y) != 0 ? ButtonState.Pressed : ButtonState.Released
                );
            dPad = new GamePadDPad(
                (rawState.Gamepad.wButtons & (uint)ButtonsConstants.DPadUp) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.wButtons & (uint)ButtonsConstants.DPadDown) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.wButtons & (uint)ButtonsConstants.DPadLeft) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.wButtons & (uint)ButtonsConstants.DPadRight) != 0 ? ButtonState.Pressed : ButtonState.Released
                );

            thumbSticks = new GamePadThumbSticks(
                Utils.ApplyLeftStickDeadZone(rawState.Gamepad.sThumbLX, rawState.Gamepad.sThumbLY, deadZone),
                Utils.ApplyRightStickDeadZone(rawState.Gamepad.sThumbRX, rawState.Gamepad.sThumbRY, deadZone)
                );
            triggers = new GamePadTriggers(
                Utils.ApplyTriggerDeadZone(rawState.Gamepad.bLeftTrigger, deadZone),
                Utils.ApplyTriggerDeadZone(rawState.Gamepad.bRightTrigger, deadZone)
                );
        }
コード例 #4
0
        internal GamePadState(bool isConnected, RawState rawState)
        {
            this.isConnected = isConnected;

            if (!isConnected)
            {
                rawState.dwPacketNumber        = 0;
                rawState.Gamepad.dwButtons     = 0;
                rawState.Gamepad.bLeftTrigger  = 0;
                rawState.Gamepad.bRightTrigger = 0;
                rawState.Gamepad.sThumbLX      = 0;
                rawState.Gamepad.sThumbLY      = 0;
                rawState.Gamepad.sThumbRX      = 0;
                rawState.Gamepad.sThumbRY      = 0;
            }

            packetNumber = rawState.dwPacketNumber;
            buttons      = new GamePadButtons(
                (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.Start) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.Back) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.LeftThumb) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.RightThumb) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.LeftShoulder) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.RightShoulder) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.A) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.B) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.X) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.Y) != 0 ? ButtonState.Pressed : ButtonState.Released
                );
            dPad = new GamePadDPad(
                (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.DPadUp) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.DPadDown) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.DPadLeft) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.dwButtons & (uint)ButtonsConstants.DPadRight) != 0 ? ButtonState.Pressed : ButtonState.Released
                );

            thumbSticks = new GamePadThumbSticks(
                new GamePadThumbSticks.StickValue(rawState.Gamepad.sThumbLX / (float)short.MaxValue, rawState.Gamepad.sThumbLY / (float)short.MaxValue),
                new GamePadThumbSticks.StickValue(rawState.Gamepad.sThumbRX / (float)short.MaxValue, rawState.Gamepad.sThumbRY / (float)short.MaxValue)
                );

            triggers = new GamePadTriggers(rawState.Gamepad.bLeftTrigger / (float)byte.MaxValue, rawState.Gamepad.bRightTrigger / (float)byte.MaxValue);
        }
コード例 #5
0
ファイル: GamePad.cs プロジェクト: TrinketBen/Courier
		internal GamePadState( bool isConnected, RawState rawState )
		{
			this.isConnected = isConnected;

			if (!isConnected)
			{
				rawState.dwPacketNumber = 0;
				rawState.Gamepad.dwButtons = 0;
				rawState.Gamepad.bLeftTrigger = 0;
				rawState.Gamepad.bRightTrigger = 0;
				rawState.Gamepad.sThumbLX = 0;
				rawState.Gamepad.sThumbLY = 0;
				rawState.Gamepad.sThumbRX = 0;
				rawState.Gamepad.sThumbRY = 0;
			}

			packetNumber = rawState.dwPacketNumber;
			buttons = new GamePadButtons(
				(rawState.Gamepad.dwButtons & (uint) ButtonsConstants.Start) != 0 ? ButtonState.Pressed : ButtonState.Released,
				(rawState.Gamepad.dwButtons & (uint) ButtonsConstants.Back) != 0 ? ButtonState.Pressed : ButtonState.Released,
				(rawState.Gamepad.dwButtons & (uint) ButtonsConstants.LeftThumb) != 0 ? ButtonState.Pressed : ButtonState.Released,
				(rawState.Gamepad.dwButtons & (uint) ButtonsConstants.RightThumb) != 0 ? ButtonState.Pressed : ButtonState.Released,
				(rawState.Gamepad.dwButtons & (uint) ButtonsConstants.LeftShoulder) != 0 ? ButtonState.Pressed : ButtonState.Released,
				(rawState.Gamepad.dwButtons & (uint) ButtonsConstants.RightShoulder) != 0 ? ButtonState.Pressed : ButtonState.Released,
				(rawState.Gamepad.dwButtons & (uint) ButtonsConstants.A) != 0 ? ButtonState.Pressed : ButtonState.Released,
				(rawState.Gamepad.dwButtons & (uint) ButtonsConstants.B) != 0 ? ButtonState.Pressed : ButtonState.Released,
				(rawState.Gamepad.dwButtons & (uint) ButtonsConstants.X) != 0 ? ButtonState.Pressed : ButtonState.Released,
				(rawState.Gamepad.dwButtons & (uint) ButtonsConstants.Y) != 0 ? ButtonState.Pressed : ButtonState.Released
			);
			dPad = new GamePadDPad(
				(rawState.Gamepad.dwButtons & (uint) ButtonsConstants.DPadUp) != 0 ? ButtonState.Pressed : ButtonState.Released,
				(rawState.Gamepad.dwButtons & (uint) ButtonsConstants.DPadDown) != 0 ? ButtonState.Pressed : ButtonState.Released,
				(rawState.Gamepad.dwButtons & (uint) ButtonsConstants.DPadLeft) != 0 ? ButtonState.Pressed : ButtonState.Released,
				(rawState.Gamepad.dwButtons & (uint) ButtonsConstants.DPadRight) != 0 ? ButtonState.Pressed : ButtonState.Released
			);

			thumbSticks = new GamePadThumbSticks(
				new GamePadThumbSticks.StickValue( rawState.Gamepad.sThumbLX / (float) short.MaxValue, rawState.Gamepad.sThumbLY / (float) short.MaxValue ),
				new GamePadThumbSticks.StickValue( rawState.Gamepad.sThumbRX / (float) short.MaxValue, rawState.Gamepad.sThumbRY / (float) short.MaxValue )
			);

			triggers = new GamePadTriggers( rawState.Gamepad.bLeftTrigger / (float) byte.MaxValue, rawState.Gamepad.bRightTrigger / (float) byte.MaxValue );
		}
コード例 #6
0
		private static float XInputGetAxisState(GamePadTriggers xiTriggers, XboxAxis xciAxis)
		{
			float stateToReturn = 0.0f;
			
			switch(xciAxis)
			{
				case XboxAxis.LeftTrigger: 		stateToReturn = xiTriggers.Left; break;
				case XboxAxis.RightTrigger: 	stateToReturn = xiTriggers.Right; break;
				default:						stateToReturn = 0.0f; break;
			}
			
			return stateToReturn;
		}
コード例 #7
0
ファイル: GamePad.cs プロジェクト: ChrisCrossed/CodeExamples
        internal GamePadState(bool isConnected, RawState rawState, GamePadDeadZone deadZone)
        {
            this.isConnected = isConnected;

            if (!isConnected)
            {
                rawState.dwPacketNumber = 0;
                rawState.Gamepad.wButtons = 0;
                rawState.Gamepad.bLeftTrigger = 0;
                rawState.Gamepad.bRightTrigger = 0;
                rawState.Gamepad.sThumbLX = 0;
                rawState.Gamepad.sThumbLY = 0;
                rawState.Gamepad.sThumbRX = 0;
                rawState.Gamepad.sThumbRY = 0;
            }

            packetNumber = rawState.dwPacketNumber;
            buttons = new GamePadButtons(
                (rawState.Gamepad.wButtons & (uint)ButtonsConstants.Start) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.wButtons & (uint)ButtonsConstants.Back) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.wButtons & (uint)ButtonsConstants.LeftThumb) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.wButtons & (uint)ButtonsConstants.RightThumb) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.wButtons & (uint)ButtonsConstants.LeftShoulder) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.wButtons & (uint)ButtonsConstants.RightShoulder) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.wButtons & (uint)ButtonsConstants.Guide) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.wButtons & (uint)ButtonsConstants.A) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.wButtons & (uint)ButtonsConstants.B) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.wButtons & (uint)ButtonsConstants.X) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.wButtons & (uint)ButtonsConstants.Y) != 0 ? ButtonState.Pressed : ButtonState.Released
            );
            dPad = new GamePadDPad(
                (rawState.Gamepad.wButtons & (uint)ButtonsConstants.DPadUp) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.wButtons & (uint)ButtonsConstants.DPadDown) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.wButtons & (uint)ButtonsConstants.DPadLeft) != 0 ? ButtonState.Pressed : ButtonState.Released,
                (rawState.Gamepad.wButtons & (uint)ButtonsConstants.DPadRight) != 0 ? ButtonState.Pressed : ButtonState.Released
            );

            thumbSticks = new GamePadThumbSticks(
                Utils.ApplyLeftStickDeadZone(rawState.Gamepad.sThumbLX, rawState.Gamepad.sThumbLY, deadZone),
                Utils.ApplyRightStickDeadZone(rawState.Gamepad.sThumbRX, rawState.Gamepad.sThumbRY, deadZone)
            );
            triggers = new GamePadTriggers(
                Utils.ApplyTriggerDeadZone(rawState.Gamepad.bLeftTrigger, deadZone),
                Utils.ApplyTriggerDeadZone(rawState.Gamepad.bRightTrigger, deadZone)
            );
        }