/// <summary> /// Generate a white noise <see cref="HeightMap"/> /// </summary> public override HeightMap Generate() { var maxLength = Math.Max(Dimensions.Height, Dimensions.Width); var noise = new DiamondSquareNoise(Seed); var result = noise.Generate(maxLength, RandomnessFactor); var resizedResult = MathHelper.Copy(result, Dimensions.Height, Dimensions.Width); var map = new HeightMap(resizedResult); return(map); }
public HeightMap(bool pPerlin, int pSize) { _size = pSize; if (pPerlin) { var n = new PerlinNoise(pSize); _map = n.Generate(4, .7f, .4f, .3f, .1f); } else { var n = new DiamondSquareNoise(pSize); _map = n.Generate(0, 5, .5f); float maxHeight = 0; float maxDepth = 1; for (int x = 0; x < pSize; x++) { for (int y = 0; y < pSize; y++) { if (_map[x, y] > maxHeight) { maxHeight = _map[x, y]; } if (_map[x, y] < maxDepth) { maxDepth = _map[x, y]; } } } //Scale all points so they are within max/min maxDepth = Math.Abs(maxDepth); for (int x = 0; x < pSize; x++) { for (int y = 0; y < pSize; y++) { if (_map[x, y] < 0) { _map[x, y] = _map[x, y] / maxDepth; } else if (_map[x, y] > 0) { _map[x, y] = _map[x, y] / maxHeight; } } } } }