• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# JoystickState类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中JoystickState的典型用法代码示例。如果您正苦于以下问题:C# JoystickState类的具体用法?C# JoystickState怎么用?C# JoystickState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



JoystickState类属于命名空间,在下文中一共展示了JoystickState类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: DirectXControllerButton

        public DirectXControllerButton(DirectXControllerInterface controllerInterface, int buttonNumber, JoystickState initialState)
        {
            _buttonNumber = buttonNumber;
            _name = "Button " + (_buttonNumber + 1);
            _value = new HeliosValue(controllerInterface, new BindingValue(GetValue(initialState)), "", _name, "Current state for " + _name + ".", "True if pressed, false other wise.", BindingValueUnits.Boolean);

            _press = new HeliosTrigger(controllerInterface, "", _name, "pressed", "Fires when " + _name + " is pressed.", "Always returns true.", BindingValueUnits.Boolean);
            _release = new HeliosTrigger(controllerInterface, "", _name, "released", "Fires when " + _name + " is released.", "Always returns false.", BindingValueUnits.Boolean);

            _triggers.Add(_press);
            _triggers.Add(_release);

            _lastPollValue = GetValue(initialState);
        }
开发者ID:Heliflyer,项目名称:helios,代码行数:14,代码来源:DirectXControllerButton.cs


示例17: Poll

        public void Poll(Action<JoystickState> f)
        {
            if (joystick.Acquire().IsFailure)
                return;

            if (joystick.Poll().IsFailure)
                return;

            joyState = joystick.GetCurrentState();
            if (Result.Last.IsFailure)
                return;

            // Joystick is all good, call the function
            f(joyState);
        }
开发者ID:ZachMassia,项目名称:GAME302,代码行数:15,代码来源:Joystick.cs


示例18: Initialize

        public override void Initialize()
        {
            buttonDown = -1;
            joystickIsReady = false;

            // Make sure that DirectInput has been initialized
            DirectInput dinput = new DirectInput();
            state = new JoystickState();

            // search for devices
            foreach (DeviceInstance device in dinput.GetDevices(DeviceClass.GameController, DeviceEnumerationFlags.AttachedOnly))
            {
                // create the device
                try
                {
                    joystick = new Joystick(dinput, device.InstanceGuid);
                    joystick.SetCooperativeLevel(Core.Settings.RenderForm.Handle,
                        CooperativeLevel.Exclusive | CooperativeLevel.Foreground);
                    break;
                }
                catch (DirectInputException)
                {
                }
            }

            if (joystick != null)
            {
                foreach (DeviceObjectInstance deviceObject in joystick.GetObjects())
                {
                    if ((deviceObject.ObjectType & ObjectDeviceType.Axis) != 0)
                        joystick.GetObjectPropertiesById((int)deviceObject.ObjectType).SetRange(-1000, 1000);
                }
            }
            else
            {
                return;
            }

            // acquire the device
            joystick.Acquire();

            timer = new Timer();
            timer.Interval = 1000 / 10;
            timer.Tick += new EventHandler(timer_Tick);
            timer.Start();
        }
开发者ID:zulis,项目名称:Cubica,代码行数:46,代码来源:JoyStick.cs


示例19: ProcessController

        protected override void ProcessController()
        {
            ControllerState newState = new ControllerState();
            JoystickState joyState = new JoystickState();

            if (this.padsList == null || !this.padsList.Any())
            {
                this.padsList = this.GetGamePads();
                if (!this.padsList.Any()) return;
            }

            if (this.device == null)
            {
                this.device = this.padsList[0];
            }

            if (this.pad == null)
            {
                this.Acquire();
            }

            if (this.pad == null || this.pad.Poll().IsFailure || this.pad.GetCurrentState(ref joyState).IsFailure)
            {
                newState.Active = false;
            }
            else
            {
                //var objs = pad.GetObjects();
                newState.Active = true;
                newState.X = (joyState.X / 5000d);
                newState.Y = (joyState.Y / 5000d);
                newState.Buttons = joyState.GetButtons();
            }

            if (!newState.Equals(this.State))
            {

                this.State = newState;

                if (this.OnUpdate != null)
                {
                    this.OnUpdate.Invoke(this.State);
                }
            }
        }
开发者ID:jochym,项目名称:ASCOM-Celestron-Telescope-Driver-RS232-BT,代码行数:45,代码来源:GamePad.cs


示例20: PollChanges

        public void PollChanges(iGameClient GameCli)
        {
            //polls changes in this controller from the previous poll and raises
            //appropriate events in iGameClient depending on the differences.
            if (!haspolled)
            {
                haspolled=true;
                ourdevice.Poll();
                laststate = ourdevice.CurrentJoystickState;
                return;

            }
            laststate = ourdevice.CurrentJoystickState;
            ourdevice.Poll();

            byte[] prevbuttons = laststate.GetButtons();
            byte[] currbuttons = ourdevice.CurrentJoystickState.GetButtons();
        }
开发者ID:BCProgramming,项目名称:BASeBlock,代码行数:18,代码来源:gamepadinput.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# JsAction类代码示例发布时间:2022-05-24
下一篇:
C# Joystick类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap