Beispiel #1
0
        public void GenGraph()
        {
            Random r = new Random(seed);
            List<BenTools.Mathematics.Vector> lv = new List<BenTools.Mathematics.Vector>();
            for (int i = 0; i < 10000; i++)
            {
                BenTools.Mathematics.Vector v = new BenTools.Mathematics.Vector(new double[2] { r.Next(1, 99) / 100f, r.Next(1, 99) / 100f });
                if (!lv.Contains(v))
                    lv.Add(v);
            }
            cells.GenVoronoi(lv);

            for (int i = 0; i < 3; i++)
            {
                //Print(String.Format("Iter{0}", x));
                minPos = new Vector2(1f, 1f);
                lv.Clear();
                foreach (Voronoi.Center c in cells.Centers.Values)
                {
                    Vector2[] points = c.corners.Keys.ToArray();
                    Vector2 cent = CalculateCentroid(points, c.corners.Count - 1);

                    if (cent.X > 0 && cent.X < 1 && cent.Y > 0 && cent.Y < 1 && !lv.Contains(Tools.Functions.Vector2ToVector(cent)))
                    {
                        if (cent.X <= minPos.X && cent.Y <= minPos.Y)
                            minPos = cent;
                        lv.Add(Tools.Functions.Vector2ToVector(cent));
                    }
                }

                cells.Clear();
                cells.GenVoronoi(lv);
            }
        }
Beispiel #2
0
        //only square size by now
        public IslandModifier(Island island, int widthRes, int heightRes, bool addOrErode = true)
        {
            _island    = island;
            AddOrErode = addOrErode;

            //generate a heightmap based on resolution
            _heightmap = new float[widthRes, heightRes];

            for (int x = 0; x < widthRes; x++)
            {
                for (int y = 0; y < heightRes; y++)
                {
                    var pos = new BenTools.Mathematics.Vector(_island.width / (float)widthRes * x, _island.width / (float)heightRes * y);
                    _heightmap[x, y] = _island.GetElevation(pos);
                }
            }
        }