Exemplo n.º 1
0
            public static float[,] GeneratePerlinMap(int worldX, int worldY, TerrainHeightMap heightMap, float[] scales, float[] additions, float[] strengths, decimal[] limits)
            {
                int size = heightMap.size;
                float[,] noise = new float[size, size];

                float top = 0;
                float bottom = Mathf.Infinity;
                float seed = 1500;
                float totalStrength = 0f;

                for (int i = 0; i < scales.Length; i++)
                {

                    float y = 0.0F;
                    while (y < size)
                    {
                        float x = 0.0F;
                        while (x < size)
                        {
                            float xCoord = (seed + x / size * scales[i]) * worldX;
                            float yCoord = (seed + y / size * scales[i]) * worldY;
                            float sample = Mathf.PerlinNoise(xCoord, yCoord);
                            noise[(int)x, (int)y] += (sample * strengths[i]) + additions[i];

                            //top and bottom check
                            if(noise[(int)x, (int)y] > top)
                                top = noise[(int)x, (int)y];
                            else if(noise[(int)x, (int)y] < bottom)
                                bottom = noise[(int)x, (int)y];
                            x++;
                        }
                        y++;
                    }
                    totalStrength += strengths[i];
                }
                heightMap.SetHeightMap(noise, top, bottom, totalStrength);
                return noise;
            }