コード例 #1
0
ファイル: MainWindow.xaml.cs プロジェクト: dgulyas/sand
        public MainWindow()
        {
            InitializeComponent();
            m_holeLocation = new Point {
                X = Size / 2, Y = Size / 2, Height = 30
            };
            ((MainViewModel)DataContext).AddMeshHeights(m_sand);
            ((MainViewModel)DataContext).AddSphere(new Point3D(m_holeLocation.X + Radius, m_holeLocation.Y + Radius, m_holeLocation.Height), Radius);
            ((MainViewModel)DataContext).AddContainer(Size, Size, SandLevel);

            HelixPane.Camera.Position      = new Point3D(119.1, -187.8, 353.7);
            HelixPane.Camera.LookDirection = new Vector3D(3.4, 310.3, -346.2);

            if (X.IsAvailable)
            {
                m_gamepad = X.Gamepad_1;
                m_gamepad.StateChanged += ProcessXboxInput;
                X.StartPolling(m_gamepad);
            }

            Closing += (sender, args) =>
            {
                X.StopPolling();
                m_drawSync.RemoveParticipant();
                m_closed = true;
            };
        }
コード例 #2
0
ファイル: Manager.cs プロジェクト: Yuka1030/CupheadTAS-1
        //static GamepadState state;
        static Manager()
        {
            if (!X.IsAvailable)
            {
                throw new FileNotFoundException("XInput1_4.dll cannot be loaded.");
            }
            gamepad = X.Gamepad_1;
            X.Gamepad.Capability caps = gamepad.Capabilities;

            gamepad.ConnectionChanged += (o, i) => {
                // Give short haptical feedback to signal initialization
                gamepad.FFB_RightMotor(1f, 250);
            };

            gamepad.StateChanged += (o, i) => {
                if (!LTriggerHeld && (gamepad.LTrigger_N != 0))
                {
                    LTriggerHeld = true;
                    if (Mode != Modes.Advance)
                    {
                        Mode      = Modes.Advance;
                        isStopped = false;
                    }
                    else
                    {
                        Mode      = Modes.AdvanceFrame;
                        isStopped = true;
                    }
                }
                else if (gamepad.LTrigger_N == 0)
                {
                    LTriggerHeld = false;
                }
                if (!RTriggerHeld && (gamepad.RTrigger_N != 0))
                {
                    RTriggerHeld = true;
                    Mode         = Modes.AdvanceFrame;
                    isStopped    = false;
                }
                else if (gamepad.RTrigger_N == 0)
                {
                    RTriggerHeld = false;
                }
                if (gamepad.LStick_up)
                {
                    event_Switch(Controller.Modes.Recording);
                    isStopped = true;
                }
                if (gamepad.RStick_up)
                {
                    event_Switch(Controller.Modes.Replaying);
                    isStopped = false;
                }
                ProcessInputs();
            };

            Mode = Modes.Advance;
            X.StartPolling(gamepad);
            // End of init
        }
コード例 #3
0
 private void EnableXInputToolStripMenuItem_Click(object sender, EventArgs e)
 {
     gamepad = X.Gamepad_1;
     gamepad.StateChanged += Gamepad_StateChanged;
     X.StartPolling(gamepad);
     enableXInputToolStripMenuItem.Enabled = false;
     MessageBox.Show("XInput enabled. To pause XInput polling, press down your left stick.", "FileHook.NET", MessageBoxButtons.OK, MessageBoxIcon.Information);
 }
コード例 #4
0
        private Keys GamepadToKeys()
        {
            Keys keys = Keys.None;

            X.Gamepad gpad = G.I.Gamepad;

            if (gpad.Dpad_Down_down)
            {
                keys = Keys.Down;
            }

            if (gpad.Dpad_Up_down)
            {
                keys = Keys.Up;
            }

            if (gpad.Dpad_Left_down)
            {
                keys = Keys.Left;
            }

            if (gpad.Dpad_Right_down)
            {
                keys = Keys.Right;
            }

            if (gpad.Back_up)
            {
                keys = Keys.F5;
            }

            if (gpad.B_down)
            {
                keys = Keys.Back;
            }

            if (gpad.A_up)
            {
                keys = Keys.Enter;
            }

            if (gpad.Start_up)
            {
                keys = Keys.Escape;
            }

            if (gpad.LBumper_down)
            {
                keys = Keys.Subtract;
            }

            if (gpad.RBumper_down)
            {
                keys = Keys.Add;
            }

            return(keys);
        }
コード例 #5
0
 static void Main(string[] args)
 {
     X.Gamepad g = X.Gamepad_1;
     g.Enable = true;
     while (true)
     {
         g.Update();
         Console.WriteLine(g.IsConnected);//g.RStick.X + "\t" + g.RStick.Y);
         Thread.Sleep(100);
     }
 }
