예제 #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
        protected override void Initialize()
        {
            SpriteBatchHelpers.Initialize(this.GraphicsDevice);

            graphics.IsFullScreen = false;
            graphics.PreferredBackBufferWidth = 512;
            graphics.PreferredBackBufferHeight = 512;
            graphics.ApplyChanges();

            inputSystem = new InputSystem(this);
            inputSystem.RegisterKeyReleasedAction(Keys.Escape, () => Exit());
            inputSystem.RegisterKeyReleasedAction(Keys.Up, () => { level++; RefreshTurtle(); });
            inputSystem.RegisterKeyReleasedAction(Keys.Down, () => { level--; RefreshTurtle(); });
            inputSystem.RegisterKeyReleasedAction(Keys.Left, () => { dist /= 2; RefreshTurtle(); });
            inputSystem.RegisterKeyReleasedAction(Keys.Right, () => { dist *= 2; RefreshTurtle(); });
            inputSystem.RegisterKeyReleasedAction(Keys.W, () => { angle /= 2; RefreshTurtle(); });
            inputSystem.RegisterKeyReleasedAction(Keys.S, () => { angle *= 2; RefreshTurtle(); });
            inputSystem.RegisterKeyReleasedAction(Keys.D0, () =>
                {
                    system = new TreeSystem();
                    angle = 45;
                    level = 8;
                    RefreshTurtle();
                });
            inputSystem.RegisterKeyReleasedAction(Keys.D1, () =>
                {
                    system = new SierpinskiTriangle();
                    angle = 60;
                    level = 8;
                    RefreshTurtle();
                });
            inputSystem.RegisterKeyReleasedAction(Keys.D2, () =>
                {
                    system = new SierpinskiTriangleB();
                    angle = 120;
                    level = 8;
                    RefreshTurtle();
                });
            inputSystem.RegisterKeyReleasedAction(Keys.D3, () =>
                {
                    system = new DragonCurve();
                    angle = 90;
                    dist = 6;
                    level = 8;
                    RefreshTurtle();
                });
            inputSystem.RegisterKeyReleasedAction(Keys.D4, () =>
                {
                    system = new KochCurve();
                    angle = 90;
                    level = 8;
                    RefreshTurtle();
                });
            inputSystem.RegisterKeyReleasedAction(Keys.D5, () =>
                {
                    system = new CantorDust();
                    level = 8;
                    RefreshTurtle();
                });
            inputSystem.RegisterKeyReleasedAction(Keys.D6, () =>
                {
                    system = new FractalPlant();
                    angle = 35;
                    level = 8;
                    RefreshTurtle();
                });

            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
            Primitives.Initialize(GraphicsDevice);

            camera = new PerspectiveCamera()
            {
                Position = -10 * Vector3.UnitZ,
                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());

            base.Initialize();
        }
예제 #5
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();
        }
예제 #6
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();
        }