本文整理汇总了C#中JoystickState类的典型用法代码示例。如果您正苦于以下问题:C# JoystickState类的具体用法?C# JoystickState怎么用?C# JoystickState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JoystickState类属于命名空间,在下文中一共展示了JoystickState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DirectInputGamePad
public DirectInputGamePad(DirectInput directInput, GamePadKey key) : base(key)
{
this.key = key;
this.directInput = directInput;
this.instance = new Joystick(directInput, key.Guid);
joystickState = new JoystickState();
}
示例2: GetValues
// TODO: allow user to configure the action based on value (vibrato, pitch shift, etc.)
/// <summary>
/// Emulates behaviour like that of <see cref="JoystickState.GetButtons()"/>.
/// </summary>
///
/// <param name="state">
/// The <see cref="JoystickState"/> instance to query.
/// </param>
///
/// <returns>
/// An array of integers representing the values of the respective axes.
/// </returns>
///
/// <remarks>
/// The irony here is that the value are probably read from an array in the first place.
/// </remarks>
public static int[] GetValues(JoystickState state)
{
int[] result = new int[] {
state.ARx,
state.ARy,
state.ARz,
state.AX,
state.AY,
state.AZ,
state.FRx,
state.FRy,
state.FRz,
state.FX,
state.FY,
state.FZ,
state.Rx,
state.Ry,
state.Rz,
state.VRx,
state.VRy,
state.VRz,
state.VX,
state.VY,
state.VZ,
state.X,
state.Y,
state.Z,
};
return result;
}
示例3: JoystickHandler
public bool[][] buttons = new bool[3][]; //2D-array, 1.dim = joystick, 2.dim = button
public JoystickHandler()
{
getSticks();
sticks = getSticks();
state = new JoystickState();
joystickDialog = new JoystickConfig();
}
示例4: Create
public static DirectXControllerFunction Create(DirectXControllerInterface controllerInterface, Guid objectType, int objectNumber, JoystickState initialState)
{
DirectXControllerFunction function = null;
if (objectType == ObjectGuid.Button)
function = new DirectXControllerButton(controllerInterface, objectNumber, initialState);
else if (objectType == ObjectGuid.Slider)
function = new DirectXControllerAxis(controllerInterface, DirectXControllerAxis.AxisType.Slider, objectNumber, initialState);
else if (objectType == ObjectGuid.XAxis)
function = new DirectXControllerAxis(controllerInterface, DirectXControllerAxis.AxisType.X, objectNumber, initialState);
else if (objectType == ObjectGuid.YAxis)
function = new DirectXControllerAxis(controllerInterface, DirectXControllerAxis.AxisType.Y, objectNumber, initialState);
else if (objectType == ObjectGuid.ZAxis)
function = new DirectXControllerAxis(controllerInterface, DirectXControllerAxis.AxisType.Z, objectNumber, initialState);
else if (objectType == ObjectGuid.RxAxis)
function = new DirectXControllerAxis(controllerInterface, DirectXControllerAxis.AxisType.Rx, objectNumber, initialState);
else if (objectType == ObjectGuid.RyAxis)
function = new DirectXControllerAxis(controllerInterface, DirectXControllerAxis.AxisType.Ry, objectNumber, initialState);
else if (objectType == ObjectGuid.RzAxis)
function = new DirectXControllerAxis(controllerInterface, DirectXControllerAxis.AxisType.Rz, objectNumber, initialState);
else if (objectType == ObjectGuid.PovController)
function = new DirectXControllerPOVHat(controllerInterface, objectNumber, initialState);
return function;
}
示例5: UpdateFrom
public void UpdateFrom(Joystick device, out JoystickState state)
{
if (!AppHelper.IsSameDevice(device, deviceInstanceGuid))
{
ShowDeviceInfo(device);
deviceInstanceGuid = Guid.Empty;
if (device != null)
{
deviceInstanceGuid = device.Information.InstanceGuid;
isWheel = device.Information.Type == SharpDX.DirectInput.DeviceType.Driving;
}
}
state = null;
if (device != null)
{
try
{
device.Acquire();
state = device.GetCurrentState();
}
catch (Exception ex)
{
var error = ex;
}
}
ShowDirectInputState(state);
}
示例6: 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;
}
示例7: Update
public static unsafe void Update(int index, int[] analogData, byte[] digitalData)
{
//Create the structure
var state = new JoystickState();
state.Signature = (uint)0x53544143;
state.NumAnalog = (char)63;
state.NumDigital = (char)128;
state.Analog = new int[state.NumAnalog];
state.Digital = new char[state.NumDigital];
//Fill it with our data
if (analogData != null)
Array.Copy(analogData, 0, state.Analog, 0, Math.Min(analogData.Length, state.Analog.Length));
if (digitalData != null)
Array.Copy(digitalData, 0, state.Digital, 0, Math.Min(digitalData.Length, state.Digital.Length));
//Send the data
uint bytesReturned = 0;
NativeOverlapped overlapped = new NativeOverlapped();
var h = _GetHandle(index);
bool ret = DeviceIoControl(h, 0x00220000,
state, (uint)Marshal.SizeOf(state),
IntPtr.Zero, 0, ref bytesReturned, ref overlapped);
if (!ret)
{
//TODO: Do something with this?
int lastError = Marshal.GetLastWin32Error();
//Invalidate the handle
_CloseHandle(h);
_handles[index] = null;
}
}
示例8: NormalizeInput
internal static JoystickState NormalizeInput(short X, short Y, short inputDeadZone, short joystickRange)
{
//From http://msdn.microsoft.com/en-us/library/windows/desktop/ee417001(v=vs.85).aspx
JoystickState result = new JoystickState();
//determine how far the controller is pushed
result.Magnitude = (float)Math.Sqrt(X * X + Y * Y);
//determine the direction the controller is pushed
result.NormalizedX = X / result.Magnitude;
result.NormalizedY = Y / result.Magnitude;
result.NormalizedMagnitude = 0;
//check if the controller is outside a circular dead zone
if (result.Magnitude > inputDeadZone)
{
//clip the magnitude at its expected maximum value
if (result.Magnitude > joystickRange)
result.Magnitude = joystickRange;
//adjust magnitude relative to the end of the dead zone
result.Magnitude -= inputDeadZone;
//optionally normalize the magnitude with respect to its expected range
//giving a magnitude value of 0.0 to 1.0
result.NormalizedMagnitude = result.Magnitude / (joystickRange - inputDeadZone);
}
else //if the controller is in the deadzone zero out the magnitude
{
result.Magnitude = 0;
result.NormalizedMagnitude = 0;
}
return result;
}
示例9: Poll
public void Poll()
{
this.device.Poll();
this.state = this.device.CurrentJoystickState;
byte[] newButtons = this.state.GetButtons();
if (this.buttons == null)
{
this.buttons = newButtons;
this.HasButtonStateChanged = true;
return;
}
this.IsButtonPressed = false;
this.HasButtonStateChanged = false;
for (int i = 0; i < newButtons.Length; i++)
{
if (newButtons[i] != this.buttons[i])
{
this.HasButtonStateChanged = true;
}
if (newButtons[i] > 0)
{
this.IsButtonPressed = true;
}
}
if (this.HasButtonStateChanged)
{
this.buttons = newButtons;
}
}
示例10: InitDevices
//Function of initialize device
public static void InitDevices()
{
//create joystick device.
foreach (DeviceInstance di in Manager.GetDevices(
DeviceClass.GameControl,
EnumDevicesFlags.AttachedOnly))
{
joystick = new Device(di.InstanceGuid);
break;
}
if (joystick == null)
{
//Throw exception if joystick not found.
}
//Set joystick axis ranges.
else {
foreach (DeviceObjectInstance doi in joystick.Objects)
{
if ((doi.ObjectId & (int)DeviceObjectTypeFlags.Axis) != 0)
{
joystick.Properties.SetRange(
ParameterHow.ById,
doi.ObjectId,
new InputRange(-5000, 5000));
}
}
joystick.Properties.AxisModeAbsolute = true;
joystick.SetCooperativeLevel(null,CooperativeLevelFlags.NonExclusive | CooperativeLevelFlags.Background);
//Acquire devices for capturing.
joystick.Acquire();
state = joystick.CurrentJoystickState;
}
}
示例11: DirectXControllerAxis
public DirectXControllerAxis(DirectXControllerInterface controllerInterface, AxisType type, int axisNumber, JoystickState initialState)
{
_axisType = type;
_axisNumber = axisNumber;
_value = new HeliosValue(controllerInterface, new BindingValue(GetValue(initialState)), "", Name, "Current value for " + Name + ".", "(0 - 65536)", BindingValueUnits.Numeric);
_triggers.Add(_value);
}
示例12: Convert
/// <summary>Retrieves the current value of the axis</summary>
/// <param name="gamePadState">Game pad state that will receive the value</param>
/// <param name="joystickState">State from which the axis is retrieved</param>
public void Convert(
FlatGamePadState gamePadState, ref JoystickState joystickState
) {
if (joystickState.X < base.Center) {
gamePadState.LeftThumbStick.X = (float)(base.Center - joystickState.X) / base.Min;
} else {
gamePadState.LeftThumbStick.X = (float)(joystickState.X - base.Center) / base.Max;
}
}
示例13: Update
public override void Update(GameTime gameTime)
{
base.Update(gameTime);
_joyState = Application.InputManager.GetJoystickState(Index);
// Mapping
// TODO Joypad mapping
// End
_previousJoystate = _joyState;
}
示例14: GetValue
public double GetValue(JoystickState joystickState, int povIndex)
{
// Position is quantized degrees from North quantized to the four cardinal directions.
int position = joystickState.GetPointOfViewControllers()[povIndex];
foreach(Range range in _directionRanges) {
if(range.Contains(position)) {
return range.Value / 100d;
}
}
return -1;
}
示例15: GetValue
/// <summary>Retrieves the current value of the axis</summary>
/// <param name="state">Joystick state the axis is taken from</param>
/// <returns>The value of the axis in the joystick state</returns>
public float GetValue(ref JoystickState state)
{
int raw = Read(ref state);
if (raw < this.center)
{
return (float) (this.center - raw)/this.min;
}
else
{
return (float) (raw - this.center)/this.max;
}
}