public static GenerateNoiseMap ( int mapWidth, int mapHeight, float scale ) : ].float[ | ||
mapWidth | int | |
mapHeight | int | |
scale | float | |
return | ].float[ |
public static float[,] GenerateNoiseMap(int mapWidth, int mapHeight, float scale) {
float[,] noiseMap = new float[mapWidth,mapHeight];
if (scale <= 0) {
scale = 0.0001f;
}
for (int y = 0; y < mapHeight; y++) {
for (int x = 0; x < mapWidth; x++) {
float sampleX = x / scale;
float sampleY = y / scale;
float perlinValue = Mathf.PerlinNoise (sampleX, sampleY);
noiseMap [x, y] = perlinValue;
}
}
return noiseMap;
}
Noise::GenerateNoiseMap ( int mapWidth, int mapHeight, int seed, float scale, int octaves, float persistance, float lacunarity, Vector2 offset ) : ].float[ | |
Noise::GenerateNoiseMap ( int mapWidth, int mapHeight, int seed, float scale, int octaves, float persistance, float lacunarity, Vector2 offset, NormalizeMode normalizeMode ) : ].float[ |
public void GenerateMap() { float[,] noiseMap = Noise.GenerateNoiseMap(mapWidth, mapHeight, seed, noiseScale, octaves, persistance, lacunarity, offset); Color[] colorMap = new Color[mapWidth * mapHeight]; for (int y = 0; y < mapHeight; y++) { for (int x = 0; x < mapWidth; x++) { float currentHeight = noiseMap[x, y]; for (int i = 0; i < regions.Length; i++) { if (currentHeight <= regions[i].height) { colorMap[y * mapWidth + x] = regions[i].color; break; } } } } MapDisplayScr display = GetComponent <MapDisplayScr>(); if (dMode == DrawMode.NoiseMap) { display.DrawTexture(TextureGenerator.TextureFromHeightMap(noiseMap)); } else if (dMode == DrawMode.ColorMap) { display.DrawTexture(TextureGenerator.TextureFromColorMap(colorMap, mapWidth, mapHeight)); } else if (dMode == DrawMode.Mesh) { display.DrawMesh(MeshGenerator.GenerateTerrainMesh(noiseMap, meshHeightMultiplier, animationCurve), TextureGenerator.TextureFromColorMap(colorMap, mapWidth, mapHeight)); } }