public void GeneratePlanet() { if (Map != null) { Map.Dispose(); } Map = new Texture2D(Game.GraphicsDevice, Width, Height); Color[] data = new Color[Width * Height]; /* * double[,] heightmap = new DiamondSquare(RNG, Width, Height, 1, 0.7, true, false).GenerateHeightmap(); * //heightmap = HydraulicErosion(heightmap, 2); * double heightmapWidth = heightmap.GetUpperBound(0); * double heightmapHeight = heightmap.GetUpperBound(1); * double widthRatio = heightmapWidth / (double)Width; * double heightRatio = heightmapHeight / (double)Height; */ int baseHeight = -500; int altitudeScale = 2500; int latitudeBonus = -1000; int sealevel = 0;// RNG.Next(-10000, 10000); ProceduralHeightmap planet = new ProceduralHeightmap(Width, Height, baseHeight, altitudeScale, 0.65, 0.1, true, false, false); //ProceduralPlanet planet = new ProceduralPlanet(Width, Height, baseHeight, altitudeScale, 0.65, 0.1); planet.Generate(RNG); for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { /* * int x2 = (int)Math.Round((x) * widthRatio); * int y2 = (int)Math.Round((y) * heightRatio); */ double latitude = (double)Math.Abs(y * 2 - Height) / Height; double altitude = baseHeight + planet.GetAltitude(x, y) + latitude * latitudeBonus; double temperature = 30 - 70 * latitude * latitude - 0.01 * altitude; if (altitude > sealevel) { if (temperature > -0) { if (altitude > 2000) { data[x + y * Width] = Color.SlateGray * (float)((altitude + altitudeScale) / (altitudeScale * 2)); } //else if (altitude > 3000) // data[x + y * Width] = Color.BurlyWood * (float)((altitude + altitudeScale) / (altitudeScale * 2)); //else if (altitude > 1000) // data[x + y * Width] = Color.YellowGreen * (float)((altitude + altitudeScale) / (altitudeScale * 2)); //else if (altitude < 100) // data[x + y * Width] = Color.SandyBrown * (float)((altitude + altitudeScale) / (altitudeScale * 2)); else { data[x + y * Width] = Color.ForestGreen * (float)((altitude + altitudeScale) / (altitudeScale * 2)); } } else { data[x + y * Width] = Color.Snow * (float)((altitude + altitudeScale) / (altitudeScale * 2)); } } else { //if (altitude > -1000 && temperature > 20) // data[x + y * Width] = Color.DarkCyan * (float)((altitude + altitudeScale) / (altitudeScale)); //else if (temperature > 0) if (temperature > -0) { data[x + y * Width] = Color.Navy * (float)((altitude + altitudeScale) / (altitudeScale)); } else { //data[x + y * Width] = Color.DarkCyan * (float)((altitude / 2 + altitudeScale) / (altitudeScale)); data[x + y * Width] = Color.Snow * (float)((altitude + altitudeScale) / (altitudeScale * 2)); } } } } for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { data[x + y * Width] = ColorExtensions.Average(GetColors(data, x, y)); } } Map.SetData(data); }