public void LoadGenerationData(int width, int height) { heightData = new MapData(width, height); for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { float x1 = x / (float)width; float y1 = y / (float)height; float value = (float)heightMap.Get(x1, y1); if (value > heightData.Max) { heightData.Max = value; } if (value < heightData.Min) { heightData.Min = value; } //normalize value between 0-1 value = (value - heightData.Min) / (heightData.Max - heightData.Min); heightData.Data [x, y] = value; } } }
public ChunkData GetChunkData(Chunk chunk) { ChunkData chunkData = new ChunkData(chunk.ChunkSize, chunk.ChunkSize); for (int y = 0; y < chunkData.Data.GetLength(1); y++) { for (int x = 0; x < chunkData.Data.GetLength(0); x++) { float x1 = ((float)chunk.Position.X + (float)x) / (float)chunkData.Data.GetLength(0); float y1 = ((float)chunk.Position.Y + (float)y) / (float)chunkData.Data.GetLength(1); float value = (float)heightMap.Get(x1, y1); if (value > chunkData.Max) { chunkData.Max = value; } if (value < chunkData.Min) { chunkData.Min = value; } //normalize value between 0 and 1 value = (value - chunkData.Min) / (chunkData.Max - chunkData.Min); chunkData.Data [x, y] = value; } } return(chunkData); }
// Extract data from a noise module private void GetData(ImplicitModuleBase module, ref MapData mapData) { mapData = new MapData(Width, Height); // loop through each x,y point - get height value for (var x = 0; x < Width; x++) { for (var y = 0; y < Height; y++) { //Sample the noise at smaller intervals float x1 = x / (float)Width; float y1 = y / (float)Height; float value = (float)HeightMap.Get(x1, y1); //keep track of the max and min values found if (value > mapData.Max) { mapData.Max = value; } if (value < mapData.Min) { mapData.Min = value; } mapData.Data[x, y] = value; } } }
public MapData GetFractalData(ImplicitFractal fractal) { var mapData = new MapData(_width, _height); for (var x = 0; x < _width; x++) { for (var y = 0; y < _height; y++) { var s = 0 + x / (float)_width; var t = 0 + y / (float)_height; var heightValue = (float)fractal.Get(s, t); if (heightValue > mapData.Max) { mapData.Max = heightValue; } if (heightValue < mapData.Min) { mapData.Min = heightValue; } mapData.Data[y * _width + x] = heightValue; } } return(mapData); }
public override void GetData() { HeightData = new MapData(Width, Height); HeatData = new MapData(Width, Height); MoistureData = new MapData(Width, Height); // loop through each x,y point - get height value for (int x = 0; x < Width; x++) { for (int y = 0; y < Height; y++) { // Sample noise at smaller intervals float x1 = x / (float)Width; float y1 = y / (float)Height; float heightValue = (float)HeightMap.Get(x1, y1); float heatValue = (float)HeatMap.Get(x1, y1); float moistureValue = (float)MoistureMap.Get(x1, y1); // keep track of the max and min values found if (heightValue > HeightData.Max) { HeightData.Max = heightValue; } if (heightValue < HeightData.Min) { HeightData.Min = heightValue; } if (heatValue > HeatData.Max) { HeatData.Max = heatValue; } if (heatValue < HeatData.Min) { HeatData.Min = heatValue; } if (moistureValue > MoistureData.Max) { MoistureData.Max = moistureValue; } if (moistureValue < MoistureData.Min) { MoistureData.Min = moistureValue; } HeightData.Data[x, y] = heightValue; HeatData.Data[x, y] = heatValue; MoistureData.Data[x, y] = moistureValue; } } }
public static Texture2D GetNoiseTex(int width, int length, float val, int oct, float frec) { ImplicitFractal treeFract = new ImplicitFractal(FractalType.MULTI, BasisType.SIMPLEX, InterpolationType.QUINTIC, oct, frec, Random.Range(0, int.MaxValue)); double min = double.MaxValue; double max = double.MinValue; double[,] arr = new double[width, length]; for (int x = 0; x < width; x++) { for (int y = 0; y < length; y++) { double n = treeFract.Get(x, y); arr[x, y] = n; if (n < min) { min = n; } if (n > max) { max = n; } } } Texture2D treeNoiseTex = new Texture2D(width, length); Color[] pixels = new Color[width * length]; for (int x = 0; x < width; x++) { for (int y = 0; y < length; y++) { double n = (arr[x, y] - min) / (max - min); if (n < val) { pixels[x + y * width] = Color.green; } else { pixels[x + y * width] = Color.black; } } } treeNoiseTex.SetPixels(pixels); treeNoiseTex.wrapMode = TextureWrapMode.Clamp; treeNoiseTex.Apply(); return(treeNoiseTex); }
public Grid <float> GenerateAnomalyMap(int mapLength, int mapWidth, int seed = -1) { if (seed == -1) { seed = Random.Range(0, int.MaxValue); } var lengthSample = mapLength * SampleModifier; var widthSample = mapWidth * SampleModifier; var anomalyMap = new Grid <float>(mapLength, mapWidth); var anomalyGenerator = new ImplicitFractal( anomalyFractalType, BasisType.Simplex, InterpolationType.Quintic, anomalyOctaves, anomalyFrequency, anomalyLacunarity) { Seed = seed }; var secondaryGenerator = new ImplicitFractal( FractalType.FractionalBrownianMotion, BasisType.Simplex, InterpolationType.Quintic, 2, anomalyFrequency * 0.7D, .9f) { Seed = seed }; anomalyMap.ForEachSet((x, y) => { // Сэмплируем шум с небольшими интервалами // Координаты шума будут не рядом, а на расстоянии (1/worldXXX) var s = x * lengthSample / (float)mapLength; var t = y * widthSample / (float)mapWidth; float nx, ny, nz, nw; SphereCoordinates(out nx, out ny, out nz, out nw, s, t); var value = (float)anomalyGenerator.Get(nx, ny, nz, nw); value = value * 0.5f + 0.5f; var secondaryValue = (float)secondaryGenerator.Get(s, t); secondaryValue = secondaryValue * 0.5f + 0.5f; return(value * secondaryValue); }); return(anomalyMap); }
protected override void GetData() { heightData = new MapData(width, height); heatData = new MapData(width, height); moistureData = new MapData(width, height); // Get height data for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { // Noise range float x1 = 0, x2 = 1; float y1 = 0, y2 = 1; float dx = x2 - x1; float dy = y2 - y1; // Get samples at smaller intervals float s = x / (float)width; float t = y / (float)height; // Calculate 4D coords float nx = x1 + Mathf.Cos(s * 2 * Mathf.PI) * dx / (2 * Mathf.PI); float ny = y1 + Mathf.Cos(t * 2 * Mathf.PI) * dy / (2 * Mathf.PI); float nz = x1 + Mathf.Sin(s * 2 * Mathf.PI) * dx / (2 * Mathf.PI); float nw = y1 + Mathf.Sin(t * 2 * Mathf.PI) * dy / (2 * Mathf.PI); float heightValue = (float)heightMap.Get(nx, ny, nz, nw); float heatValue = (float)heatMap.Get(nx, ny, nz, nw); float moistureValue = (float)moistureMap.Get(nx, ny, nz, nw); // Keep track of the min/max values heightData.max = (heightValue > heightData.max) ? heightValue : heightData.max; heightData.min = (heightValue < heightData.min) ? heightValue : heightData.min; heatData.max = (heatValue > heatData.max) ? heatValue : heatData.max; heatData.min = (heatValue < heatData.min) ? heatValue : heatData.min; moistureData.max = (moistureValue > moistureData.max) ? moistureValue : moistureData.max; moistureData.min = (moistureValue < moistureData.min) ? moistureValue : moistureData.min; heightData.data [x, y] = heightValue; heatData.data [x, y] = heatValue; moistureData.data [x, y] = moistureValue; } } }
public Grid <float> GenerateLandscapeMap(int mapLength, int mapWidth, int seed = -1) { if (seed == -1) { seed = Random.Range(0, int.MaxValue); } var lengthSample = mapLength * SampleModifier; var widthSample = mapWidth * SampleModifier; var landscapeMap = new Grid <float>(mapLength, mapWidth); var landscapeGenerator = new ImplicitFractal( heightFractalType, BasisType.Simplex, InterpolationType.Quintic, 2, 2, 0.45D) { Seed = seed }; landscapeMap.ForEachSet((x, y) => { // Координаты шума будут не рядом, а на расстоянии (1/worldXXX) var xSample = x * lengthSample / (float)mapLength; var ySample = y * lengthSample / (float)mapWidth; var height = (float)landscapeGenerator.Get(xSample, ySample); // Перевод из -1 -- 1 в 0 -- 1 height = height * 0.5f + 0.5f; return(height); }); return(landscapeMap); }
// Extract data from a noise module private void GetData() { HeightData = new MapData(Width, Height); HeatData = new MapData(Width, Height); MoistureData = new MapData(Width, Height); // loop through each x,y point - get height value for (var x = 0; x < Width; x++) { for (var y = 0; y < Height; y++) { // WRAP ON BOTH AXIS // Noise range float x1 = 0, x2 = 2; float y1 = 0, y2 = 2; float dx = x2 - x1; float dy = y2 - y1; // Sample noise at smaller intervals float s = x / (float)Width; float t = y / (float)Height; // Calculate our 4D coordinates float nx = x1 + Mathf.Cos(s * 2 * Mathf.PI) * dx / (2 * Mathf.PI); float ny = y1 + Mathf.Cos(t * 2 * Mathf.PI) * dy / (2 * Mathf.PI); float nz = x1 + Mathf.Sin(s * 2 * Mathf.PI) * dx / (2 * Mathf.PI); float nw = y1 + Mathf.Sin(t * 2 * Mathf.PI) * dy / (2 * Mathf.PI); float heightValue = (float)HeightMap.Get(nx, ny, nz, nw); float heatValue = (float)HeatMap.Get(nx, ny, nz, nw); float moistureValue = (float)MoistureMap.Get(nx, ny, nz, nw); // keep track of the max and min values found if (heightValue > HeightData.Max) { HeightData.Max = heightValue; } if (heightValue < HeightData.Min) { HeightData.Min = heightValue; } if (heatValue > HeatData.Max) { HeatData.Max = heatValue; } if (heatValue < HeatData.Min) { HeatData.Min = heatValue; } if (moistureValue > MoistureData.Max) { MoistureData.Max = moistureValue; } if (moistureValue < MoistureData.Min) { MoistureData.Min = moistureValue; } HeightData.Data[x, y] = heightValue; HeatData.Data[x, y] = heatValue; MoistureData.Data[x, y] = moistureValue; } } }
protected override void GetData() { heightData = new MapData(width, height); heatData = new MapData(width, height); moistureData = new MapData(width, height); clouds1 = new MapData(width, height); clouds2 = new MapData(width, height); // Define our map area in latitude/longitude float southLatBound = -180; float northLatBound = 180; float westLonBound = -90; float eastLonBound = 90; float lonExtent = eastLonBound - westLonBound; float latExtent = northLatBound - southLatBound; float xDelta = lonExtent / (float)width; float yDelta = latExtent / (float)height; float curLon = westLonBound; float curLat = southLatBound; // Loop through each tile using its lat/long coordinates for (var x = 0; x < width; x++) { curLon = westLonBound; for (var y = 0; y < height; y++) { float x1 = 0, y1 = 0, z1 = 0; // Convert this lat/lon to x/y/z LatLonToXYZ(curLat, curLon, ref x1, ref y1, ref z1); // Heat data float sphereValue = (float)heatMap.Get(x1, y1, z1); if (sphereValue > heatData.max) { heatData.max = sphereValue; } if (sphereValue < heatData.min) { heatData.min = sphereValue; } heatData.data [x, y] = sphereValue; float coldness = Mathf.Abs(curLon) / 90f; float heat = 1 - Mathf.Abs(curLon) / 90f; heatData.data [x, y] += heat; heatData.data [x, y] -= coldness; // Height Data float heightValue = (float)heightMap.Get(x1, y1, z1); if (heightValue > heightData.max) { heightData.max = heightValue; } if (heightValue < heightData.min) { heightData.min = heightValue; } heightData.data [x, y] = heightValue; // Moisture Data float moistureValue = (float)moistureMap.Get(x1, y1, z1); if (moistureValue > moistureData.max) { moistureData.max = moistureValue; } if (moistureValue < moistureData.min) { moistureData.min = moistureValue; } moistureData.data [x, y] = moistureValue; // Cloud Data clouds1.data [x, y] = (float)cloud1Map.Get(x1, y1, z1); if (clouds1.data [x, y] > clouds1.max) { clouds1.max = clouds1.data [x, y]; } if (clouds1.data [x, y] < clouds1.min) { clouds1.min = clouds1.data [x, y]; } clouds2.data [x, y] = (float)cloud2Map.Get(x1, y1, z1); if (clouds2.data [x, y] > clouds2.max) { clouds2.max = clouds2.data [x, y]; } if (clouds2.data [x, y] < clouds2.min) { clouds2.min = clouds2.data [x, y]; } curLon += xDelta; } curLat += yDelta; } }
protected override void GetData() { HeightData = new MapData(Width, Height); HeatData = new MapData(Width, Height); MoistureData = new MapData(Width, Height); Clouds1 = new MapData(Width, Height); Clouds2 = new MapData(Width, Height); // Define our map area in latitude/longitude float southLatBound = -180; float northLatBound = 180; float westLonBound = -90; float eastLonBound = 90; float lonExtent = eastLonBound - westLonBound; float latExtent = northLatBound - southLatBound; float xDelta = lonExtent / (float)Width; float yDelta = latExtent / (float)Height; float curLon = westLonBound; float curLat = southLatBound; // Loop through each tile using its lat/long coordinates for (var x = 0; x < Width; x++) { curLon = westLonBound; for (var y = 0; y < Height; y++) { float x1 = 0, y1 = 0, z1 = 0; // Convert this lat/lon to x/y/z LatLonToXYZ(curLat, curLon, ref x1, ref y1, ref z1); // Heat data float sphereValue = (float)HeatMap.Get(x1, y1, z1); if (sphereValue > HeatData.Max) { HeatData.Max = sphereValue; } if (sphereValue < HeatData.Min) { HeatData.Min = sphereValue; } HeatData.Data [x, y] = sphereValue; float coldness = Mathf.Abs(curLon) / 90f; float heat = 1 - Mathf.Abs(curLon) / 90f; HeatData.Data [x, y] += heat; HeatData.Data [x, y] -= coldness; // Height Data float heightValue = (float)HeightMap.Get(x1, y1, z1); if (heightValue > HeightData.Max) { HeightData.Max = heightValue; } if (heightValue < HeightData.Min) { HeightData.Min = heightValue; } HeightData.Data [x, y] = heightValue; // Moisture Data float moistureValue = (float)MoistureMap.Get(x1, y1, z1); if (moistureValue > MoistureData.Max) { MoistureData.Max = moistureValue; } if (moistureValue < MoistureData.Min) { MoistureData.Min = moistureValue; } MoistureData.Data [x, y] = moistureValue; // Cloud Data Clouds1.Data[x, y] = (float)Cloud1Map.Get(x1, y1, z1); if (Clouds1.Data[x, y] > Clouds1.Max) { Clouds1.Max = Clouds1.Data[x, y]; } if (Clouds1.Data[x, y] < Clouds1.Min) { Clouds1.Min = Clouds1.Data[x, y]; } Clouds2.Data[x, y] = (float)Cloud2Map.Get(x1, y1, z1); if (Clouds2.Data[x, y] > Clouds2.Max) { Clouds2.Max = Clouds2.Data[x, y]; } if (Clouds2.Data[x, y] < Clouds2.Min) { Clouds2.Min = Clouds2.Data[x, y]; } curLon += xDelta; } curLat += yDelta; } }
// Extract data from a noise module private void GetData() { _heightData = new MapData(_height, _width); _heatData = new MapData(_height, _width); _moistureData = new MapData(_height, _width); // loop through each x,y point - get height value for (var x = 0; x < _height; x++) { for (var y = 0; y < _width; y++) { // WRAP ON BOTH AXIS // Noise range float x1 = 0, x2 = 2; float y1 = 0, y2 = 2; var dx = x2 - x1; var dy = y2 - y1; // Sample noise at smaller intervals var s = x / (float)_height; var t = y / (float)_width; // Calculate our 4D coordinates var nx = x1 + Mathf.Cos(s * 2 * Mathf.PI) * dx / (2 * Mathf.PI); var ny = y1 + Mathf.Cos(t * 2 * Mathf.PI) * dy / (2 * Mathf.PI); var nz = x1 + Mathf.Sin(s * 2 * Mathf.PI) * dx / (2 * Mathf.PI); var nw = y1 + Mathf.Sin(t * 2 * Mathf.PI) * dy / (2 * Mathf.PI); var heightValue = (float)_heightMap.Get(nx, ny, nz, nw); var heatValue = (float)_heatMap.Get(nx, ny, nz, nw); var moistureValue = (float)_moistureMap.Get(nx, ny, nz, nw); // keep track of the max and min values found if (heightValue > _heightData.Max) { _heightData.Max = heightValue; } if (heightValue < _heightData.Min) { _heightData.Min = heightValue; } if (heatValue > _heatData.Max) { _heatData.Max = heatValue; } if (heatValue < _heatData.Min) { _heatData.Min = heatValue; } if (moistureValue > _moistureData.Max) { _moistureData.Max = moistureValue; } if (moistureValue < _moistureData.Min) { _moistureData.Min = moistureValue; } _heightData.Data[x, y] = heightValue; _heatData.Data[x, y] = heatValue; _moistureData.Data[x, y] = moistureValue; } } }
private void GenerateMap(HexMap m) { // Generate AltitudeMap ImplicitFractal AltitudeMap = GetFractal(m.AltitudeFractal); // Generate TemperatureMap ImplicitGradient gradient = new ImplicitGradient(1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1); ImplicitCombiner TemperatureMap = new ImplicitCombiner(CombinerType.MULTIPLY); TemperatureMap.AddSource(gradient); TemperatureMap.AddSource(AltitudeMap); // Generate PressureMap ImplicitCombiner PressureMap = new ImplicitCombiner(CombinerType.AVERAGE); //PressureMap.AddSource( AltitudeMap ); PressureMap.AddSource(GetFractal(m.PressureFractal)); // Generate HumidityMap ImplicitFractal HumidityMap = GetFractal(m.HumidityFractal); // Generate RadiationMap ImplicitFractal RadiationMap = GetFractal(m.RadiationFractal); HexModel hex; for (int x = 0; x < _map.Width; x++) { for (int y = 0; y < _map.Height; y++) { hex = new HexModel { X = x, Y = y, Lens = m.Lens }; _map.Table[x][y] = hex; // WRAP ON BOTH AXIS // Noise range float x1 = 0, x2 = 2; float y1 = 0, y2 = 2; float dx = x2 - x1; float dy = y2 - y1; // Sample noise at smaller intervals float s = (float)x / _map.Width; float t = (float)y / _map.Height; // Calculate our 4D coordinates float nx = x1 + Mathf.Cos(s * 2 * Mathf.PI) * dx / (2 * Mathf.PI); float ny = y1 + Mathf.Cos(t * 2 * Mathf.PI) * dy / (2 * Mathf.PI); float nz = x1 + Mathf.Sin(s * 2 * Mathf.PI) * dx / (2 * Mathf.PI); float nw = y1 + Mathf.Sin(t * 2 * Mathf.PI) * dy / (2 * Mathf.PI); float altitude = (float)AltitudeMap.Get(nx, ny, nz, nw); float temperature = (float)(1 - TemperatureMap.Get(nx, ny, nz, nw)); float equador = (float)(gradient.Get(nx, ny, nz, nw)); //float pressure = PressureMap.Get( nx, ny, nz, nw ); float humidity = (float)HumidityMap.Get(nx, ny, nz, nw); float radiation = (float)RadiationMap.Get(nx, ny, nz, nw); // keep track of the max and min values found SetInitialHexValue(hex, R.Altitude, altitude); SetInitialHexValue(hex, R.Temperature, temperature); SetInitialHexValue(hex, R.Humidity, humidity); SetInitialHexValue(hex, R.Pressure, 1f - altitude); SetInitialHexValue(hex, R.Radiation, .5f); } } //Normalize Ranges to 0-1 for (int x = 0; x < _map.Width; x++) { for (int y = 0; y < _map.Height; y++) { hex = _map.Table[x][y]; SetHex(hex, R.Altitude, 0.005f); /* * if( hex.Props[ R.Altitude ].Value < _planetModel.LiquidLevel ) * { * SetInitialHexValue( hex, R.Humidity, hex.Props[ R.Humidity ].Value + 0.5f ); * SetInitialHexValue( hex, R.Pressure, hex.Props[ R.Pressure ].Value + 0.5f ); * SetInitialHexValue( hex, R.Radiation, hex.Props[ R.Radiation ].Value - 0.5f ); * if( hex.Props[ R.Temperature ].Value > 0.33 ) * { * SetInitialHexValue( hex, R.Temperature, ( hex.Props[ R.Temperature ].Value - ( hex.Props[ R.Temperature ].Value * 0.5f ) ) ); * } * else * { * SetInitialHexValue( hex, R.Temperature, ( hex.Props[ R.Temperature ].Value + ( hex.Props[ R.Temperature ].Value * 0.5f ) ) ); * } * } */ SetHex(hex, R.Temperature); SetHex(hex, R.Pressure); SetHex(hex, R.Humidity); SetHex(hex, R.Radiation); //element index hex.Props[R.Element].Index = (int)RandomUtil.GetWeightedValue(_elementsProbabilities); hex.Props[R.Element].Value = _elementsDict[hex.Props[R.Element].Index].Amount; hex.Props[R.Element].Delta = _elementsDict[hex.Props[R.Element].Index].Weight * 1; Color mColor; ColorUtility.TryParseHtmlString(_elementsDict[(int)hex.Props[R.Element].Index].Color, out mColor); hex.Props[R.Element].Color = mColor; //hex.Props[ R.Element ].Value = _planetModel._Elements[ RandomUtil.FromRangeInt( 0, _planetModel._Elements.Count ) ].Index; //hex.Props[ R.Minerals ].Value = (int)_elements[ (int)hex.Props[ R.Element ].Value ].Weight; hex.Props[R.Altitude].Value *= 2; _hexUpdateCommand.Execute(hex); _hexScoreUpdateCommand.ExecuteHex(hex); } } }
// Extract data from a noise module private void GetData(ImplicitModuleBase module, ref MapData mapData) { mapData = new MapData(Width, Height); // loop through each x,y point - get height value for (var x = 0; x < Width; x++) { for (var y = 0; y < Height; y++) { //Wrap on x-axis only // //Noise range // float x1 = 0, x2 = 1; // float y1 = 0, y2 = 1; // float dx = x2 - x1; // float dy = y2 - y1; // // //Sample noise at smaller intervals // float s = x / (float)Width; // float t = y / (float)Height; // // // Calculate our 3D coordinates // float nx = x1 + Mathf.Cos (s * 2 * Mathf.PI) * dx / (2 * Mathf.PI); // float ny = x1 + Mathf.Sin (s * 2 * Mathf.PI) * dx / (2 * Mathf.PI); // float nz = t; // // float heightValue = (float)HeightMap.Get (nx, ny, nz); // // // keep track of the max and min values found // if (heightValue > mapData.Max) // mapData.Max = heightValue; // if (heightValue < mapData.Min) // mapData.Min = heightValue; // // mapData.Data [x, y] = heightValue; // WRAP ON BOTH AXIS // Noise range float x1 = 0, x2 = 2; float y1 = 0, y2 = 2; float dx = x2 - x1; float dy = y2 - y1; // Sample noise at smaller intervals float s = x / (float)Width; float t = y / (float)Height; // Calculate our 4D coordinates float nx = x1 + Mathf.Cos(s * 2 * Mathf.PI) * dx / (2 * Mathf.PI); float ny = y1 + Mathf.Cos(t * 2 * Mathf.PI) * dy / (2 * Mathf.PI); float nz = x1 + Mathf.Sin(s * 2 * Mathf.PI) * dx / (2 * Mathf.PI); float nw = y1 + Mathf.Sin(t * 2 * Mathf.PI) * dy / (2 * Mathf.PI); float heightValue = (float)HeightMap.Get(nx, ny, nz, nw); // keep track of the max and min values found if (heightValue > mapData.Max) { mapData.Max = heightValue; } if (heightValue < mapData.Min) { mapData.Min = heightValue; } mapData.Data[x, y] = heightValue; } } }