Example #1
0
            public static void VCell(Vec location)
            {
                Vec   index     = chunkpos + location;
                Color cellcolor = BColors.BCList[Globe.GetChunk(index).BiomeID];

                Point cellcenter = new Point(Globe.GetChunk(index).BiomeCenter[0], Globe.GetChunk(index).BiomeCenter[1]);

                Biomes[(int)location[0] + 1, (int)location[1] + 1] = Globe.GetChunk(index).BiomeID;

                RadialGradientBrush cellbrush = new RadialGradientBrush()
                {
                    GradientOrigin = new Point(0.5, 0.5),
                    Center         = new Point(0.5, 0.5),
                    RadiusX        = 0.5,
                    RadiusY        = 0.5
                };

                cellbrush.GradientStops.Add(new GradientStop(cellcolor, 0.0));
                cellbrush.GradientStops.Add(new GradientStop(Color.Multiply(cellcolor, (float)0.75), 1.0));

                cellbrush.Freeze();

                Polygon cell = new Polygon()
                {
                    Fill = cellbrush
                };

                Cells[(int)location[0] + 1, (int)location[1] + 1] = cell;

                // voronoi from triangulation algorithm

                Vec[] t = new Vec[4];
                Vec   p;
                Vec   q;

                q = new Vec()
                {
                    -1, 0
                };
                p    = Globe.GetChunk(index + q).BiomeCenter;
                t[0] = (Vec)(new Polar(p[0], p[1] / 64)) + origin + (q * 200) + (location * 200);
                q    = new Vec()
                {
                    -1, -1
                };
                p    = Globe.GetChunk(index + q).BiomeCenter;
                t[1] = (Vec)(new Polar(p[0], p[1] / 64)) + origin + (q * 200) + (location * 200);
                q    = new Vec()
                {
                    0, -1
                };
                p    = Globe.GetChunk(index + q).BiomeCenter;
                t[2] = (Vec)(new Polar(p[0], p[1] / 64)) + origin + (q * 200) + (location * 200);
                q    = new Vec()
                {
                    0, 0
                };
                p    = Globe.GetChunk(index + q).BiomeCenter;
                t[3] = (Vec)(new Polar(p[0], p[1] / 64)) + origin + (q * 200) + (location * 200);

                if (!Consts.IsInCirc(t))
                {
                    Vec v1 = Consts.Center(t[0], t[1], t[3]);
                    Vec v2 = Consts.Center(t[1], t[2], t[3]);

                    Point p1 = new Point(v1[0], v1[1]);
                    Point p2 = new Point(v2[0], v2[1]);

                    cell.Points.Add(p1);
                    cell.Points.Add(p2);
                }
                else
                {
                    Vec v1 = Consts.Center(t[0], t[2], t[3]);

                    Point p1 = new Point(v1[0], v1[1]);

                    cell.Points.Add(p1);
                }

                q = new Vec()
                {
                    0, -1
                };
                p    = Globe.GetChunk(index + q).BiomeCenter;
                t[0] = (Vec)(new Polar(p[0], p[1] / 64)) + origin + (q * 200) + (location * 200);
                q    = new Vec()
                {
                    1, -1
                };
                p    = Globe.GetChunk(index + q).BiomeCenter;
                t[1] = (Vec)(new Polar(p[0], p[1] / 64)) + origin + (q * 200) + (location * 200);
                q    = new Vec()
                {
                    1, 0
                };
                p    = Globe.GetChunk(index + q).BiomeCenter;
                t[2] = (Vec)(new Polar(p[0], p[1] / 64)) + origin + (q * 200) + (location * 200);
                q    = new Vec()
                {
                    0, 0
                };
                p    = Globe.GetChunk(index + q).BiomeCenter;
                t[3] = (Vec)(new Polar(p[0], p[1] / 64)) + origin + (q * 200) + (location * 200);

                if (!Consts.IsInCirc(t))
                {
                    Vec v1 = Consts.Center(t[0], t[1], t[3]);
                    Vec v2 = Consts.Center(t[1], t[2], t[3]);

                    Point p1 = new Point(v1[0], v1[1]);
                    Point p2 = new Point(v2[0], v2[1]);

                    cell.Points.Add(p1);
                    cell.Points.Add(p2);
                }
                else
                {
                    Vec v1 = Consts.Center(t[0], t[2], t[3]);

                    Point p1 = new Point(v1[0], v1[1]);

                    cell.Points.Add(p1);
                }

                q = new Vec()
                {
                    1, 0
                };
                p    = Globe.GetChunk(index + q).BiomeCenter;
                t[0] = (Vec)(new Polar(p[0], p[1] / 64)) + origin + (q * 200) + (location * 200);
                q    = new Vec()
                {
                    1, 1
                };
                p    = Globe.GetChunk(index + q).BiomeCenter;
                t[1] = (Vec)(new Polar(p[0], p[1] / 64)) + origin + (q * 200) + (location * 200);
                q    = new Vec()
                {
                    0, 1
                };
                p    = Globe.GetChunk(index + q).BiomeCenter;
                t[2] = (Vec)(new Polar(p[0], p[1] / 64)) + origin + (q * 200) + (location * 200);
                q    = new Vec()
                {
                    0, 0
                };
                p    = Globe.GetChunk(index + q).BiomeCenter;
                t[3] = (Vec)(new Polar(p[0], p[1] / 64)) + origin + (q * 200) + (location * 200);

                if (!Consts.IsInCirc(t))
                {
                    Vec v1 = Consts.Center(t[0], t[1], t[3]);
                    Vec v2 = Consts.Center(t[1], t[2], t[3]);

                    Point p1 = new Point(v1[0], v1[1]);
                    Point p2 = new Point(v2[0], v2[1]);

                    cell.Points.Add(p1);
                    cell.Points.Add(p2);
                }
                else
                {
                    Vec v1 = Consts.Center(t[0], t[2], t[3]);

                    Point p1 = new Point(v1[0], v1[1]);

                    cell.Points.Add(p1);
                }

                q = new Vec()
                {
                    0, 1
                };
                p    = Globe.GetChunk(index + q).BiomeCenter;
                t[0] = (Vec)(new Polar(p[0], p[1] / 64)) + origin + (q * 200) + (location * 200);
                q    = new Vec()
                {
                    -1, 1
                };
                p    = Globe.GetChunk(index + q).BiomeCenter;
                t[1] = (Vec)(new Polar(p[0], p[1] / 64)) + origin + (q * 200) + (location * 200);
                q    = new Vec()
                {
                    -1, 0
                };
                p    = Globe.GetChunk(index + q).BiomeCenter;
                t[2] = (Vec)(new Polar(p[0], p[1] / 64)) + origin + (q * 200) + (location * 200);
                q    = new Vec()
                {
                    0, 0
                };
                p    = Globe.GetChunk(index + q).BiomeCenter;
                t[3] = (Vec)(new Polar(p[0], p[1] / 64)) + origin + (q * 200) + (location * 200);

                if (!Consts.IsInCirc(t))
                {
                    Vec v1 = Consts.Center(t[0], t[1], t[3]);
                    Vec v2 = Consts.Center(t[1], t[2], t[3]);

                    Point p1 = new Point(v1[0], v1[1]);
                    Point p2 = new Point(v2[0], v2[1]);

                    cell.Points.Add(p1);
                    cell.Points.Add(p2);
                }
                else
                {
                    Vec v1 = Consts.Center(t[0], t[2], t[3]);

                    Point p1 = new Point(v1[0], v1[1]);

                    cell.Points.Add(p1);
                }

                Cells[(int)location[0] + 1, (int)location[1] + 1] = cell;
                MainWindow.App.map.Children.Add(cell);

                Bases.Draw(index, location);
            }