Пример #1
0
        public InputManager(World world)
        {
            this.world = world;

            inputSystem = new InputSystem(world.Game);
            inputSystem.RegisterKeyReleasedAction(Keys.Escape, () => world.Game.Exit());
            inputSystem.RegisterKeyReleasedAction(Keys.Tab, () =>
                {
                    DiagnosticsManager.Instance.UI.Show();
                });
            inputSystem.RegisterMouseWheelAction(change =>
                {
                    if (change < 0)
                    {
                        // closing to focus point
                        distance /= 2f;
                    }
                    else if (change > 0)
                    {
                        distance *= 2f;
                    }
                });
            inputSystem.RegisterMouseMoveAction((x, y) =>
                {
                    var horizontalAngle = MathHelper.ToRadians((float)-x / 10);
                    var verticalAngle = MathHelper.ToRadians((float)y / 10);
                    this.horizontalAngle += horizontalAngle;
                    this.verticalAngle += verticalAngle;
                });
        }
Пример #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()
        {
            graphics.IsFullScreen = false;
            graphics.PreferredBackBufferWidth = 512;
            graphics.PreferredBackBufferHeight = 512;
            graphics.ApplyChanges();

            SpriteBatchHelpers.Initialize(this.GraphicsDevice);
            inputSystem = new InputSystem(this);

            anim = new AnimatedLightning(Vector2.One * 12, Vector2.One * 500, 45, MathHelper.ToRadians(45), 0.7f, 5, 1, 10);

            //lightningPoints = LightningGenerator.Get(Vector2.One * 12, Vector2.One * 500, 140, 5, 1);
            //lightningSegments = LightningGenerator.GetForked(Vector2.One * 12, Vector2.One * 500, 45, MathHelper.ToRadians(45), 0.7f, 5, 1);

            inputSystem.RegisterKeyReleasedAction(Keys.Escape, () => Exit());
            inputSystem.RegisterMouseMoveAction((x, y) =>
                {
                    anim.End += new Vector2(x, y);
                });

            base.Initialize();
        }
Пример #3
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
            Primitives.Initialize(GraphicsDevice);

            sceneTarget = new RenderTarget2D(GraphicsDevice
                , GraphicsDevice.PresentationParameters.BackBufferWidth
                , GraphicsDevice.PresentationParameters.BackBufferHeight
                , false
                , GraphicsDevice.PresentationParameters.BackBufferFormat
                , GraphicsDevice.PresentationParameters.DepthStencilFormat);

            camera = new PerspectiveCamera()
            {
                Position = Vector3.UnitX,
                Target = Vector3.Zero,
                Up = Vector3.Up,
                FieldOfView = MathHelper.PiOver4,
                AspectRatio = GraphicsDevice.Viewport.AspectRatio,
                NearPlane = 0.01f,
                FarPlane = 5000f
            };

            inputSystem = new InputSystem(this);
            inputSystem.RegisterKeyReleasedAction(Keys.Escape, () => Exit());
            inputSystem.RegisterMouseWheelAction(change =>
                {
                    var prevZoomLevel = zoomLevel;
                    if (change < 0)
                    {
                        // closing to focus point
                        if (zoomLevel < 1) zoomLevel -= 0.025f;
                        else zoomLevel -= 0.1f;
                    }
                    else if (change > 0)
                    {
                        if (zoomLevel < 1) zoomLevel += 0.025f;
                        else zoomLevel += 0.1f;
                    }
                    if (zoomLevel <= 0) zoomLevel = prevZoomLevel;
                });
            inputSystem.RegisterMouseMoveAction((x, y) =>
                {
                    var axis = Vector3.Cross(camera.Target - camera.Position, camera.Up);
                    var transform = Quaternion.CreateFromAxisAngle(axis, MathHelper.ToRadians(y * 10));
                    camera.Position = Vector3.Transform(camera.Position, transform);

                    cameraAngle += MathHelper.ToRadians(x);
                    cameraHeight += y % 10;
                });

            primitives[0] = new Primitive(GraphicsDevice, 1, Primitives.Sphere) { Position = Vector3.UnitX };
            primitives[1] = new Primitive(GraphicsDevice, 1, Primitives.Cube) { Position = Vector3.UnitX * 3 };
            primitives[2] = new Primitive(GraphicsDevice, 1, Primitives.Plane) { Position = Vector3.UnitX * 5 };

            base.Initialize();
        }
Пример #4
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

            sceneTarget = new RenderTarget2D(GraphicsDevice
                , GraphicsDevice.PresentationParameters.BackBufferWidth
                , GraphicsDevice.PresentationParameters.BackBufferHeight
                , false
                , GraphicsDevice.PresentationParameters.BackBufferFormat
                , GraphicsDevice.PresentationParameters.DepthStencilFormat);

            camera = new PerspectiveCamera()
                {
                    Position = Vector3.UnitX,
                    Target = Vector3.Zero,
                    Up = Vector3.Up,
                    FieldOfView = MathHelper.PiOver4,
                    AspectRatio = GraphicsDevice.Viewport.AspectRatio,
                    NearPlane = 0.01f,
                    FarPlane = 5000f
                };

            inputSystem = new InputSystem(this);
            inputSystem.RegisterKeyReleasedAction(Keys.Escape, () => Exit());
            inputSystem.RegisterKeyReleasedAction(Keys.Tab, () =>
                {
                    DiagnosticsManager.Instance.UI.Show();
                });
            inputSystem.RegisterMouseWheelAction(change =>
                {
                    if (change < 0)
                    {
                        // closing to focus point
                        followCam.Distance /= 2f;
                    }
                    else if (change > 0)
                    {
                        followCam.Distance *= 2f;
                    }
                });
            inputSystem.RegisterMouseMoveAction((x, y) =>
                {
                    var horizontalAngle = MathHelper.ToRadians((float)-x / 10);
                    var verticalAngle = MathHelper.ToRadians((float)y / 10);

                    if (inputSystem.CurrentMouseState.MiddleButton == ButtonState.Pressed)
                    {
                        followCam.HorizontalAngle += horizontalAngle;
                        followCam.VerticalAngle += verticalAngle;
                    }
                    else
                    {
                        ship.Turn(horizontalAngle, verticalAngle);
                    }
                });
            inputSystem.RegisterMouseButtonHeldDownAction(MouseButtons.LeftButton, () =>
                {
                    ship.Velocity += ship.Forward;
                });
            inputSystem.RegisterMouseButtonHeldDownAction(MouseButtons.RightButton, () =>
                {
                    ship.Velocity -= ship.Forward;
                });

            Services.AddService(typeof(ICamera), camera);
            Services.AddService(typeof(InputSystem), inputSystem);

            base.Initialize();
        }