Пример #1
0
 public DirectInputDeviceProvider(IgnoredDeviceService ignoredDeviceService, InputConfigManager inputConfigManager, IdHelper idHelper, NotificationService notificationService)
 {
     this.ignoredDeviceService = ignoredDeviceService;
     this.inputConfigManager   = inputConfigManager;
     this.idHelper             = idHelper;
     this.notificationService  = notificationService;
 }
Пример #2
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here
            // zfar is decreased intentionally, because on large values Ray Vector becomes NaN
            camera = new Camera(new Vector3(0, 0, 100.0f), Vector3.Forward, Vector3.UnitY, 45.0f, graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight, 0.01f, 10000.0f);

            MouseManager.IsPointerVisible = true;
            this.IsMouseVisible           = MouseManager.IsPointerVisible;
            MouseManager.LoadCustomCursor(@"Content\AnimatedCursor.ani");
            Form winForm = (Form)Form.FromHandle(this.Window.Handle);

            winForm.Cursor = MouseManager.CustomCursor;

            isWireFrame            = false;
            isKeybindingsHintShown = false;

            _hexSphere = new DrawableHexSphere(graphics, 7, 50);
            _hexSphere.Effect.VertexColorEnabled = true;
            drawablePlane          = new DrawablePlane(graphics, Content.Load <Texture2D>("Wall"), 50, 50, 1, 1);
            drawablePlane.Position = new Vector3(50, 0, 0);
            drawablePlane.Rotation = new Vector3(MathHelper.ToRadians(-30), 0, 0);

            // Create a new SpriteBatch, which can be used to draw textures / text
            spriteBatch = new SpriteBatch(GraphicsDevice);

            InputConfigManager.DefaultInitialize();

            base.Initialize();
        }
Пример #3
0
        public MouseDeviceProvider(InputConfigManager inputConfigManager, MouseHook hook)
        {
            this.hook = hook;
            this.inputConfigManager = inputConfigManager;
#if !DEBUG
            hook.StartHook();
#endif
        }
Пример #4
0
        public KeyboardDeviceProvider(InputConfigManager inputConfigManager, KeyboardHook hook)
        {
            this.hook = hook;
            this.inputConfigManager = inputConfigManager;
#if !DEBUG
            hook.StartHook();
#endif
        }
Пример #5
0
 public MouseDevice(InputConfigManager inputConfigManager, MouseHook hook)
 {
     this.inputConfigManager = inputConfigManager;
     this.hook             = hook;
     UniqueId              = MouseDeviceProvider.DeviceId;
     DisplayName           = MouseDeviceProvider.DeviceId;
     sources               = Enum.GetValues(typeof(MouseButton)).OfType <MouseButton>().Select((b) => new MouseSource(this, b.ToString(), (int)b)).ToArray();
     targets               = new ForceFeedbackTarget[0];
     inputChangedEventArgs = new DeviceInputChangedEventArgs(this);
 }
Пример #6
0
        public DirectInputDevice(InputConfigManager inputConfigManager, Joystick joystick, string guid, string productName, bool hasForceFeedbackDevice,
                                 string uniqueId, string hardwareId, string interfacePath)
        {
            this.inputConfigManager = inputConfigManager;
            this.joystick           = joystick;
            UniqueId      = uniqueId;
            InterfacePath = interfacePath;
            HardwareID    = hardwareId;
            DisplayName   = productName;
            var buttonObjectInstances = joystick.GetObjects(DeviceObjectTypeFlags.Button).Where(b => b.Usage > 0).OrderBy(b => b.ObjectId.InstanceNumber).Take(128).ToArray();
            var buttons = buttonObjectInstances.Select((b, i) => DirectInputSource.FromButton(this, b, i)).ToArray();
            var axes    = GetAxes().OrderBy(a => a.Usage).Take(24).Select(a => DirectInputSource.FromAxis(this, a));
            var sliders = joystick.GetObjects().Where(o => o.ObjectType == ObjectGuid.Slider).OrderBy(a => a.Usage).Select((s, i) => DirectInputSource.FromSlider(this, s, i));
            IEnumerable <DirectInputSource> dpads = new DirectInputSource[0];

            if (joystick.Capabilities.PovCount > 0)
            {
                dpads = Enumerable.Range(0, joystick.Capabilities.PovCount)
                        .SelectMany(i => DirectInputSource.FromDPad(this, i));
            }
            sources = buttons.Concat(axes).Concat(sliders).Concat(dpads).ToArray();

            EffectInfo force = null;

            if (hasForceFeedbackDevice)
            {
                try
                {
                    joystick.SetCooperativeLevel(WindowHandleStore.Handle, CooperativeLevel.Background | CooperativeLevel.Exclusive);
                }
                catch (Exception)
                {
                    logger.Warn($"Failed to set cooperative level to exclusive for {ToString()}");
                }
                var constantForce = joystick.GetEffects().FirstOrDefault(x => x.Guid == EffectGuid.ConstantForce);
                if (constantForce == null)
                {
                    force = joystick.GetEffects().FirstOrDefault();
                }
                else
                {
                    force = constantForce;
                }
                var actuatorAxes = joystick.GetObjects().Where(doi => doi.ObjectId.Flags.HasFlag(DeviceObjectTypeFlags.ForceFeedbackActuator)).ToArray();
                targets        = actuatorAxes.Select(i => new ForceFeedbackTarget(this, i.Name, i.Offset)).ToArray();
                forceFeedbacks = targets.ToDictionary(t => t, t => new DirectDeviceForceFeedback(joystick, UniqueId, force, actuatorAxes.First(a => a.Offset == t.Offset)));
            }
            else
            {
                targets        = new ForceFeedbackTarget[0];
                forceFeedbacks = new Dictionary <ForceFeedbackTarget, DirectDeviceForceFeedback>();
            }
            joystick.Acquire();
            inputChangedEventArgs = new DeviceInputChangedEventArgs(this);
        }
