示例#1
0
    public void CalculateData(ImplicitModuleBase module)
    {
        int width  = Values.GetLength(0);
        int length = Values.GetLength(1);

        for (int x = 0; x < width; x++)
        {
            for (int z = 0; z < length; z++)
            {
                float x1    = x / (float)width;
                float z1    = z / (float)length;
                float value = (float)module.Get(x1, z1);
                Values[x, z] = value;

                if (value > Max)
                {
                    Max = value;
                }
                if (value < Min)
                {
                    Min = value;
                }
            }
        }

        for (int x = 0; x < width; x++)
        {
            for (int z = 0; z < length; z++)
            {
                Values[x, z] = (Values[x, z] - Min) / (Max - Min);
            }
        }
    }
示例#2
0
 public void GetData(ImplicitModuleBase modul)
 {
     for (int x = 0; x < width; x++)
     {
         for (int y = 0; y < length; y++)
         {
             float value = (float)modul.Get(x, y);
             if (value < Min)
             {
                 Min = value;
             }
             if (value > Max)
             {
                 Max = value;
             }
             val[x, y] = value;
         }
     }
 }
示例#3
0
        private void GetMapData(ImplicitModuleBase HeightMap, out float[,] heightMap, out float minHeight, out float maxHeight,
                                ImplicitModuleBase HeatMap, out float[,] heatMap, out float minHeat, out float maxHeat,
                                ImplicitModuleBase MoistureMap, out float[,] moistureMap, out float minMoisture, out float maxMoisture)
        {
            heightMap   = new float[Width, Height];
            heatMap     = new float[Width, Height];
            moistureMap = new float[Width, Height];
            minHeight   = float.MaxValue;
            maxHeight   = float.MinValue;
            minHeat     = float.MaxValue;
            maxHeat     = float.MinValue;
            minMoisture = float.MaxValue;
            maxMoisture = float.MinValue;
            // Get all the values to be used and track max/min to normalize when assigning to tiles
            for (var x = 0; x < Width; x++)
            {
                for (var y = 0; y < Height; y++)
                {
                    #region X-AXIS WRAPPING
                    // X-AXIS WRAPPING
                    //// noise range
                    //float x1 = 0, x2 = 1;
                    //float y1 = 0, y2 = 1;
                    //float dx = x2 - x1;
                    //float dy = y2 - y1;

                    //// Sample nosie at smaller intervals
                    //float s = x / (float)Width;
                    //float t = y / (float)Height;

                    //// Calculate 3D coordinates
                    //float nx = (float)(x1 + Math.Cos(s * 2 * Math.PI) * dx / (2 * Math.PI));
                    //float ny = (float)(x1 + Math.Sin(s * 2 * Math.PI) * dx / (2 * Math.PI));
                    //float nz = t;

                    //float heightValue = (float)HeightMap.Get(nx, ny, nz);

                    //// keep track of max and min
                    //if (heightValue > maxHeight) maxHeight = heightValue;
                    //if (heightValue < minHeight) minHeight = heightValue;

                    //heightMap[x, y] = heightValue;
                    #endregion

                    // X AND Y AXIS WRAPPING
                    // 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 = (float)(x1 + Math.Cos(s * 2 * Math.PI) * dx / (2 * Math.PI));
                    float ny = (float)(y1 + Math.Cos(t * 2 * Math.PI) * dy / (2 * Math.PI));
                    float nz = (float)(x1 + Math.Sin(s * 2 * Math.PI) * dx / (2 * Math.PI));
                    float nw = (float)(y1 + Math.Sin(t * 2 * Math.PI) * dy / (2 * Math.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 > maxHeight)
                    {
                        maxHeight = heightValue;
                    }
                    if (heightValue < minHeight)
                    {
                        minHeight = heightValue;
                    }

                    if (heatValue > maxHeat)
                    {
                        maxHeat = heatValue;
                    }
                    if (heatValue < minHeat)
                    {
                        minHeat = heatValue;
                    }

                    if (moistureValue > maxMoisture)
                    {
                        maxMoisture = moistureValue;
                    }
                    if (moistureValue < minMoisture)
                    {
                        minMoisture = moistureValue;
                    }

                    heightMap[x, y]   = heightValue;
                    heatMap[x, y]     = heatValue;
                    moistureMap[x, y] = moistureValue;
                }
            }
        }