public Mountains(int seed, int width, int height, int minMountainRadius, int maxMountainRadius, int minMuntainDistance, int numSamplesBeforeAbort) : base(seed, width, height) { noiseMap = new float[width * height]; float side = minMountainRadius / (float)Math.Sqrt(2); List <Vector2> points = PoissonSample.GeneratePoints(Random, minMuntainDistance, new Vector2(width, height), numSamplesBeforeAbort); for (int i = 0; i < points.Count; i++) { int cx = (int)points[i].X; int cy = (int)points[i].Y; int rnd = Random.Next(minMountainRadius, maxMountainRadius); int buildStartX = Math.Max(0, cx - rnd); int buildEndX = Math.Min(width, cx + rnd); int buildStartY = Math.Max(0, cy - rnd); int buildEndY = Math.Min(height, cy + rnd); int center = Math.Min((buildStartX + buildEndX) / 2 - buildStartX, (buildStartY + buildEndY) / 2 - buildStartY); float MountainHeight = (float)Random.NextDouble(); float h = 0f; for (int c = 0; c < center; c++) { h += MountainHeight / center * 2; for (int y = buildStartY + c; y < buildEndY - c; y++) { for (int x = buildStartX + c; x < buildEndX - c; x++) { noiseMap[y * width + x] = h; } } } } }
public Planet(int id, int seed, GraphicsDeviceManager graphics, PlanetTypes planetType, PlanetSizes planetSize) { Id = id; PlanetType = planetType; PlanetSize = planetSize; ChunksWidth = PlanetSizeDImensions[(int)planetSize][0]; ChunksHeight = PlanetSizeDImensions[(int)planetSize][1]; CellsWidth = ChunksWidth * CHUNK_WIDTH; CellsHeight = ChunksHeight * CHUNK_HEIGHT; noiseGenerator = new NoiseGenerator(planetType, seed, CellsWidth, CellsHeight); Map = new Map.Map(id, seed, ChunksWidth, ChunksHeight, noiseGenerator, graphics, planetType); List <Vector2> greens = PoissonSample.GeneratePoints(new Random(seed), 15, new Vector2(CellsWidth, CellsHeight)); List <Vector2> blues = PoissonSample.GeneratePoints(new Random(seed), 20, new Vector2(CellsWidth, CellsHeight)); List <Vector2> reds = PoissonSample.GeneratePoints(new Random(seed), 25, new Vector2(CellsWidth, CellsHeight)); for (int i = 0; i < greens.Count; i++) { Structures.Add(new Ore(GetCellAtPosition(greens[i]), Ore.OreTypes.Green)); } for (int i = 0; i < blues.Count; i++) { Structures.Add(new Ore(GetCellAtPosition(blues[i]), Ore.OreTypes.Blue)); } for (int i = 0; i < reds.Count; i++) { Structures.Add(new Ore(GetCellAtPosition(reds[i]), Ore.OreTypes.Red)); } }
public MergeCandidate(PoissonSample s, int src) { sample = s; sourceDist = src; }
private static void MakeProgressive(ref List<PoissonSample> distribution) { if (distribution.Count < 2) return; distribution.Sort(); // PossionSample implements IComparable #region fix equal-ranking samples by random interleaving Random random = new Random(); for (int i = 0; i < distribution.Count; i++) { int rankingFixStart = i; float ranking = distribution[i].ranking; while (i + 1 < distribution.Count && distribution[i + 1].ranking == ranking) { i++; } if (rankingFixStart < i) { int fixLength = i - rankingFixStart + 1; int[] shuffle = new int[fixLength]; for (int j = 0; j < fixLength; j++) shuffle[j] = rankingFixStart + j; for (int j = 0; j < fixLength; j++) { int a = random.Next(fixLength); int b = random.Next(fixLength); if (a == b) continue; int aux = shuffle[a]; shuffle[a] = shuffle[b]; shuffle[b] = aux; } PoissonSample[] interleavedSamples = new PoissonSample[fixLength]; for (int j = 0; j < fixLength; j++) { interleavedSamples[j] = distribution[shuffle[j]]; } for (int j = 0; j < fixLength; j++) { distribution[rankingFixStart + j] = interleavedSamples[j]; } } } for (int i = 0; i < distribution.Count; i++) distribution[i].ranking = (float)i / distribution.Count; #endregion #region fix seam-neighbors const float alpha = 0.5f; for (int i = 2; i < distribution.Count - 1; i++) { int j = i; float threshold = alpha * (float)Math.Sqrt(i); for (; j < distribution.Count - 1; j++) { float d = float.MaxValue; for (int k = 0; k < i; k++) { float dist = distribution[j].DistSquared(distribution[k]); if (dist < d) { d = dist; } } if ((float)Math.Sqrt(d) > threshold) break; } if (j != i) { PoissonSample aux = distribution[i]; distribution[i] = distribution[j]; distribution[j] = aux; } } #endregion }
private static void MakeProgressive(ref List <PoissonSample> distribution) { if (distribution.Count < 2) { return; } distribution.Sort(); // PossionSample implements IComparable #region fix equal-ranking samples by random interleaving Random random = new Random(); for (int i = 0; i < distribution.Count; i++) { int rankingFixStart = i; float ranking = distribution[i].ranking; while (i + 1 < distribution.Count && distribution[i + 1].ranking == ranking) { i++; } if (rankingFixStart < i) { int fixLength = i - rankingFixStart + 1; int[] shuffle = new int[fixLength]; for (int j = 0; j < fixLength; j++) { shuffle[j] = rankingFixStart + j; } for (int j = 0; j < fixLength; j++) { int a = random.Next(fixLength); int b = random.Next(fixLength); if (a == b) { continue; } int aux = shuffle[a]; shuffle[a] = shuffle[b]; shuffle[b] = aux; } PoissonSample[] interleavedSamples = new PoissonSample[fixLength]; for (int j = 0; j < fixLength; j++) { interleavedSamples[j] = distribution[shuffle[j]]; } for (int j = 0; j < fixLength; j++) { distribution[rankingFixStart + j] = interleavedSamples[j]; } } } for (int i = 0; i < distribution.Count; i++) { distribution[i].ranking = (float)i / distribution.Count; } #endregion #region fix seam-neighbors const float alpha = 0.5f; for (int i = 2; i < distribution.Count - 1; i++) { int j = i; float threshold = alpha * (float)Math.Sqrt(i); for (; j < distribution.Count - 1; j++) { float d = float.MaxValue; for (int k = 0; k < i; k++) { float dist = distribution[j].DistSquared(distribution[k]); if (dist < d) { d = dist; } } if ((float)Math.Sqrt(d) > threshold) { break; } } if (j != i) { PoissonSample aux = distribution[i]; distribution[i] = distribution[j]; distribution[j] = aux; } } #endregion }