Esempio n. 1
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            spriteFont = Content.Load<SpriteFont>(@"Fonts\DemoFont");

            // Setup terrain.

            terrain = new Terrain(GraphicsDevice, Content);

            //terrain.AddTextureHeightRegion(0.0f, 300.0f, @"Textures\region1", @"Textures\region1_nmap");
            //terrain.AddTextureHeightRegion(301.0f, 501.0f, @"Textures\region2", @"Textures\region2_nmap");
            //terrain.AddTextureHeightRegion(502.0f, 802.0f, @"Textures\region3", @"Textures\region3_nmap");
            //terrain.AddTextureHeightRegion(803.0f, 1024.0f, @"Textures\region4", @"Textures\region4_nmap");

            List<TextureHeightRegionDTO> textureHeightRegionDTOs = new List<TextureHeightRegionDTO>() {
                new TextureHeightRegionDTO(){min = 0.0f, max = 300.0f, colorMapAssetName = @"Textures\region1", normalMapAssetName = @"Textures\region1_nmap"},
                new TextureHeightRegionDTO(){min = 301.0f, max = 501.0f, colorMapAssetName = @"Textures\region2", normalMapAssetName = @"Textures\region2_nmap"},
                new TextureHeightRegionDTO(){min = 502.0f, max = 802.0f, colorMapAssetName = @"Textures\region3", normalMapAssetName = @"Textures\region3_nmap"},
                new TextureHeightRegionDTO(){min = 803.0f, max = 1024.0f, colorMapAssetName = @"Textures\region4", normalMapAssetName = @"Textures\region4_nmap"}
            };

            terrain.Create(512, 8, 0.0f, 1024.0f, textureHeightRegionDTOs);

            terrain.GenerateUsingDiamondSquareFractal(1.2f);

            terrain.SunlightDirection = Vector3.Down;
            terrain.SunlightColor = new Vector4(1.0f, 1.0f, 1.0f, 1.0f);
            terrain.TerrainAmbient = new Vector4(0.3f, 0.3f, 0.3f, 1.0f);
            terrain.TerrainDiffuse = new Vector4(0.7f, 0.7f, 0.7f, 1.0f);

            // Setup camera.

            camera.CurrentBehavior = Camera.Behavior.RealTimeStrategy;
            camera.Velocity = new Vector3(300.0f, 300.0f, 300.0f);
            camera.Acceleration = new Vector3(600.0f, 600.0f, 600.0f);

            camera.Perspective(85.0f, GraphicsDevice.Viewport.AspectRatio,
                1.0f, terrain.TerrainBoundingSphere.Radius * 4.0f);

            Vector3 cameraPos = new Vector3();
            cameraPos.X = terrain.TerrainSize / 2.0f;
            cameraPos.Z = terrain.TerrainSize * 0.75f;
            cameraPos.Y = terrain.TerrainHeightMap.HeightAt(cameraPos.X, cameraPos.Z) * 1.5f;

            camera.LookAt(cameraPos, terrain.TerrainCenter, Vector3.Up);
        }