Ballz.GameSession.World.Terrain.SmoothTerrain C# (CSharp) Méthode

SmoothTerrain() private méthode

private SmoothTerrain ( float gauss ) : void
gauss float
Résultat void
        private void SmoothTerrain(float[] gauss)
        {
            int halfGauss = gauss.GetLength(0) / 2;

            // Iterate over all bitmap pixels
            for (int y = 0; y < height; ++y)
            {
                for (int x = 0; x < width; ++x)
                {
                    float sum = 0.0f;
                    float weight = 0.0f;
                    for (int i = -halfGauss; i <= halfGauss; ++i)
                    {
                        int index = x + i;
                        if (index >= 0 && index < width)
                        {
                            float val = gauss[i + halfGauss];

                            var cur = WorkingShape.TerrainBitmap[index, y];
                            sum += ((cur == TerrainType.Earth || cur == TerrainType.Sand || cur == TerrainType.Stone )? 1.0f : 0.0f) * val;
                            weight += val;
                        }
                    }

                    float newVal = sum / weight;
                    terrainSmoothmap[x, y] = newVal;
                    terrainSmoothmapCopy[x, y] = newVal;
                }
            }

            for (int y = 0; y < height; ++y)
            {
                for (int x = 0; x < width; ++x)
                {
                    float sum = 0.0f;
                    float weight = 0.0f;
                    for (int i = -halfGauss; i <= halfGauss; ++i)
                    {
                        int index = y + i;
                        if (index >= 0 && index < height)
                        {
                            float val = gauss[i + halfGauss];

                            sum += terrainSmoothmapCopy[x, index] * val;
                            weight += val;
                        }
                    }

                    terrainSmoothmap[x, y] = sum / weight;
                }
            }
        }