Пример #7
0
 public RawInputDevice(InputConfigManager inputConfigManager, HidDevice device, ReportDescriptor reportDescriptor, DeviceItem deviceItem,
                       HidStream hidStream, string uniqueId)
 {
     this.inputConfigManager = inputConfigManager;
     this.device             = device;
     inputReportBuffer       = new byte[device.GetMaxInputReportLength()];
     inputReceiver           = reportDescriptor.CreateHidDeviceInputReceiver();
     inputParser             = deviceItem.CreateDeviceItemInputParser();
     inputReceiver.Start(hidStream);
     DisplayName           = device.GetProductName();
     UniqueId              = uniqueId;
     InterfacePath         = device.DevicePath;
     HardwareID            = IdHelper.GetHardwareId(InterfacePath);
     inputChangedEventArgs = new DeviceInputChangedEventArgs(this);
     sources = reportDescriptor.InputReports.SelectMany(ir => ir.DataItems)
               .SelectMany(di => di.Usages.GetAllValues())
               .Select(u => (Usage)u)
               .SelectMany(u => RawInputSource.FromUsage(this, u))
               .ToArray();
 }
Пример #8
0
 public DirectInputDeviceProvider(IgnoredDeviceService ignoredDeviceService, InputConfigManager inputConfigManager)
 {
     this.ignoredDeviceService = ignoredDeviceService;
     this.inputConfigManager   = inputConfigManager;
 }
Пример #9
0
 public KeyboardDeviceProvider(InputConfigManager inputConfigManager, KeyboardHook hook)
 {
     this.hook = hook;
     this.inputConfigManager = inputConfigManager;
 }
Пример #10
0
 public MouseDeviceProvider(InputConfigManager inputConfigManager, MouseHook hook)
 {
     this.hook = hook;
     this.inputConfigManager = inputConfigManager;
 }
Пример #11
0
 public DirectInputDeviceProvider(InputConfigManager inputConfigManager)
 {
     this.inputConfigManager = inputConfigManager;
 }
