Ejemplo n.º 1
0
        public float IslandFactor(float x, float y, Vector2 center, float noiseFactor, float size)
        {
            float distance = Vector2.DistanceSquared(center, noise.Perturb(x, y, 1, noiseFactor));
            float heigth   = (size * size - distance) / (size * size);

            return(heigth);
        }
Ejemplo n.º 2
0
        public static void generateTerrain(int chunksX, int chunksY)
        {
            PerlinNoiseGenerater noise;

            noise = new PerlinNoiseGenerater();
            float          factor                  = 0.1f;
            float          scale                   = 1f;
            List <Vector3> positions               = new List <Vector3>();
            List <Vector3> positionsbase           = new List <Vector3>();
            List <Vector3> positionsbaseDifference = new List <Vector3>();

            List <Color> colors     = new List <Color>();
            List <Color> colorsbase = new List <Color>();

            int           width  = chunksX * 16;
            int           height = chunksY * 16;
            SimpleTerrain terrain;
            SimpleTerrain terrainbase;
            SimpleTerrain terrainbaseDiffernce;


            ProceduralHeigthGenerater gen = new ProceduralHeigthGenerater(8, 0.7f);

            float[,] heightData         = new float[width, height];
            float[,] heightDataErrosion = new float[width, height];
            //float[,] heightDataErrosionDiffernce = new float[width, height];



            for (int i = 0; i < (int)(width); i++)
            {
                for (int j = 0; j < height; j++)
                {
                    heightData[i, j] = (noise.GetPerlineNoise(i, j, 8, 0.1f, 0.8f, 0.8f) * 0.8f + noise.GetPerlineNoise(noise.Perturb(i, j, 0.1f, 30).X, noise.Perturb(i, j, 0.1f, 30).Y, 4, 0.2f, 0.5f, 0.5f) * 0.25f) * 70;
                }
            }
            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    positionsbase.Add(new Vector3(i, heightData[i, j], j));
                    colorsbase.Add(Color.White);
                }
            }
            //heightDataErrosionDiffernce = heightData
            heightDataErrosion = gen.GenerateHydrolicErrosion(heightData, 50 * width * height, width, height);

            for (int i = 0; i < width; i++)
            {
                for (int j = 0; j < height; j++)
                {
                    positions.Add(new Vector3(i, heightDataErrosion[i, j], j));
                    colors.Add(new Color(new Microsoft.Xna.Framework.Vector3(positions[i * width + j].Y - positionsbase[i * width + j].Y, 50, 50)));
                    //positionsbaseDifference.Add(new Vector3(i, positions[i * width + j].Y - positionsbase[i * width + j].Y, j));(
                }
            }


            for (int x = 0; x < chunksX; x++)
            {
                for (int y = 0; y < chunksY; y++)
                {
                    var terr = new VoxelTerrainChunk();
                    terr.Size = new Point3(16, 64, 16);
                    //terr.Size = new Point3(5, 5, 5);
                    terr.WorldPosition = Vector3.Modulate(terr.Size.ToVector3() * terr.NodeSize, new Vector3(x, 0, y));
                    terr.Create();

                    TW.Data.GetSingleton <Datastore>().Persist(terr);

                    for (int tx = 0; tx < terr.Size.X; tx++)
                    {
                        for (int ty = 0; ty < terr.Size.Y / 2; ty++)
                        {
                            for (int tz = 0; tz < terr.Size.Z; tz++)
                            {
                                var heightMapX = tx + (int)terr.WorldPosition.X;
                                var heightMapZ = tz + (int)terr.WorldPosition.Z;
                                if (heightMapX >= width || heightMapZ >= height)
                                {
                                    continue;
                                }
                                if (ty < heightDataErrosion[heightMapX, heightMapZ] / 2f)
                                {
                                    terr.GetVoxelInternal(new Point3(tx, ty, tz)).Filled = true;
                                }
                            }
                        }
                    }
                }
            }
        }