Exemple #1
0
        public void Generate(Random random)
        {
            if (DoReset)
            {
                Array.Clear(Altitude, 0, Altitude.Length);
                Array.Clear(Temperature, 0, Temperature.Length);
                Array.Clear(Water, 0, Water.Length);
                Array.Clear(Vapor, 0, Vapor.Length);
            }

            double[,] heightmap = new DiamondSquare(random, XSize, YSize, AltitudeScale, Roughness, WrapX, WrapY).GenerateHeightmap();
            double heightmapWidth   = heightmap.GetUpperBound(0);
            double heightmapDepth   = heightmap.GetUpperBound(1);
            double widthRatio       = heightmapWidth / XSize;
            double heightRatio      = heightmapDepth / YSize;
            int    middleX          = XSize / 2;
            int    middleY          = YSize / 2;
            int    edgeSizeX        = XSize / 8;
            int    edgeSizeY        = YSize / 8;
            int    smoothThresholdX = middleX - edgeSizeX;
            int    smoothThresholdY = middleY - edgeSizeY;

            for (int x = 0; x < XSize; x++)
            {
                for (int y = 0; y < YSize; y++)
                {
                    double multiplier = 1.0;
                    if (SmoothEdges)
                    {
                        int dx = Math.Abs(middleX - x);
                        int dy = Math.Abs(middleY - y);
                        if (dx >= smoothThresholdX)
                        {
                            multiplier *= 1 - (dx - smoothThresholdX) / (double)(edgeSizeX);
                        }
                        if (dy >= smoothThresholdY)
                        {
                            multiplier *= 1 - (dy - smoothThresholdY) / (double)(edgeSizeY);
                        }
                    }

                    int x2 = (int)Math.Round((x) * widthRatio);
                    int y2 = (int)Math.Round((y) * heightRatio);
                    Altitude[x, y]    = -AltitudeScale + (AltitudeScale + heightmap[x2, y2]) * multiplier;
                    Temperature[x, y] = 300;
                    Water[x, y]       = 4000.0;
                    //Vapor[x, y] = 0;
                }
            }


            DoReset = true;
        }
Exemple #2
0
        public void Generate(Random rng)
        {
            Altitude = new double[SizeX, SizeY];

            double[,] heightmap = new DiamondSquare(rng, SizeX, SizeY, 1, Roughness, WrapX, WrapY).GenerateHeightmap();
            double heightmapWidth   = heightmap.GetUpperBound(0);
            double heightmapDepth   = heightmap.GetUpperBound(1);
            double widthRatio       = heightmapWidth / SizeX;
            double heightRatio      = heightmapDepth / SizeY;
            int    middleX          = SizeX / 2;
            int    middleY          = SizeY / 2;
            int    edgeSizeX        = SizeX / 4;
            int    edgeSizeY        = SizeY / 4;
            int    smoothThresholdX = middleX - edgeSizeX;
            int    smoothThresholdY = middleY - edgeSizeY;

            for (int x = 0; x < SizeX; x++)
            {
                for (int y = 0; y < SizeY; y++)
                {
                    double multiplier = 1.0;
                    if (SmoothEdges)
                    {
                        int dx = Math.Abs(middleX - x);
                        int dy = Math.Abs(middleY - y);
                        if (dx >= smoothThresholdX)
                        {
                            multiplier *= 1 - (dx - smoothThresholdX) / (double)(edgeSizeX);
                        }
                        if (dy >= smoothThresholdY)
                        {
                            multiplier *= 1 - (dy - smoothThresholdY) / (double)(edgeSizeY);
                        }
                    }
                    if (Noise > 0)
                    {
                        multiplier *= rng.NextDouble(1 - Noise, 1);
                    }

                    int x2 = (int)Math.Round((x) * widthRatio);
                    int y2 = (int)Math.Round((y) * heightRatio);
                    Altitude[x, y] = FloorHeight + (AltitudeScale + heightmap[x2, y2] * AltitudeScale) * multiplier;
                }
            }
        }