コード例 #1
0
        public void calculateOffset(int x, int z)
        {
            float currentPoint = heights[(z + x * terrainSize)];

            offset = 0;

            int[] neighbours = TerrainUtilities.GetNeighbours(x, z, terrainSize);

            float weightedNeighbours = 0.0f;

            for (int i = 0; i < neighbours.Length; i++)
            {
                weightedNeighbours += heights[neighbours[i]];
            }
            weightedNeighbours /= (float)neighbours.Length;

            if (invert)
            {
                offset = (((weightedNeighbours - currentPoint) - min) / range) + shift;
            }
            else
            {
                offset = (((currentPoint - weightedNeighbours) - min) / range) + shift;
            }
        }
コード例 #2
0
        public void calculateMinMax()
        {
            min = -0.01f;
            max = 0.01f;
            float currentPoint;
            float check;

            for (int x = 0; x < terrainSize; x++)
            {
                for (int z = 0; z < terrainSize; z++)
                {
                    currentPoint = heights[(z + x * terrainSize)];

                    int[] neighbours = TerrainUtilities.GetNeighbours(x, z, terrainSize);

                    float weightedNeighbours = 0.0f;
                    for (int i = 0; i < neighbours.Length; i++)
                    {
                        weightedNeighbours += heights[neighbours[i]];
                    }
                    weightedNeighbours /= (float)neighbours.Length;

                    check = currentPoint - weightedNeighbours;

                    if (check < min)
                    {
                        min = check;
                    }
                    else if (check > max)
                    {
                        max = check;
                    }
                }
            }

            range = -min + max * colorRange;
        }