当前位置: 首页>>代码示例>>C#>>正文


C# JoystickState类代码示例

本文整理汇总了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();
 }
开发者ID:h78hy78yhoi8j,项目名称:xenko,代码行数:7,代码来源:InputManager.Windows.DirectInput.cs

示例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;
 }
开发者ID:olivierdagenais,项目名称:yeehawklipklippe,代码行数:46,代码来源:AxisMapping.cs

示例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();
        }
开发者ID:rtorsvik,项目名称:ROVInterface,代码行数:10,代码来源:JoystickHandeler.cs

示例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;
        }
开发者ID:Heliflyer,项目名称:helios,代码行数:25,代码来源:DirectXControllerFunction.cs

示例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);
 }
开发者ID:suvjunmd,项目名称:x360ce,代码行数:27,代码来源:DirectInputControl.cs

示例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;
        }
开发者ID:RockyTV,项目名称:opentk,代码行数:34,代码来源:XInputJoystick.cs

示例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;
              }
        }
开发者ID:aromis,项目名称:uDrawTablet,代码行数:34,代码来源:PPJoyInterface.cs

示例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;
 }
开发者ID:GroM,项目名称:SDK,代码行数:29,代码来源:InputHelper.cs

示例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;
            }
        }
开发者ID:jtdowney,项目名称:OperatorGame,代码行数:33,代码来源:Gamepad.cs

示例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;
            }
        }
开发者ID:eserozvataf,项目名称:itec316,代码行数:36,代码来源:joystick.cs

示例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);
        }
开发者ID:Heliflyer,项目名称:helios,代码行数:8,代码来源:DirectXControllerAxis.cs

示例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;
   }
 }
开发者ID:pr0gramm3r1,项目名称:AngryTanks,代码行数:12,代码来源:GamePadConverter.Converters.cs

示例13: Update

        public override void Update(GameTime gameTime)
        {
            base.Update(gameTime);

            _joyState = Application.InputManager.GetJoystickState(Index);

            // Mapping
            // TODO Joypad mapping

            // End
            _previousJoystate = _joyState;
        }
开发者ID:valryon,项目名称:Rabbit-Apocalypse,代码行数:12,代码来源:JoypadDevice.cs

示例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;
        }
开发者ID:kjburns31,项目名称:vixen-modules,代码行数:12,代码来源:CardinalPovBehavior.cs

示例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;
        }
      }
开发者ID:Azzuro,项目名称:IR-Server-Suite,代码行数:16,代码来源:DirectInputConverter.AxisReaders.cs


注:本文中的JoystickState类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。