コード例 #6
0
        /// <summary>
        /// Generates Controller inputs from a gamepad input.
        /// Buttons are bound to match my own Rocket League settings.
        /// </summary>
        /// <param name="gamepad"></param>
        /// <returns></returns>
        public static Controller GenerateControlsCustom(X.Gamepad gamepad)
        {
            Controller c = new Controller();

            c.Throttle = gamepad.RTrigger_N - gamepad.LTrigger_N;
            c.Steer    = gamepad.LStick_N.X;
            c.Yaw      = gamepad.LStick_N.X;
            c.Pitch    = -gamepad.LStick_N.Y;
            c.Roll     = gamepad.RStick_N.X;

            c.Jump      = gamepad.A_down;
            c.Boost     = gamepad.RBumper_down;
            c.Handbrake = gamepad.LBumper_down;

            return(c);
        }
コード例 #7
0
        private void Gamepad_StateChanged(object sender, EventArgs e)
        {
            X.Gamepad gpad = G.I.Gamepad;
            Keys      k    = GamepadToKeys();

            if (k != Keys.None)
            {
                startDelta = DateTime.UtcNow.Ticks;
                if (isShowSelectLevel)
                {
                    TranslateGamepadButtons(k);
                }
                else
                {
                    Do_Keys(new KeyEventArgs(k));
                }
            }
        }
コード例 #8
0
        /// <summary>
        /// Generates Controller inputs from a gamepad input.
        /// Buttons are bound the same as the default Rocket League binds.
        /// </summary>
        /// <param name="gamepad"></param>
        /// <returns></returns>
        public static Controller GenerateControlsDefault(X.Gamepad gamepad)
        {
            Controller c = new Controller();

            c.Throttle = gamepad.RTrigger_N - gamepad.LTrigger_N;
            c.Steer    = gamepad.LStick_N.X;
            c.Pitch    = -gamepad.LStick_N.Y;

            if (gamepad.X_down)
            {
                c.Roll = gamepad.LStick_N.X;
            }
            else
            {
                c.Yaw = gamepad.LStick_N.X;
            }

            c.Jump      = gamepad.A_down;
            c.Boost     = gamepad.B_down;
            c.Handbrake = gamepad.X_down;

            return(c);
        }
コード例 #9
0
ファイル: ControllerPoller.cs プロジェクト: culturespy/ZapU
        public static void Poller(X.Gamepad gamepad,
                                  DeviceBase device,
                                  PanicDelegate DoPanic,
                                  List <RadioButton> controlmodeselections,
                                  NumericUpDown stick_sensitivity,
                                  NumericUpDown shoulder_sensitivity,
                                  NumericUpDown shoulder_floor,
                                  bool clear_to_send,
                                  ref bool A_button_debounce,
                                  ref bool B_button_debounce,
                                  ref bool X_button_debounce,
                                  ref bool Y_button_debounce)
        {
            if (gamepad == null)
            {
                return;
            }
            gamepad.Update();

            if (gamepad.X_down && !X_button_debounce)
            {
                X_button_debounce = true;
                DoPanic();
                return;
            }
            else
            {
                X_button_debounce = false;
            }

            RadioButton checked_input = controlmodeselections.FirstOrDefault(e => e.Checked);

            if (checked_input == null)
            {
                return;
            }

            if (gamepad.Y_down && !Y_button_debounce)
            {
                Y_button_debounce = true;
                int selidx = controlmodeselections.IndexOf(checked_input);
                selidx++;
                if (selidx >= controlmodeselections.Count)
                {
                    selidx = 0;
                }
                checked_input         = controlmodeselections[selidx];
                checked_input.Checked = true;
                return;
            }
            else if (gamepad.Y_up)
            {
                Y_button_debounce = false;
            }

            int shoulder_sensitivity_adjust = 0;

            if (gamepad.Dpad_Right_down)
            {
                shoulder_sensitivity_adjust = 1;
            }
            if (gamepad.Dpad_Left_down)
            {
                shoulder_sensitivity_adjust = -1;
            }
            if (shoulder_sensitivity_adjust != 0)
            {
                try
                {
                    shoulder_sensitivity.Value += shoulder_sensitivity_adjust;
                }
                catch (Exception) { }
            }

            int shoulder_floor_adjust = 0;

            if (gamepad.RBumper_down)
            {
                shoulder_floor_adjust = 1;
            }
            if (gamepad.LBumper_down)
            {
                shoulder_floor_adjust = -1;
            }
            if (shoulder_floor_adjust != 0)
            {
                try
                {
                    shoulder_floor.Value += shoulder_floor_adjust;
                }
                catch (Exception) { }
            }

            if (device == null || !device.IsReady || !clear_to_send)
            {
                return;
            }

            ModeCommand mode = null;

            if (gamepad.B_down && !B_button_debounce)
            {
                mode = new ModeCommand()
                {
                    Mode = (int)Intense.Mode,
                    MA   = Intense.StartingMA
                };
                B_button_debounce = true;
            }
            else if (gamepad.B_up)
            {
                B_button_debounce = false;
            }

            if (gamepad.A_down && !A_button_debounce)
            {
                mode = new ModeCommand()
                {
                    Mode = (int)Waves.Mode,
                    MA   = Waves.StartingMA
                };
                A_button_debounce = true;
            }
            else if (gamepad.A_up)
            {
                A_button_debounce = false;
            }

            if (mode != null)
            {
                device.SetMode(mode);
                return;
            }

            int           sensitivity, floor;
            LevelsCommand level = new LevelsCommand()
            {
                Mode = (ControlMode)checked_input.Tag
            };

            switch (level.Mode)
            {
            case ControlMode.remote:
                return;

            case ControlMode.absolute:
                //TODO: need to mathematically ensure this always winds up 0 <= x <= 255
                sensitivity = (int)shoulder_sensitivity.Value;
                floor       = (int)shoulder_floor.Value;
                level.A     = (int)Math.Sqrt((gamepad.LTrigger + floor) * sensitivity);
                level.B     = (int)Math.Sqrt((gamepad.RTrigger + floor) * sensitivity);
                break;

            case ControlMode.relative:
                sensitivity = (int)stick_sensitivity.Value;
                level.A     = (int)(gamepad.LStick_N.Y * sensitivity);
                level.B     = (int)(gamepad.RStick_N.Y * sensitivity);
                break;
            }
            if (gamepad.Dpad_Up_down)
            {
                level.MA = 1;
            }
            if (gamepad.Dpad_Down_down)
            {
                level.MA = -1;
            }

            device.SetLevels(level);
        }