Пример #12
0
        private void HandleCameraInput()
        {
            // Camera handling
            if (InputConfigManager.IsKeyBindingPressed(ActionType.SwitchCameraFreeMode))
            {
                camera.SetFreeCamera();
            }
            if (InputConfigManager.IsKeyBindingPressed(ActionType.SwitchCameraThirdPersonMode))
            {
                camera.SetThirdPersonCamera(_hexSphere.Position, _hexSphere.AxisRotationQuaternion, new Vector3(0, 0, 0), CameraType.ThirdPersonFree, null, 200);
            }
            if (InputConfigManager.IsKeyBindingPressed(ActionType.SwitchCameraThirdPersonAltMode))
            {
                camera.SetThirdPersonCamera(_hexSphere.Position, _hexSphere.AxisRotationQuaternion, new Vector3(0, 0, 0), CameraType.ThirdPersonFreeAlt, null, 200);
            }
            if (InputConfigManager.IsKeyBindingPressed(ActionType.SwitchCameraThirdPersonLockedMode))
            {
                camera.SetThirdPersonCamera(_hexSphere.Position, _hexSphere.AxisRotationQuaternion, new Vector3(0, 0, 0), CameraType.ThirdPersonLocked, null, 200);
            }
            if (InputConfigManager.IsKeyBindingDown(ActionType.CameraMoveForward))
            {
                camera.MoveRelativeZ(-camera.MovementVelocity * FrameRateCounter.FrameTime);
            }
            if (InputConfigManager.IsKeyBindingDown(ActionType.CameraMoveBackward))
            {
                camera.MoveRelativeZ(camera.MovementVelocity * FrameRateCounter.FrameTime);
            }
            if (InputConfigManager.IsKeyBindingDown(ActionType.CameraMoveLeft))
            {
                camera.MoveRelativeX(-camera.MovementVelocity * FrameRateCounter.FrameTime);
            }
            if (InputConfigManager.IsKeyBindingDown(ActionType.CameraMoveRight))
            {
                camera.MoveRelativeX(camera.MovementVelocity * FrameRateCounter.FrameTime);
            }
            if (InputConfigManager.IsKeyBindingDown(ActionType.CameraMoveDown))
            {
                camera.MoveRelativeY(-camera.MovementVelocity * FrameRateCounter.FrameTime);
            }
            if (InputConfigManager.IsKeyBindingDown(ActionType.CameraMoveUp))
            {
                camera.MoveRelativeY(camera.MovementVelocity * FrameRateCounter.FrameTime);
            }
            if (InputConfigManager.IsKeyBindingDown(ActionType.CameraTiltLeft))
            {
                camera.RotateRelativeZ(-camera.RotationVelocity * FrameRateCounter.FrameTime);
            }
            if (InputConfigManager.IsKeyBindingDown(ActionType.CameraTiltRight))
            {
                camera.RotateRelativeZ(camera.RotationVelocity * FrameRateCounter.FrameTime);
            }
            if (InputConfigManager.IsKeyBindingDown(ActionType.CameraRotateUp))
            {
                camera.RotateRelativeX(-camera.RotationVelocity * FrameRateCounter.FrameTime);
            }
            if (InputConfigManager.IsKeyBindingDown(ActionType.CameraRotateDown))
            {
                camera.RotateRelativeX(camera.RotationVelocity * FrameRateCounter.FrameTime);
            }
            if (InputConfigManager.IsKeyBindingDown(ActionType.CameraRotateLeft))
            {
                camera.RotateRelativeY(-camera.RotationVelocity * FrameRateCounter.FrameTime);
            }
            if (InputConfigManager.IsKeyBindingDown(ActionType.CameraRotateRight))
            {
                camera.RotateRelativeY(camera.RotationVelocity * FrameRateCounter.FrameTime);
            }

            camera.Update();
        }
Пример #13
0
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            // TODO: Add your update logic here
            FrameRateCounter.Update(gameTime);
            KeyboardManager.Update();
            MouseManager.Update();

            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
            {
                this.Exit();
            }
            if (InputConfigManager.IsKeyBindingPressed(ActionType.Exit))
            {
                this.Exit();
            }

            // Toggle keybindings hint
            if (InputConfigManager.IsKeyBindingPressed(ActionType.ToggleKeybindingsHint))
            {
                isKeybindingsHintShown = !isKeybindingsHintShown;
            }

            // Toggle wireframe mode
            if (InputConfigManager.IsKeyBindingPressed(ActionType.ToggleWireframe))
            {
                isWireFrame = !isWireFrame;
            }

            RasterizerState rasterizerState = new RasterizerState();

            if (isWireFrame == true)
            {
                rasterizerState.FillMode = FillMode.WireFrame;
            }
            else
            {
                rasterizerState.FillMode = FillMode.Solid;
            }
            GraphicsDevice.RasterizerState = rasterizerState;

            // Framerate handling
            if (InputConfigManager.IsKeyBindingPressed(ActionType.ToggleFixedFramerate))
            {
                graphics.SynchronizeWithVerticalRetrace = !graphics.SynchronizeWithVerticalRetrace;
                this.IsFixedTimeStep = !this.IsFixedTimeStep;
                graphics.ApplyChanges();
            }

            // Fullscreen handling
            if (InputConfigManager.IsKeyBindingPressed(ActionType.ToggleFullscreen))
            {
                graphics.IsFullScreen = !graphics.IsFullScreen;
                graphics.ApplyChanges();
            }

            HandleCameraInput();

            Ray mouseRay = CalculateRay(MouseManager.MouseStatus.Position.ToVector2(), camera.ViewMatrix, camera.ProjectionMatrix, _hexSphere.Effect.World, GraphicsDevice.Viewport);

            _hexSphere.CheckIntersection(ref mouseRay, out _hexSphereIntersectionChecksCount);


            _hexSphere.Update(gameTime, camera.Offset);
            drawablePlane.Update(camera.Offset);

            base.Update(gameTime);
        }
Пример #14
0
 public RawInputDeviceProvider(IgnoredDeviceService ignoredDeviceService, InputConfigManager inputConfigManager, IdHelper idHelper)
 {
     this.ignoredDeviceService = ignoredDeviceService;
     this.inputConfigManager   = inputConfigManager;
     this.idHelper             = idHelper;
 }