本文整理汇总了C#中JoystickState.SetIsConnected方法的典型用法代码示例。如果您正苦于以下问题:C# JoystickState.SetIsConnected方法的具体用法?C# JoystickState.SetIsConnected怎么用?C# JoystickState.SetIsConnected使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JoystickState
的用法示例。
在下文中一共展示了JoystickState.SetIsConnected方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetState
public JoystickState GetState(int index)
{
XInputState xstate;
XInputErrorCode error = xinput.GetState((XInputUserIndex)index, out xstate);
JoystickState state = new JoystickState();
if (error == XInputErrorCode.Success)
{
state.SetIsConnected(true);
state.SetAxis(JoystickAxis.Axis0, (short)xstate.GamePad.ThumbLX);
state.SetAxis(JoystickAxis.Axis1, (short)Math.Min(short.MaxValue, -xstate.GamePad.ThumbLY));
state.SetAxis(JoystickAxis.Axis2, (short)Common.HidHelper.ScaleValue(xstate.GamePad.LeftTrigger, 0, byte.MaxValue, short.MinValue, short.MaxValue));
state.SetAxis(JoystickAxis.Axis3, (short)xstate.GamePad.ThumbRX);
state.SetAxis(JoystickAxis.Axis4, (short)Math.Min(short.MaxValue, -xstate.GamePad.ThumbRY));
state.SetAxis(JoystickAxis.Axis5, (short)Common.HidHelper.ScaleValue(xstate.GamePad.RightTrigger, 0, byte.MaxValue, short.MinValue, short.MaxValue));
state.SetButton(JoystickButton.Button0, (xstate.GamePad.Buttons & XInputButtons.A) != 0);
state.SetButton(JoystickButton.Button1, (xstate.GamePad.Buttons & XInputButtons.B) != 0);
state.SetButton(JoystickButton.Button2, (xstate.GamePad.Buttons & XInputButtons.X) != 0);
state.SetButton(JoystickButton.Button3, (xstate.GamePad.Buttons & XInputButtons.Y) != 0);
state.SetButton(JoystickButton.Button4, (xstate.GamePad.Buttons & XInputButtons.LeftShoulder) != 0);
state.SetButton(JoystickButton.Button5, (xstate.GamePad.Buttons & XInputButtons.RightShoulder) != 0);
state.SetButton(JoystickButton.Button6, (xstate.GamePad.Buttons & XInputButtons.Back) != 0);
state.SetButton(JoystickButton.Button7, (xstate.GamePad.Buttons & XInputButtons.Start) != 0);
state.SetButton(JoystickButton.Button8, (xstate.GamePad.Buttons & XInputButtons.LeftThumb) != 0);
state.SetButton(JoystickButton.Button9, (xstate.GamePad.Buttons & XInputButtons.RightThumb) != 0);
state.SetButton(JoystickButton.Button10, (xstate.GamePad.Buttons & XInputButtons.Guide) != 0);
state.SetHat(JoystickHat.Hat0, new JoystickHatState(TranslateHat(xstate.GamePad.Buttons)));
}
return state;
}
示例2: GetState
public JoystickState GetState(int index)
{
JoystickState state = new JoystickState();
if (IsValid(index))
{
JoyInfoEx info = new JoyInfoEx();
info.Size = JoyInfoEx.SizeInBytes;
info.Flags = JoystickFlags.All;
JoystickError result = UnsafeNativeMethods.joyGetPosEx(index, ref info);
if (result == JoystickError.NoError)
{
JoyCaps caps;
result = UnsafeNativeMethods.joyGetDevCaps(index, out caps, JoyCaps.SizeInBytes);
if (result == JoystickError.NoError)
{
state.SetAxis(JoystickAxis.Axis0, CalculateOffset(info.XPos, caps.XMin, caps.XMax));
state.SetAxis(JoystickAxis.Axis1, CalculateOffset(info.YPos, caps.YMin, caps.YMax));
state.SetAxis(JoystickAxis.Axis2, CalculateOffset(info.ZPos, caps.ZMin, caps.ZMax));
state.SetAxis(JoystickAxis.Axis3, CalculateOffset(info.RPos, caps.RMin, caps.RMax));
state.SetAxis(JoystickAxis.Axis4, CalculateOffset(info.UPos, caps.UMin, caps.UMax));
state.SetAxis(JoystickAxis.Axis5, CalculateOffset(info.VPos, caps.VMin, caps.VMax));
for (int i = 0; i < 16; i++)
{
state.SetButton(JoystickButton.Button0 + i, (info.Buttons & 1 << i) != 0);
}
state.SetIsConnected(true);
}
}
if (result == JoystickError.Unplugged)
{
UnplugJoystick(index);
}
}
else
{
Debug.Print("[Win] Invalid WinMM joystick device {0}", index);
}
return state;
}
示例3: JoystickState
JoystickState IJoystickDriver2.GetState(int index)
{
JoystickState state = new JoystickState();
if (IsJoystickValid(index))
{
JoystickDevice<Sdl2JoystickDetails> joystick =
(JoystickDevice<Sdl2JoystickDetails>)joysticks[index];
for (int i = 0; i < joystick.Axis.Count; i++)
{
state.SetAxis(JoystickAxis.Axis0 + i, (short)(joystick.Axis[i] * short.MaxValue + 0.5f));
}
for (int i = 0; i < joystick.Button.Count; i++)
{
state.SetButton(JoystickButton.Button0 + i, joystick.Button[i]);
}
state.SetIsConnected(joystick.Details.IsConnected);
state.SetPacketNumber(joystick.Details.PacketNumber);
}
return state;
}
示例4: GetState
public JoystickState GetState(int player_index)
{
lock (sync)
{
JoystickState state = new JoystickState();
if (IsValid(player_index))
{
int device_index = player_to_index[player_index];
int index = index_to_stick[device_index];
JoystickDevice<WinMMJoyDetails> stick =
sticks[index] as JoystickDevice<WinMMJoyDetails>;
// For joysticks with fewer than three axes or four buttons, we must
// use joyGetPos; otherwise, joyGetPosEx. This is not just a cosmetic
// difference, simple devices will return incorrect results if we use
// joyGetPosEx on them.
if (stick.Details.Capabilities.AxisCount <= 3 || stick.Details.Capabilities.ButtonCount <= 4)
{
// Use joyGetPos
JoyInfo info = new JoyInfo();
JoystickError result = UnsafeNativeMethods.joyGetPos(device_index, ref info);
if (result == JoystickError.NoError)
{
for (int i = 0; i < stick.Details.Capabilities.AxisCount; i++)
{
state.SetAxis(JoystickAxis.Axis0 + i, CalculateOffset(info.GetAxis(i), stick.Details.Min[i], stick.Details.Max[i]));
}
for (int i = 0; i < stick.Details.Capabilities.ButtonCount; i++)
{
state.SetButton(JoystickButton.Button0 + i, (info.Buttons & 1 << i) != 0);
}
state.SetIsConnected(true);
}
else if (result == JoystickError.Unplugged)
{
UnplugJoystick(player_index);
}
}
else
{
// Use joyGetPosEx
JoyInfoEx info = new JoyInfoEx();
info.Size = JoyInfoEx.SizeInBytes;
info.Flags = JoystickFlags.All;
JoystickError result = UnsafeNativeMethods.joyGetPosEx(device_index, ref info);
if (result == JoystickError.NoError)
{
for (int i = 0; i < stick.Details.Capabilities.AxisCount; i++)
{
state.SetAxis(JoystickAxis.Axis0 + i, CalculateOffset(info.GetAxis(i), stick.Details.Min[i], stick.Details.Max[i]));
}
for (int i = 0; i < stick.Details.Capabilities.ButtonCount; i++)
{
state.SetButton(JoystickButton.Button0 + i, (info.Buttons & 1 << i) != 0);
}
state.SetIsConnected(true);
}
else if (result == JoystickError.Unplugged)
{
UnplugJoystick(player_index);
}
}
}
return state;
}
}
示例5: GetState
public JoystickState GetState(int player_index)
{
lock (sync)
{
JoystickState state = new JoystickState();
if (IsValid(player_index))
{
int device_index = player_to_index[player_index];
int index = index_to_stick[device_index];
JoystickDevice<WinMMJoyDetails> stick =
sticks[index] as JoystickDevice<WinMMJoyDetails>;
// For joysticks with fewer than three axes or four buttons, we must
// use joyGetPos; otherwise, joyGetPosEx. This is not just a cosmetic
// difference, simple devices will return incorrect results if we use
// joyGetPosEx on them.
if (stick.Details.Capabilities.AxisCount <= 3 || stick.Details.Capabilities.ButtonCount <= 4)
{
// Use joyGetPos
JoyInfo info = new JoyInfo();
JoystickError result = UnsafeNativeMethods.joyGetPos(device_index, ref info);
if (result == JoystickError.NoError)
{
for (int i = 0; i < stick.Details.Capabilities.AxisCount; i++)
{
state.SetAxis(JoystickAxis.Axis0 + i, CalculateOffset(info.GetAxis(i), stick.Details.Min[i], stick.Details.Max[i]));
}
for (int i = 0; i < stick.Details.Capabilities.ButtonCount; i++)
{
state.SetButton(JoystickButton.Button0 + i, (info.Buttons & 1 << i) != 0);
}
state.SetIsConnected(true);
}
else if (result == JoystickError.Unplugged)
{
UnplugJoystick(player_index);
}
}
else
{
// Use joyGetPosEx
JoyInfoEx info_ex = new JoyInfoEx();
info_ex.Size = JoyInfoEx.SizeInBytes;
info_ex.Flags = JoystickFlags.All;
JoystickError result = UnsafeNativeMethods.joyGetPosEx(device_index, ref info_ex);
if (result == JoystickError.NoError)
{
for (int i = 0; i < stick.Details.Capabilities.AxisCount; i++)
{
state.SetAxis(JoystickAxis.Axis0 + i, CalculateOffset(info_ex.GetAxis(i), stick.Details.Min[i], stick.Details.Max[i]));
}
for (int i = 0; i < stick.Details.Capabilities.ButtonCount; i++)
{
state.SetButton(JoystickButton.Button0 + i, (info_ex.Buttons & 1 << i) != 0);
}
for (int i = 0; i < stick.Details.Capabilities.HatCount; i++)
{
// A discrete POV returns specific values for left, right, etc.
// A continuous POV returns an integer indicating an angle in degrees * 100, e.g. 18000 == 180.00 degrees.
// The vast majority of joysticks have discrete POVs, so we'll treat all of them as discrete for simplicity.
if ((JoystickPovPosition)info_ex.Pov != JoystickPovPosition.Centered)
{
HatPosition hatpos = HatPosition.Centered;
if (info_ex.Pov < 4500 || info_ex.Pov >= 31500)
hatpos |= HatPosition.Up;
if (info_ex.Pov >= 4500 && info_ex.Pov < 13500)
hatpos |= HatPosition.Right;
if (info_ex.Pov >= 13500 && info_ex.Pov < 22500)
hatpos |= HatPosition.Down;
if (info_ex.Pov >= 22500 && info_ex.Pov < 31500)
hatpos |= HatPosition.Left;
state.SetHat(JoystickHat.Hat0 + i, new JoystickHatState(hatpos));
}
}
state.SetIsConnected(true);
}
else if (result == JoystickError.Unplugged)
{
UnplugJoystick(player_index);
}
}
}
return state;
}
}