示例#1
0
文件: Point.cs 项目: bmjoy/PlanetHex
        public List <Point> Subdivide(Point point, int count, Hexasphere hexasphere)
        {
            var segments = new List <Point>();

            segments.Add(this);

            for (var i = 1; i < count; i++)
            {
                float ratio = (float)i / count;
                float x     = this.x * (1 - ratio) + point.x * ratio;
                float y     = this.y * (1 - ratio) + point.y * ratio;
                float z     = this.z * (1 - ratio) + point.z * ratio;
                var   np    = new Point(x, y, z);
                np = hexasphere.GetOrAddPoint(np);
                segments.Add(np);
            }
            segments.Add(point);
            return(segments);
        }
示例#2
0
        public static Planet Generate(int radius, int terrainHeight, int?heightLimit0 = null)
        {
            int numDivisions = (int)Mathf.Sqrt((Mathf.PI * Mathf.Pow(radius, 2)) / 5);

            int heightLimit = (heightLimit0 == null) ? terrainHeight + 20 : (int)heightLimit0;

            Hexasphere hexasphere = new Hexasphere(radius, numDivisions);

            Region[] regions = hexasphere.Regions;

            var noiseGenerator = new SimplexNoiseGenerator();

            foreach (var region in regions)
            {
                region.GenerateTerrain(noiseGenerator, terrainHeight, heightLimit, radius);
            }

            var planet = new Planet(radius, terrainHeight);

            planet.Regions = regions;

            return(planet);
        }