コード例 #1
0
        public void NoiseTestFractalBrowning()
        {
            XNAGame game = new XNAGame();
            PerlinNoiseGenerater noise;

            noise = new PerlinNoiseGenerater();
            float          factor           = 0.02f;
            float          scale            = 40f;
            List <Vector3> positions        = new List <Vector3>();
            List <Color>   colors           = new List <Color>();
            int            width            = 300;
            int            height           = 300;
            float          verticesPerMeter = 0.5f;
            int            verticesX        = (int)(width * verticesPerMeter);
            int            verticesY        = (int)(height * verticesPerMeter);
            SimpleTerrain  terrain;

            noise.NumberOfOctaves = 4;
            noise.persistance     = 0.5f;

            for (int i = 0; i < verticesX; i++)
            {
                for (int j = 0; j < verticesY; j++)
                {
                    positions.Add(new Vector3(i / verticesPerMeter, noise.GetFractalBrowningNoise(i / verticesPerMeter, j / verticesPerMeter, 4, 2.0f, 0.4f, 0.2f) * scale, j / verticesPerMeter));
                    colors.Add(new Color((byte)(150 * noise.GetPerlineNoise(i, j)), (byte)(100 + 70 * noise.GetPerlineNoise(i + 1, j + 1)), (byte)(140 * noise.GetPerlineNoise(i, j + 2))));
                }
            }
            terrain = new SimpleTerrain(game, positions, colors, verticesX, verticesY);
            game.InitializeEvent +=
                delegate
            {
                terrain.CreateRenderData();
            };

            game.DrawEvent +=
                delegate
            {
                terrain.Render();
            };
            game.Run();
        }
コード例 #2
0
        public Array2D <float> GenerateBottomIslandHeightmap(int size)
        {
            PerlinNoiseGenerater noise;

            noise = new PerlinNoiseGenerater();
            float          factor          = 0.1f;
            float          scale           = 10f;
            List <Vector3> positions       = new List <Vector3>();
            List <Color>   colors          = new List <Color>();
            List <Vector3> positionsIsland = new List <Vector3>();
            List <Color>   colorsIsland    = new List <Color>();
            List <Vector3> positionsFinal  = new List <Vector3>();
            List <Color>   colorsFinal     = new List <Color>();
            int            width           = size;
            int            height          = size;
            float          lengthFactor    = 0.2f;
            SimpleTerrain  terrain;
            SimpleTerrain  terrainIsland;
            SimpleTerrain  terrainFinal;

            ProceduralHeigthGenerater gen = new ProceduralHeigthGenerater(8, 0.7f);
            float heigestFBM   = 0;
            float heigestRidge = 0;

            float lowestIsland = 0;
            var   heights      = new Array2D <float>(new Point2(width, height));

            float[,] heightDataRidge  = new float[width, height];
            float[,] heightDataFBM    = new float[width, height];
            float[,] heightDataIsland = new float[width, height];
            float[,] heightDataFinal  = new float[width, height];


            var r = random;

            var octaves = new[]
            {
                //new Vector4(1/2f, 0.5f, (float)r.NextDouble(), (float)r.NextDouble()),
                //new Vector4(1/5f, 2, (float)r.NextDouble(), (float)r.NextDouble()),
                //new Vector4(1/10f, 5f, (float)r.NextDouble(), (float)r.NextDouble()),
                //new Vector4(1f, 1f, (float)r.NextDouble(), (float)r.NextDouble()),
                new Vector4(1 / 2f, 1f, (float)r.NextDouble(), (float)r.NextDouble()),
                new Vector4(1 / 5f, 4, (float)r.NextDouble(), (float)r.NextDouble()),
                new Vector4(1 / 10f, 10f, (float)r.NextDouble(), (float)r.NextDouble()),
            };


            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    noise.NumberOfOctaves = 1;

                    //heights[new Point2(i, j)] += noise.RidgedMF(i * lengthFactor, j * lengthFactor, 0.15f, 8, 2f, 0.7f, 0.8f);//noise.CombinedFractalBrowningAndRidgedMF(i * lengthFactor, j * lengthFactor, 8, 4,5f, 0.5f, 2f, 0.8f, 1f);


                    foreach (var v in octaves)
                    {
                        float   frequency = v.X;
                        float   oScale    = v.Y;
                        Vector2 offset    = new Vector2(v.Z, v.W) * 1000;

                        heights[new Point2(i, j)] += noise.GetPerlineNoise((i + offset.X) * frequency, (j + offset.Y) * frequency) * oScale;
                    }

                    heightDataFBM[i, j]    = noise.GetFractalBrowningNoise(i * lengthFactor, j * lengthFactor, 8, 1.2f, 1.9f, 1.2f);
                    heightDataIsland[i, j] = gen.IslandFactor(i * lengthFactor, j * lengthFactor, new Vector2(width * lengthFactor * 0.5f, height * lengthFactor * 0.5f), width * lengthFactor * 0.42f, width * lengthFactor * 0.4f);//noise.CombinedFractalBrowningAndRidgedMF(i, j, 8, 4, 4, 0.9f, 0.5f, 1.2f, 0.8f)*0.1f+gen.IslandFactor(i, j, new Vector2(width * 0.45f, height * 0.5f),0,width*0.22f)*0.9f  ;

                    if (heigestFBM < heightDataFBM[i, j])
                    {
                        heigestFBM = heightDataFBM[i, j];
                    }
                    if (heigestRidge < heightDataRidge[i, j])
                    {
                        heigestRidge = heightDataRidge[i, j];
                    }

                    if (lowestIsland > heightDataIsland[i, j])
                    {
                        lowestIsland = heightDataIsland[i, j];
                    }
                }
            }


            return(heights);
        }