Esempio n. 1
0
        protected override void Update(GameTime gameTime)
        {
            keyboardState = Keyboard.GetState();

            if (keyboardState.IsKeyDown(Keys.Escape))
            {
                this.Exit();
            }

            if (IsKeyTyped(Keys.F1))
            {
                ChangeTerrain(TerrainType.Quadtree);
            }

            if (IsKeyTyped(Keys.F2))
            {
                ChangeTerrain(TerrainType.GeoMipMap);
            }

            if (IsKeyTyped(Keys.F3))
            {
                ChangeTerrain(TerrainType.ROAM);
            }

            if (IsKeyTyped(Keys.D0))
            {
                ToggleFullscreen();
            }

            if (IsKeyTyped(Keys.Tab))
            {
                ToggleFillMode();
            }

            if (IsKeyTyped(Keys.G))
            {
                terrain.GeomorphEnabled = !terrain.GeomorphEnabled;
            }

            if (IsKeyTyped(Keys.H))
            {
                terrain.HeightmapEnabled = !terrain.HeightmapEnabled;
            }

            if (IsKeyTyped(Keys.T))
            {
                terrain.TextureEnabled = !terrain.TextureEnabled;
            }

            if (IsKeyTyped(Keys.L))
            {
                terrain.LightEnabled = !terrain.LightEnabled;
            }

            if (IsKeyTyped(Keys.B))
            {
                terrain.BruteForceEnabled = !terrain.BruteForceEnabled;
            }

            if (IsKeyTyped(Keys.F))
            {
                terrain.FrustumCullingEnabled = !terrain.FrustumCullingEnabled;
            }

            if (IsKeyTyped(Keys.O))
            {
                fakeCamera = !fakeCamera;
            }

            if (IsKeyTyped(Keys.C))
            {
                GC.Collect();
            }

            if (IsKeyTyped(Keys.I))
            {
                hud.Visible = !hud.Visible;
            }

            if (IsKeyTyped(Keys.D1))
            {
                terrain.LoadHeightmap("Heightmaps/Heightmap1");
            }

            if (IsKeyTyped(Keys.D2))
            {
                terrain.LoadHeightmap("Heightmaps/Heightmap2");
            }

            if (IsKeyTyped(Keys.D3))
            {
                terrain.LoadHeightmap("Heightmaps/Heightmap3");
            }

            if (IsKeyTyped(Keys.D4))
            {
                terrain.LoadHeightmap("Heightmaps/Heightmap4");
            }

            if (IsKeyTyped(Keys.D5))
            {
                terrain.LoadHeightmap("Heightmaps/PugetSound");
                terrain.LoadTexture("Textures/PugetSound");
                terrain.TextureResolution = 1;
                terrain.Bumpiness         = 100;
            }

            if (IsKeyTyped(Keys.D6))
            {
                terrain.LoadTexture("Textures/Rock");
            }

            if (IsKeyTyped(Keys.D7))
            {
                terrain.LoadTexture("Textures/Sand");
            }

            if (IsKeyTyped(Keys.D8))
            {
                terrain.LoadTexture("Textures/Desert");
            }

            if (IsKeyTyped(Keys.D9))
            {
                terrain.LoadTexture("Textures/Grass");
            }

            if (IsKeyTyped(Keys.F10))
            {
                terrain.Bumpiness += 10.0f;
            }

            if (IsKeyTyped(Keys.F9))
            {
                terrain.Bumpiness -= 10.0f;
            }

            if (IsKeyTyped(Keys.F12))
            {
                terrain.TextureResolution *= 2.0f;
            }

            if (IsKeyTyped(Keys.F11))
            {
                terrain.TextureResolution *= 0.5f;
            }

            if (IsKeyTyped(Keys.OemPlus))
            {
                terrain.Quality *= 2.0f;
            }

            if (IsKeyTyped(Keys.OemMinus))
            {
                terrain.Quality /= 2.0f;
            }

            previousKeyboardState = keyboardState;

            base.Update(gameTime);

            if (!fakeCamera)
            {
                fakeCameraPosition     = camera.Position;
                fakeViewFrustum.Matrix = camera.ViewFrustum.Matrix;
            }

            terrain.ViewFrustum    = fakeViewFrustum;
            terrain.CameraPosition = fakeCameraPosition;

            terrain.Update(gameTime);

            hud.FPS       = (int)Math.Round(fps.FrameRate);
            hud.Size      = terrain.Size;
            hud.Quality   = terrain.Quality;
            hud.DrawCalls = terrain.DrawCalls;
            hud.Triangles = terrain.Triangles;
            hud.Bumpiness = terrain.Bumpiness;

            switch (terrain.GetTerrainType())
            {
            case TerrainType.Basic: hud.Method = "Basic"; break;

            case TerrainType.GeoMipMap: hud.Method = "GeoMipMap"; break;

            case TerrainType.Quadtree: hud.Method = "Roettger"; break;

            case TerrainType.ROAM: hud.Method = "ROAM"; break;
            }
        }