public void Generate(ProgressBar progress, int type) { progress.Value = 40; MapHeights heights = MapHeights.creates[type](Width, Height); progress.Value = 70; int[,] distribution = Utilites.DFS <double>(heights.Map, (double a) => { return(a < Water.seaLevel); }); progress.Value = 80; MapNormals normals = new MapNormals(heights); progress.Value = 90; initLight(); progress.Value = 92; initCells(new Size(Form1.CELL_SIZE, Form1.CELL_SIZE), heights, normals, Light, distribution); Light.FirstPass(); progress.Value = 95; }
public static MapHeights createSeabed(int w, int h) { MapHeights perlin = MapHeights.createPerlinNoise(w, h, (double)((int)(100000f / Form1.CELL_SIZE)) / 100000f, 20, 2); perlin.normalize(-1, -.6); perlin.Smooth(-1, -.6, 8); perlin.Smooth(-1, -.8, 5); return(perlin); }
public static MapHeights createHills(int w, int h) { MapHeights perlin = MapHeights.createPerlinNoise(w, h, (double)((int)(100000f / Form1.CELL_SIZE)) / 100000f, 5, 35); perlin.SimpleTransform(1); perlin.Smooth(0, .1, 8); perlin.Smooth(0, .2, 2); perlin.normalizeWithExtention(-.1, .38, .9); return(perlin); }
public static MapHeights createPlains(int w, int h) { MapHeights perlin = MapHeights.createPerlinNoise(w, h, (double)((int)(100000f / Form1.CELL_SIZE)) / 100000f, 10, 2); perlin.normalize(-.2, .3); perlin.Smooth(-.2, .3, 7); perlin.Smooth(.1, .3, 5); perlin.Smooth(-.2, .1, 3); perlin.Loosening(-.2, .3, 0.009, 1); return(perlin); }
public static MapHeights createLandscape(int w, int h) { MapHeights landscape; MapHeights mountains = createMountains(w, h); MapHeights hills = createHills(w, h); int[,] heights = Utilites.DFS <double>(mountains.Map, (double a) => { return(a < .3); }); mountains = createUnion( false, (int i, int j, MapHeights[] maps) => { if (heights[i, j] > 0) { return((maps[0][i, j] * (.3 - maps[1][i, j]) + maps[1][i, j] * (.5 + maps[1][i, j])) * 10f / 8f); } else { return(maps[1][i, j]); } }, hills, mountains); Bitmap layoutM = new Bitmap(Bitmap.FromFile(@"C:\Users\Роман\source\repos\World\World\images\layout_mountains.bmp"), mountains.Width, mountains.Height); MapHeights plains = createPlains(w, h); landscape = createUnion( false, (int i, int j, MapHeights[] maps) => { double intensive = (layoutM.GetPixel(i, j).R / 255f); return(maps[0][i, j] * intensive + maps[1][i, j] * (1 - intensive)); }, plains, mountains); MapHeights seabed = createSeabed(w, h); Bitmap layoutS = new Bitmap(Bitmap.FromFile(@"C:\Users\Роман\source\repos\World\World\images\layout_sea.bmp"), seabed.Width, seabed.Height); landscape = createUnion( false, (int i, int j, MapHeights[] maps) => { double intensive = 1 - (layoutS.GetPixel(i, j).R / 255f); return(maps[0][i, j] * intensive + maps[1][i, j] * (1 - intensive)); }, seabed, landscape); landscape.max = 1; landscape.min = -1; //landscape.postprocessing(); return(landscape); }
public static MapHeights createArchipelago(int w, int h) { MapHeights m1 = MapHeights.createDiamondSquare(w, h, 0.08); MapHeights m2 = MapHeights.createPerlinNoise(w, h, (double)((int)(100000f / Form1.CELL_SIZE)) / 100000, 5, 9); MapHeights heights = MapHeights.createUnion( true, (int i, int j, MapHeights[] m) => { return(m[0][i, j] + m[1][i, j] * (1 + m[0][i, j]) / 1.9f); }, m2, m1); heights.postprocessing(); heights.normalizeWithExtention(-1, 1, 0.98); return(heights); }
private void initCells(Size cellSize, MapHeights heights, MapNormals normals, Lighting light, int[,] distribution) { for (int i = 0; i < Width; i++) { for (int j = 0; j < Height; j++) { if (Map[i, j] == null) { Map[i, j] = new Cell(i, j, cellSize); } for (int k = 0; k < cellSize.Width; k++) { for (int s = 0; s < cellSize.Height; s++) { int x = Map[i, j].Location.X + k; int y = Map[i, j].Location.Y + s; int cx = i * cellSize.Width + k; int cy = j * cellSize.Height + s; switch (distribution[cx, cy] == 0 ? Cell.Element.GROUND : Cell.Element.WATER) { case Cell.Element.WATER: Map[i, j][k, s] = new Cell.Property( new Water(x, y, heights[cx, cy]), new Normal(x, y, normals[cx, cy])); break; case Cell.Element.GROUND: Map[i, j][k, s] = new Cell.Property( new Ground(x, y, heights[cx, cy], normals[cx, cy]), new Normal(x, y, normals[cx, cy])); break; } if (Map[i, j][k, s].Height is IBrightness) { light.Add((IBrightness)Map[i, j][k, s].Height); } } } } } }
public static MapHeights createMountains(int w, int h) { MapHeights perlin = MapHeights.createPerlinNoise(w, h, (double)((int)(100000f / Form1.CELL_SIZE)) / 100000, 10, 25); MapHeights diamond = MapHeights.createDiamondSquare(w, h, .9); perlin.normalizeWithExtention(0, 1, .95); diamond.normalizeWithExtention(-.1, .4, .95); MapHeights union = createUnion( true, (int i, int j, MapHeights[] maps) => { return(maps[0][i, j] + maps[1][i, j] * (maps[0][i, j] + 1.1) / 2.1f); }, perlin, diamond); union.SimpleTransform(1); union.Loosening(0.4, 1, 0.03, 1); union.Loosening(0.7, 1, 0.08, 2); union.Smooth(0.4, 1, 1); union.normalizeWithExtention(-.5, 1, .97); return(union); }
public MapNormals(MapHeights heights) : this(heights.Width, heights.Height, heights.Map) { }
public MapShadows(int width, int height, MapHeights heights, LightSource source) : base(width, height) { this.heights = heights; this.source = source; }