/// <param name="input">The InputState instance this manager should use.</param>
 public ScreenManager(Game game, InputState input)
     : base(game)
 {
     screens = new List<GameScreen>();
     screensToUpdate = new List<GameScreen>();
     this.input = input;
 }
 /// <summary>
 /// Handler for the input to this screen. This is called only when this screen has focus.
 /// </summary>
 /// <param name="input">The InputState instance to read input from.</param>
 public virtual void HandleInput(InputState input)
 {
 }
        public override void HandleInput(InputState input)
        {
            base.HandleInput(input);

            if (input.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.Enter))
                ScreenManager.Game.Exit();
        }
        public override void HandleInput(InputState input)
        {
            base.HandleInput(input);

            if (input.IsKeyPressed(Keys.Escape))
            {
                VolumetricRenderer.Game.Components.Remove(volumetricModel);

                // Reload the main menu and return.
                ScreenManager.AddScreen(new BackgroundScreen());
                ScreenManager.AddScreen(new MainMenuScreen());
                Finished();
            }

            // Volumetric Model
            if (input.IsKeyPressed(Keys.OemTilde))
            {
                if (volumeFile.Contains("skull"))
                {
                    volumeFile = "BostonTeapot.raw";
                    volumeFileSize = new Vector3(256, 256, 178);
                }
                else
                {
                    volumeFile = "skull.raw";
                    volumeFileSize = new Vector3(256, 256, 256);
                }

                VolumetricRenderer.Game.Components.Remove(volumetricModel);
                LoadVolumeData();
            }

            // Lighting
            if (input.IsKeyPressed(Keys.D8))
            {
                volumetricModel.ToggleLighting1();
            }
            else if (input.IsKeyPressed(Keys.D9))
            {
                volumetricModel.ToggleLighting2();
            }
            else if (input.IsKeyPressed(Keys.D0))
            {
                volumetricModel.ToggleLighting3();
            }

            // Transfer function testing.
            if (input.IsKeyPressed(Keys.D7))
            {
                volumetricModel.ToggleTransferFunction();
            }
            else if (input.IsKeyDown(Keys.OemPlus) || input.IsKeyDown(Keys.OemMinus) ||
                input.IsKeyDown(Keys.OemCloseBrackets) || input.IsKeyDown(Keys.OemOpenBrackets) ||
                input.IsKeyDown(Keys.OemQuotes) || input.IsKeyDown(Keys.OemSemicolon) ||
                input.IsKeyPressed(Keys.D1) || input.IsKeyPressed(Keys.D2) ||
                input.IsKeyPressed(Keys.D4) || input.IsKeyPressed(Keys.D5))
            {
                if (input.IsKeyPressed(Keys.D1))
                {
                    isoValue = 30;
                    alphaValue = 0.02f;
                    range = 130;
                }
                else if (input.IsKeyPressed(Keys.D2))
                {
                    isoValue = 30;
                    alphaValue = 0.03f;
                    range = 30;
                }
                else if (input.IsKeyPressed(Keys.D4))
                {
                    isoValue = 60;
                    alphaValue = 0.998f;
                    range = 50;
                }
                else if (input.IsKeyPressed(Keys.D5))
                {
                    isoValue = 130;
                    alphaValue = 0.998f;
                    range = 90;
                }
                else if (isoValue == 0)
                    return;
                else if (input.IsKeyDown(Keys.OemPlus) && isoValue < 252 - range)
                    isoValue++;
                else if (input.IsKeyDown(Keys.OemMinus) && isoValue > 3)
                    isoValue--;
                else if (input.IsKeyDown(Keys.OemCloseBrackets) && alphaValue < 0.997f)
                    alphaValue += 0.002f;
                else if (input.IsKeyDown(Keys.OemOpenBrackets) && alphaValue > 0.003f)
                    alphaValue -= 0.002f;
                else if (input.IsKeyDown(Keys.OemQuotes) && range < 252 - isoValue)
                    range++;
                else if (input.IsKeyDown(Keys.OemSemicolon) && range > 1)
                    range--;

                volumetricModel.TransferPoints = new TransferControlPoints(3, 6);

                volumetricModel.TransferPoints.AddRGBControlPoint(Color.Red, 0);
                volumetricModel.TransferPoints.AddRGBControlPoint(Color.Red, 1);
                volumetricModel.TransferPoints.AddRGBControlPoint(Color.Red, 255);

                volumetricModel.TransferPoints.AddAlphaControlPoint(0f, 0);
                volumetricModel.TransferPoints.AddAlphaControlPoint(0f, (byte)(isoValue - 2));
                volumetricModel.TransferPoints.AddAlphaControlPoint(alphaValue, isoValue);
                volumetricModel.TransferPoints.AddAlphaControlPoint(alphaValue, (byte)(isoValue + range));
                volumetricModel.TransferPoints.AddAlphaControlPoint(0f, (byte)(isoValue + range + 2));
                volumetricModel.TransferPoints.AddAlphaControlPoint(0f, 255);

                volumetricModel.CreateTransferFunction();
            }

            // Transfer function testing.
            if (input.IsKeyPressed(Keys.D3))
            {
                isoValue = 0;
                alphaValue = 0f;
                range = 0;

                volumetricModel.TransferPoints = new TransferControlPoints(4, 6);

                volumetricModel.TransferPoints.AddRGBControlPoint(Color.Blue, 0);
                volumetricModel.TransferPoints.AddRGBControlPoint(Color.Blue, 58);
                volumetricModel.TransferPoints.AddRGBControlPoint(Color.Red, 62);
                volumetricModel.TransferPoints.AddRGBControlPoint(Color.Red, 255);

                volumetricModel.TransferPoints.AddAlphaControlPoint(0f, 0);
                volumetricModel.TransferPoints.AddAlphaControlPoint(0f, 28);
                volumetricModel.TransferPoints.AddAlphaControlPoint(0.03f, 32);
                volumetricModel.TransferPoints.AddAlphaControlPoint(0.02f, 130);
                volumetricModel.TransferPoints.AddAlphaControlPoint(0.1f, 135);
                volumetricModel.TransferPoints.AddAlphaControlPoint(0.1f, 255);

                volumetricModel.CreateTransferFunction();
            }
        }
        public VolumetricRendererGame()
        {
            Debug.OnAssert += new EventHandler<DebugEventArgs>(HandleAssert);
            //Debug.BlockAfterAssert = true;

            // Set up and run initial threads.
            //mainThread = Thread.CurrentThread;
            //mainThread.Name = "Main";

            //updateLock = new object();
            //updateThread = new Thread(new ThreadStart(UpdateThread));
            //updateThread.Name = "Update";
            //updateThread.IsBackground = true;
            //updateThread.Start();

            //drawLock = new object();
            //drawThread = new Thread(new ThreadStart(DrawThread));
            //drawThread.Name = "Draw";
            //drawThread.IsBackground = true;
            //drawThread.Start();

            // Set up the game.
            updateMethod = Update_Normal;
            drawMethod = Draw_Normal;
            assertHandled = false;

            Content.RootDirectory = "Content";

            graphicsDM = new GraphicsDeviceManager(this);
            graphicsDM.PreferredBackBufferWidth = 1280;
            graphicsDM.PreferredBackBufferHeight = 960;
            graphicsDM.PreferMultiSampling = false;
            graphicsDM.SynchronizeWithVerticalRetrace = false;
            graphicsDM.IsFullScreen = false;

            input = new InputState();
            screenManager = new ScreenManager(this, input);
            Components.Add(screenManager);

            IsMouseVisible = true;
        }