using System; namespace SharpDX.DirectInput { /// /// No documentation. /// /// DIJOYSTATE2 public class JoystickState : IDeviceState { public JoystickState() { Sliders = new int[2]; PointOfViewControllers = new int[4]; Buttons = new bool[128]; VelocitySliders = new int[2]; AccelerationSliders = new int[2]; ForceSliders = new int[2]; } /// /// No documentation. /// /// int lX public int X { get; set; } /// /// No documentation. /// /// int lY public int Y { get; set; } /// /// No documentation. /// /// int lZ public int Z { get; set; } /// /// No documentation. /// /// int lRx public int RotationX { get; set; } /// /// No documentation. /// /// int lRy public int RotationY { get; set; } /// /// No documentation. /// /// int lRz public int RotationZ { get; set; } /// /// No documentation. /// /// int rglSlider[2] public int[] Sliders { get; internal set; } /// /// No documentation. /// /// unsigned int rgdwPOV[4] public int[] PointOfViewControllers { get; internal set; } /// /// No documentation. /// /// unsigned char rgbButtons[128] public bool[] Buttons { get; internal set; } /// /// No documentation. /// /// int lVX public int VelocityX { get; set; } /// /// No documentation. /// /// int lVY public int VelocityY { get; set; } /// /// No documentation. /// /// int lVZ public int VelocityZ { get; set; } /// /// No documentation. /// /// int lVRx public int AngularVelocityX { get; set; } /// /// No documentation. /// /// int lVRy public int AngularVelocityY { get; set; } /// /// No documentation. /// /// int lVRz public int AngularVelocityZ { get; set; } /// /// No documentation. /// /// int rglVSlider[2] public int[] VelocitySliders { get; internal set; } /// /// No documentation. /// /// int lAX public int AccelerationX { get; set; } /// /// No documentation. /// /// int lAY public int AccelerationY { get; set; } /// /// No documentation. /// /// int lAZ public int AccelerationZ { get; set; } /// /// No documentation. /// /// int lARx public int AngularAccelerationX { get; set; } /// /// No documentation. /// /// int lARy public int AngularAccelerationY { get; set; } /// /// No documentation. /// /// int lARz public int AngularAccelerationZ { get; set; } /// /// No documentation. /// /// int rglASlider[2] public int[] AccelerationSliders { get; internal set; } /// /// No documentation. /// /// int lFX public int ForceX { get; set; } /// /// No documentation. /// /// int lFY public int ForceY { get; set; } /// /// No documentation. /// /// int lFZ public int ForceZ { get; set; } /// /// No documentation. /// /// int lFRx public int TorqueX { get; set; } /// /// No documentation. /// /// int lFRy public int TorqueY { get; set; } /// /// No documentation. /// /// int lFRz public int TorqueZ { get; set; } /// /// No documentation. /// /// int rglFSlider[2] public int[] ForceSliders { get; internal set; } // Internal native struct used for marshalling public void Update(JoystickUpdate update) { int value = update.Value; switch (update.Offset) { case JoystickOffset.X: X = value; break; case JoystickOffset.Y: Y = value; break; case JoystickOffset.Z: Z = value; break; case JoystickOffset.RotationX: RotationX = value; break; case JoystickOffset.RotationY: RotationY = value; break; case JoystickOffset.RotationZ: RotationZ = value; break; case JoystickOffset.Sliders0: Sliders[0] = value; break; case JoystickOffset.Sliders1: Sliders[1] = value; break; case JoystickOffset.PointOfViewControllers0: PointOfViewControllers[0] = value; break; case JoystickOffset.PointOfViewControllers1: PointOfViewControllers[1] = value; break; case JoystickOffset.PointOfViewControllers2: PointOfViewControllers[2] = value; break; case JoystickOffset.PointOfViewControllers3: PointOfViewControllers[3] = value; break; case JoystickOffset.VelocityX: VelocityX = value; break; case JoystickOffset.VelocityY: VelocityY = value; break; case JoystickOffset.VelocityZ: VelocityZ = value; break; case JoystickOffset.AngularVelocityX: AngularVelocityX = value; break; case JoystickOffset.AngularVelocityY: AngularVelocityY = value; break; case JoystickOffset.AngularVelocityZ: AngularVelocityZ = value; break; case JoystickOffset.VelocitySliders0: VelocitySliders[0] = value; break; case JoystickOffset.VelocitySliders1: VelocitySliders[1] = value; break; case JoystickOffset.AccelerationX: AccelerationX = value; break; case JoystickOffset.AccelerationY: AccelerationY = value; break; case JoystickOffset.AccelerationZ: AccelerationZ = value; break; case JoystickOffset.AngularAccelerationX: AngularAccelerationX = value; break; case JoystickOffset.AngularAccelerationY: AngularAccelerationY = value; break; case JoystickOffset.AngularAccelerationZ: AngularAccelerationZ = value; break; case JoystickOffset.AccelerationSliders0: AccelerationSliders[0] = value; break; case JoystickOffset.AccelerationSliders1: AccelerationSliders[1] = value; break; case JoystickOffset.ForceX: ForceX = value; break; case JoystickOffset.ForceY: ForceY = value; break; case JoystickOffset.ForceZ: ForceZ = value; break; case JoystickOffset.TorqueX: TorqueX = value; break; case JoystickOffset.TorqueY: TorqueY = value; break; case JoystickOffset.TorqueZ: TorqueZ = value; break; case JoystickOffset.ForceSliders0: ForceSliders[0] = value; break; case JoystickOffset.ForceSliders1: ForceSliders[1] = value; break; default: int buttonIndex = update.Offset - JoystickOffset.Buttons0; if (buttonIndex >= 0 && buttonIndex <128) Buttons[buttonIndex] = (value & 0x80) != 0; break; } } public void MarshalFrom(ref RawJoystickState value) { unsafe { this.X = value.X; this.Y = value.Y; this.Z = value.Z; this.RotationX = value.RotationX; this.RotationY = value.RotationY; this.RotationZ = value.RotationZ; fixed (int* __from = value.Sliders) { Sliders[0] = __from[0]; Sliders[1] = __from[1]; } fixed (int* __from = value.PointOfViewControllers) { PointOfViewControllers[0] = __from[0]; PointOfViewControllers[1] = __from[1]; PointOfViewControllers[2] = __from[2]; PointOfViewControllers[3] = __from[3]; } fixed(void* __from = value.Buttons) { for(int i = 0; i < 128; i++) Buttons[i] = (((byte*)__from)[i] & 0x80) != 0; } this.VelocityX = value.VelocityX; this.VelocityY = value.VelocityY; this.VelocityZ = value.VelocityZ; this.AngularVelocityX = value.AngularVelocityX; this.AngularVelocityY = value.AngularVelocityY; this.AngularVelocityZ = value.AngularVelocityZ; fixed (int* __from = value.VelocitySliders) { VelocitySliders[0] = __from[0]; VelocitySliders[1] = __from[1]; } this.AccelerationX = value.AccelerationX; this.AccelerationY = value.AccelerationY; this.AccelerationZ = value.AccelerationZ; this.AngularAccelerationX = value.AngularAccelerationX; this.AngularAccelerationY = value.AngularAccelerationY; this.AngularAccelerationZ = value.AngularAccelerationZ; fixed (int* __from = value.AccelerationSliders) { AccelerationSliders[0] = __from[0]; AccelerationSliders[1] = __from[1]; } this.ForceX = value.ForceX; this.ForceY = value.ForceY; this.ForceZ = value.ForceZ; this.TorqueX = value.TorqueX; this.TorqueY = value.TorqueY; this.TorqueZ = value.TorqueZ; fixed (int* __from = value.ForceSliders) { ForceSliders[0] = __from[0]; ForceSliders[1] = __from[1]; } } } public override string ToString() { return string.Format(System.Globalization.CultureInfo.InvariantCulture, "X: {0}, Y: {1}, Z: {2}, RotationX: {3}, RotationY: {4}, RotationZ: {5}, Sliders: {6}, PointOfViewControllers: {7}, Buttons: {8}, VelocityX: {9}, VelocityY: {10}, VelocityZ: {11}, AngularVelocityX: {12}, AngularVelocityY: {13}, AngularVelocityZ: {14}, VelocitySliders: {15}, AccelerationX: {16}, AccelerationY: {17}, AccelerationZ: {18}, AngularAccelerationX: {19}, AngularAccelerationY: {20}, AngularAccelerationZ: {21}, AccelerationSliders: {22}, ForceX: {23}, ForceY: {24}, ForceZ: {25}, TorqueX: {26}, TorqueY: {27}, TorqueZ: {28}, ForceSliders: {29}", X, Y, Z, RotationX, RotationY, RotationZ, Utilities.Join(";",Sliders), Utilities.Join(";",PointOfViewControllers), Utilities.Join(";",Buttons), VelocityX, VelocityY, VelocityZ, AngularVelocityX, AngularVelocityY, AngularVelocityZ, Utilities.Join(";",VelocitySliders), AccelerationX, AccelerationY, AccelerationZ, AngularAccelerationX, AngularAccelerationY, AngularAccelerationZ, Utilities.Join(";",AccelerationSliders), ForceX, ForceY, ForceZ, TorqueX, TorqueY, TorqueZ, Utilities.Join(";",ForceSliders)); } } }