Beispiel #1
0
        public MapData GetCombinerData(ImplicitCombiner combiner)
        {
            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)combiner.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);
        }
Beispiel #2
0
        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;
                }
            }
        }
Beispiel #3
0
        public Grid <float> GenerateHeatMap(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 heatMap = new Grid <float>(mapLength, mapWidth);

            var gradientGenerator = new ImplicitGradient(1, 1, 0, 1,
                                                         1, 1, 1, 1,
                                                         1, 1, 1, 1)
            {
                Seed = seed
            };

            var fractalGenerator = new ImplicitFractal(heatFractalType, BasisType.Simplex,
                                                       InterpolationType.Quintic, heatOctaves, heatFrequency, heatLacunarity)
            {
                Seed = seed
            };

            var combiner = new ImplicitCombiner(CombinerType.Multiply);

            combiner.AddSource(gradientGenerator);
            combiner.AddSource(fractalGenerator);

            heatMap.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 heat = (float)combiner.Get(nx, ny, nz, nw);

                heat = heat * 0.5f + 0.5f;

                var newHeat = (float)Contrast(heat, contrast);

                return(newHeat);
            });

            return(heatMap);
        }
Beispiel #4
0
    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;
            }
        }
    }
    // 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;
            }
        }
    }
Beispiel #6
0
    // 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;
            }
        }
    }
Beispiel #7
0
    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);
            }
        }
    }