/// <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() { TerrainChunk.CalculateIndices(); _defaultRasterizerState = GraphicsDevice.RasterizerState; _treeRasterizerState = new RasterizerState() { CullMode = CullMode.None }; _oldMouseState = Mouse.GetState(); _oldKeyboardState = Keyboard.GetState(); int worldSeed = 0; NoiseProvider mainNoiseProvider = new NoiseProvider(worldSeed, 4, 0.2f, 200); NoiseProvider modulationNoiseProvider = new NoiseProvider(worldSeed + 1, 2, 0.2f, 600); DirectionLight light = new DirectionLight(Vector3.Normalize(new Vector3(0, -0.3f, 1)), 1, 0.1f, 64); NoiseProvider decorNoiseProvider = new NoiseProvider(worldSeed + 2, 2, 0.2f, 200); _world = new World(GraphicsDevice, new TerrainHeightProvider(mainNoiseProvider, modulationNoiseProvider), light, decorNoiseProvider); Matrix cameraProjectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(60), GraphicsDevice.Viewport.AspectRatio, 1, World.ChunkRenderDistance); _camera = new Camera() { ProjectionMatrix = cameraProjectionMatrix }; _spriteBatch = new SpriteBatch(GraphicsDevice); _waterTileScaleMatrix = Matrix.CreateScale(TerrainChunk.EdgeLength); _mouseLookActive = true; _waterRefractionMapRenderTarget = new RenderTarget2D(GraphicsDevice, WaterMapSize, WaterMapSize, false, SurfaceFormat.Color, DepthFormat.Depth24); _waterReflectionMapRenderTarget = new RenderTarget2D(GraphicsDevice, WaterMapSize, WaterMapSize, false, SurfaceFormat.Color, DepthFormat.Depth24); _terrainChunkIndexBuffer = new IndexBuffer(GraphicsDevice, typeof(ushort), TerrainChunk.Indices.Length, BufferUsage.WriteOnly); _terrainChunkIndexBuffer.SetData(TerrainChunk.Indices); base.Initialize(); }