Example #1
0
        public override void Stop()
        {
            if (timer != null)
            {
                timer.Stop();
            }
            foreach (KeyValuePair <IntPtr, CursorData> pair in deviceList)
            {
                pair.Value.CloseCursor();
            }
            if (lowLevelMouseHook != null)
            {
                lowLevelMouseHook.Unhook();
            }
            WFCursor.Show();
            RawDevice.UnregisterRawDevices(0x01, 0x02);
            RawDevice.RawInput -= RawDevice_RawInput;
            isRunning           = false;

            System.Windows.Forms.Application.Exit();

            deviceList.Clear();
            historyList.Clear();
            currentList.Clear();
        }
Example #2
0
        protected override void OnLoad(EventArgs e)
        {
            _spheres = new List <Sphere> {
                new Sphere(Vector3.Zero, _sRadius, _sDensity)
            };

            _camera        = new SphereCamera(Width, Height, _spheres[0], StandEyeLevel);
            _camera.SkyBox = Starfield.Generate(_sSkySeed, 1024, 4);

            _frameTimer         = new Stopwatch();
            _lastPosUpdateTimer = new Stopwatch();

            _frameTimer.Start();
            _lastPosUpdateTimer.Start();

            _frameCounter = 0;

            Mouse.Move += (sender, me) => {
                if (!Focused || !_captureMouse)
                {
                    return;
                }

                var centre = new Point(Bounds.Left + Width / 2, Bounds.Top + Height / 2);

                if (WFCursor.Position.X == centre.X && WFCursor.Position.Y == centre.Y)
                {
                    return;
                }

                _camera.Yaw   += (WFCursor.Position.X - centre.X) / 360f;
                _camera.Pitch += (WFCursor.Position.Y - centre.Y) / 360f;

                _camera.Pitch = Tools.Clamp(_camera.Pitch, -MathHelper.PiOver2, MathHelper.PiOver2);

                WFCursor.Position = centre;
            };

            Mouse.ButtonUp += (sender, me) => {
                if (_captureMouse)
                {
                    return;
                }

                _captureMouse = true;
                WFCursor.Hide();
            };

            Keyboard.KeyDown += (sender, ke) => {
                switch (ke.Key)
                {
                case Key.Escape:
                    _captureMouse = !_captureMouse;
                    if (_captureMouse)
                    {
                        WFCursor.Hide();
                    }
                    else
                    {
                        WFCursor.Show();
                    }
                    break;

                case Key.Space:
                    if (_camera.Altitude <= _camera.EyeHeight)
                    {
                        _camera.Jump(8f);
                    }
                    break;

                case Key.F11:
                    if (WindowState == WindowState.Fullscreen)
                    {
                        WindowState = WindowState.Normal;
                    }
                    else
                    {
                        WindowState = WindowState.Fullscreen;
                    }
                    break;

                case Key.F12:
                    _takeScreenShot = true;
                    break;
                }
            };
        }