コード例 #10
0
 private bool GetButtonState(X.Gamepad pad, X.Gamepad.GamepadButtons button)
 {
     return(((short)pad.Buttons & (short)button) == (short)button);
 }
コード例 #11
0
 //checks button states and raises events if necessary.
 public ControllerInputState(X.Gamepad pPad)
 {
     Pad = pPad;
 }
コード例 #12
0
 public ControllerPassthrough(string botName, int botTeam, int botIndex) : base(botName, botTeam, botIndex)
 {
     gamePad = X.Gamepad_1;
 }
コード例 #13
0
ファイル: MainForm.cs プロジェクト: tjrov/1819-Core
        public MainForm()
        {
            //controller
            pilot        = X.Gamepad_1;
            pilot.Enable = true;
            pilot.Update(); //must call update right after setting enable to true in order for it to connect

            //setup window
            KeyPreview = true;
            InitializeComponent();
            armButton.Enabled   = false;
            resetButton.Enabled = false;

            //setup devices
            string portName = "COM6";

            try
            {
                portName = BetterSerialPort.GetPortNames()[0];
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "No Serial ports available");
            }
            BetterSerialPort port = new BetterSerialPort(portName, 4800);

            portLabel.Text = string.Format("{0}@{1}baud", port.PortName, port.BaudRate);
            comms          = new SerialCommunication(port);
            comms.Stopped += comms_Stopped;
            comms.Started += comms_Started;
            comms.CommunicationException += Comms_CommunicationException;
            //comms.Connect();*/

            rov = new ROV(comms);

            //update displays when sensors polled
            rov.OrientationSensor.Updated += OrientationSensor_Updated;
            rov.DepthSensor.Updated       += DepthSensor_Updated;

            // enumerate video devices
            videoDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
            for (int i = 0; i < videoDevices.Count; i++)
            {
                if (videoDevices[i].Name.Equals("OEM Device"))
                {
                    videoSource = new VideoCaptureDevice(videoDevices[i].MonikerString);
                    videoSource.CrossbarVideoInput = videoSource.AvailableCrossbarVideoInputs[1];
                    videoSource.VideoResolution    = videoSource.VideoCapabilities[1];
                }
            }
            // set NewFrame event handler
            try
            {
                videoSource.NewFrame += new NewFrameEventHandler(video_NewFrame);
            }
            catch (NullReferenceException potato)
            {
                //fill in later, catch made temporarily to ignore NullReferenceException
            }
            picture.SizeMode = PictureBoxSizeMode.StretchImage;
        }