public List <IData3DCollection> AddMapImages(BaseUtils.Map2d [] list)
        {
            if (list.Length > 0)
            {
                var datasetMapImg = Data3DCollection <TexturedQuadData> .Create("mapimage", Color.White, 1.0f);

                for (int i = 0; i < list.Length; i++)
                {
                    BaseUtils.Map2d map = list[i];

                    if (_cachedTextures.ContainsKey(map.FileName))
                    {
                        datasetMapImg.Add(_cachedTextures[map.FileName]);
                    }
                    else
                    {
                        Bitmap bmp = map.Image as Bitmap;      // either a stored one, or loaded

                        Vector3 centre = new Vector3((map.TopLeft.X + map.BottomRight.X) / 2, 0, (map.TopRight.Y + map.BottomLeft.Y) / 2);
                        float   width  = map.TopRight.X - map.BottomLeft.X;
                        float   height = map.TopLeft.Y - map.BottomRight.Y;         // its rectangular.. so does not really matter which left/right/top/bot you use

                        var texture = TexturedQuadData.FromBitmap(bmp, centre, TexturedQuadData.NoRotation, width, height);

                        _cachedTextures[map.FileName] = texture;
                        datasetMapImg.Add(texture);
                    }
                }
                _datasets.Add(datasetMapImg);
            }

            return(_datasets);
        }
        public List <IData3DCollection> AddCoarseGridLines()
        {
            var datasetGridLOD1 = Data3DCollection <LineData> .Create("gridNormal", CoarseGridLines, 0.6f);

            for (float x = MinGridPos.X; x <= MaxGridPos.X; x += gridunitSize)
            {
                datasetGridLOD1.Add(new LineData(x, 0, MinGridPos.Y, x, 0, MaxGridPos.Y));
            }

            for (float z = MinGridPos.Y; z <= MaxGridPos.Y; z += gridunitSize)
            {
                datasetGridLOD1.Add(new LineData(MinGridPos.X, 0, z, MaxGridPos.X, 0, z));
            }

            _datasets.Add(datasetGridLOD1);

            var datasetGridLOD2 = Data3DCollection <LineData> .Create("gridCoarse", CoarseGridLines, 0.6f);

            for (float x = MinGridPos.X; x <= MaxGridPos.X; x += gridunitSize * 10)
            {
                datasetGridLOD2.Add(new LineData(x, 0, MinGridPos.Y, x, 0, MaxGridPos.Y));
            }

            for (float z = MinGridPos.Y; z <= MaxGridPos.Y; z += gridunitSize * 10)
            {
                datasetGridLOD2.Add(new LineData(MinGridPos.X, 0, z, MaxGridPos.X, 0, z));
            }

            _datasets.Add(datasetGridLOD2);
            return(_datasets);
        }
        public List <IData3DCollection> AddNotedBookmarks(Bitmap map, Bitmap maptarget, float widthly, float heightly, Vector3 rotation, List <HistoryEntry> syslists)
        {
            var datasetbks = Data3DCollection <TexturedQuadData> .Create("bkmrs", Color.White, 1f);

            long bookmarknoted = TargetClass.GetTargetNotedSystem();

            if (syslists != null)
            {
                foreach (HistoryEntry vs in syslists.Where(s => s.IsLocOrJump))
                {
                    SystemNoteClass notecs = SystemNoteClass.GetNoteOnSystem(vs.System.Name);

                    if (notecs != null)         // if we have a note..
                    {
                        string note = notecs.Note.Trim();

                        if (note.Length > 0)
                        {
                            PointData pd = new PointData(vs.System.X, vs.System.Y, vs.System.Z);

                            Bitmap           touse      = (notecs.id == bookmarknoted) ? maptarget : map;
                            TexturedQuadData newtexture = TexturedQuadData.FromBitmap(touse, pd, rotation, widthly, heightly, 0, heightly / 2);
                            newtexture.Tag  = vs;
                            newtexture.Tag2 = 1;        // note mark
                            datasetbks.Add(newtexture);
                        }
                    }
                }
            }

            _datasets.Add(datasetbks);

            return(_datasets);
        }
Exemple #4
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            var dataset = Data3DCollection <PointData> .Create("Points", Color.Red, 2.0f);

            //for (int y = -500; y < 500; y += 20)
            //{
            //    for (int x = -500; x < 500; x += 20)
            //    {
            //        for (int z = -500; z < 500; z += 20)
            //            dataset.Add(new PointData(x, y, z));
            //    }
            //}

            Random rnd = new Random(202929);

            for (int s = 0; s < 10000; s++)
            {
                int x = rnd.Next(1000) - 500;
                int y = rnd.Next(1000) - 500;
                int z = rnd.Next(1000) - 500;
                dataset.Add(new PointData(x, y, z));
            }

            datasets.Add(dataset);

            var smalldatasetGrid = Data3DCollection <LineData> .Create("gridFine", Color.Yellow, 0.6f);

            for (float x = MinGridPos.X; x <= MaxGridPos.X; x += 1000)
            {
                smalldatasetGrid.Add(new LineData(x, 0, MinGridPos.Y, x, 0, MaxGridPos.Y));
            }

            for (float z = MinGridPos.Y; z <= MaxGridPos.Y; z += 1000)
            {
                smalldatasetGrid.Add(new LineData(MinGridPos.X, 0, z, MaxGridPos.X, 0, z));
            }

            datasets.Add(smalldatasetGrid);

            gltracker.Start(new Vector3(0, 0, 0), Vector3.Zero, 1F);
            gltracker.TravelSpeed = (ms) =>
            {
                float zoomlimited  = Math.Min(Math.Max(gltracker.Zoom.Current, 0.01F), 15.0F);
                float distance1sec = gltracker.MatrixCalc.ZoomDistance * (1.0f / zoomlimited);        // move Zoomdistance in one second, scaled by zoomY
                return(distance1sec * (float)ms / 1000.0f);
            };


            //
            //    w
            //
            //    distance1sec *= TravelSpeed;
            //public float TravelSpeed { get; private set; } = 1.0f;       // Distance speed, in units, (ZoomDistance / zoom) is the 1 second movement, use this to scale up/down

            //var distance = LastHandleInterval * (1.0f / zoomlimited);
        }
        public List <IData3DCollection> BuildRouteTri(List <ISystem> PlannedRoute)
        {
            if (PlannedRoute != null && PlannedRoute.Any())
            {
                var routeLines = Data3DCollection <LineData> .Create("PlannedRoute", PlannedRouteColor, 25.0f);

                ISystem prevSystem = PlannedRoute.First();
                foreach (ISystem point in PlannedRoute.Skip(1))
                {
                    routeLines.Add(new LineData(prevSystem.X, prevSystem.Y, prevSystem.Z, point.X, point.Y, point.Z));
                    prevSystem = point;
                }
                _datasets.Add(routeLines);
            }
            return(_datasets);
        }
        public List <IData3DCollection> AddFineGridLines()
        {
            int smallUnitSize    = gridunitSize / 10;
            var smalldatasetGrid = Data3DCollection <LineData> .Create("gridFine", FineGridLines, 0.6f);

            for (float x = MinGridPos.X; x <= MaxGridPos.X; x += smallUnitSize)
            {
                smalldatasetGrid.Add(new LineData(x, 0, MinGridPos.Y, x, 0, MaxGridPos.Y));
            }

            for (float z = MinGridPos.Y; z <= MaxGridPos.Y; z += smallUnitSize)
            {
                smalldatasetGrid.Add(new LineData(MinGridPos.X, 0, z, MaxGridPos.X, 0, z));
            }

            _datasets.Add(smalldatasetGrid);
            return(_datasets);
        }
        public List <IData3DCollection> AddStarBookmarks(Bitmap mapstar, Bitmap mapregion, Bitmap maptarget, Bitmap mapsurface, float widthly, float heightly, Vector3 rotation)
        {
            var datasetbks = Data3DCollection <TexturedQuadData> .Create("bkmrs", Color.White, 1f);

            long bookmarktarget = TargetClass.GetTargetBookmark();

            foreach (BookmarkClass bc in GlobalBookMarkList.Instance.Bookmarks)
            {
                Bitmap           touse      = (bc.id == bookmarktarget) ? maptarget : (bc.isRegion ? mapregion : (bc.hasPlanetaryMarks ? mapsurface : mapstar));
                TexturedQuadData newtexture = TexturedQuadData.FromBitmap(touse, new PointData(bc.x, bc.y, bc.z), rotation, widthly, heightly, 0, heightly / 2);
                newtexture.Tag  = bc;
                newtexture.Tag2 = 0;        // bookmark
                datasetbks.Add(newtexture);
            }

            _datasets.Add(datasetbks);

            return(_datasets);
        }
        public List <IData3DCollection> BuildSelected(ISystem centersystem, ISystem selectedsystem, GalacticMapObject selectedgmo, float widthly, float heightly, Vector3 rotation)
        {
            Bitmap selmark = SelectedMarker;

            if (centersystem != null)
            {
                var dataset = Data3DCollection <PointData> .Create("Center", CentredSystem, 5.0f);

                dataset.Add(new PointData(centersystem.X, centersystem.Y, centersystem.Z));
                _datasets.Add(dataset);
            }

            if (selectedsystem != null)
            {
                var datasetbks = Data3DCollection <TexturedQuadData> .Create("selstar", Color.White, 1f);

                TexturedQuadData newtexture = TexturedQuadData.FromBitmap(selmark, new PointData(selectedsystem.X, selectedsystem.Y, selectedsystem.Z), rotation, widthly, heightly / 2, 0, heightly / 4 + heightly / 16);
                newtexture.Tag = 0;
                datasetbks.Add(newtexture);
                _datasets.Add(datasetbks);
            }

            if (selectedgmo != null)
            {
                if (selectedgmo.Points.Count > 0)               // paranoia
                {
                    var datasetbks = Data3DCollection <TexturedQuadData> .Create("selgmo", Color.White, 1f);

                    long             gmotarget  = TargetClass.GetTargetGMO();
                    float            hoff       = (gmotarget == selectedgmo.ID) ? (heightly * gmoseltarget) : (heightly * gmoselonly);
                    TexturedQuadData newtexture = TexturedQuadData.FromBitmap(selmark, selectedgmo.Points[0].Convert(), rotation, widthly, heightly / 2, 0, hoff);
                    newtexture.Tag = 1;
                    datasetbks.Add(newtexture);
                    _datasets.Add(datasetbks);
                }
            }

            return(_datasets);
        }
        // DotColour = transparent, use the map colour associated with each entry.  Else use this colour for all

        public List <IData3DCollection> BuildSystems(bool DrawLines, bool DrawDots, Color DotColour, List <HistoryEntry> syslists)
        {
            // we use the expanded capability of Line and Point to holds colours for each element instead of the previous sorting system
            // This means less submissions to GL.

            if (syslists.Any())
            {
                if (DrawLines)
                {
                    var datasetl = Data3DCollection <LineData> .Create("visitedstarslines", Color.Transparent, 2.0f);

                    Vector3d?lastpos = null;

                    Color drawcolour = Color.Green;

                    foreach (HistoryEntry sp in syslists)
                    {
                        if (sp.EntryType == JournalTypeEnum.Resurrect || sp.EntryType == JournalTypeEnum.Died)
                        {
                            lastpos = null;
                        }
                        else if (sp.IsLocOrJump && sp.System.HasCoordinate)
                        {
                            if (sp.journalEntry is IJournalJumpColor)
                            {
                                drawcolour = Color.FromArgb(((IJournalJumpColor)sp.journalEntry).MapColor);
                                if (drawcolour.GetBrightness() < 0.05)
                                {
                                    drawcolour = Color.Red;
                                }
                            }

                            if (lastpos.HasValue)
                            {
                                datasetl.Add(new LineData(sp.System.X, sp.System.Y, sp.System.Z,
                                                          lastpos.Value.X, lastpos.Value.Y, lastpos.Value.Z, drawcolour));
                            }

                            lastpos = new Vector3d(sp.System.X, sp.System.Y, sp.System.Z);
                        }
                    }

                    _datasets.Add(datasetl);
                }

                if (DrawDots)
                {
                    var datasetp = Data3DCollection <PointData> .Create("visitedstarsdots", DotColour, 2.0f);

                    Color drawcolour = Color.Green;

                    foreach (HistoryEntry vs in syslists)
                    {
                        if (vs.System.HasCoordinate)
                        {
                            if (vs.journalEntry is IJournalJumpColor)
                            {
                                drawcolour = Color.FromArgb(((IJournalJumpColor)vs.journalEntry).MapColor);
                                if (drawcolour.GetBrightness() < 0.05)
                                {
                                    drawcolour = Color.Red;
                                }
                            }

                            datasetp.Add(new PointData(vs.System.X, vs.System.Y, vs.System.Z, drawcolour));
                        }
                    }

                    _datasets.Add(datasetp);
                }
            }

            return(_datasets);
        }
        public List <IData3DCollection> AddGridCoords()
        {
            string fontname = "MS Sans Serif";

            {
                Font fnt = BaseUtils.FontLoader.GetFont(fontname, 20F);

                int    bitmapwidth, bitmapheight;
                Bitmap text_bmp = new Bitmap(300, 30);
                using (Graphics g = Graphics.FromImage(text_bmp))
                {
                    SizeF sz = g.MeasureString("-99999,-99999", fnt);
                    bitmapwidth  = (int)sz.Width + 4;
                    bitmapheight = (int)sz.Height + 4;
                }
                var datasetMapImgLOD1 = Data3DCollection <TexturedQuadData> .Create("text bitmap LOD1", Color.White, 1.0f);

                var datasetMapImgLOD2 = Data3DCollection <TexturedQuadData> .Create("text bitmap LOD2", Color.FromArgb(128, Color.White), 1.0f);

                int textheightly = 50;
                int textwidthly  = textheightly * bitmapwidth / bitmapheight;

                int gridwideLOD1 = (int)Math.Floor((MaxGridPos.X - MinGridPos.X) / gridunitSize + 1);
                int gridhighLOD1 = (int)Math.Floor((MaxGridPos.Y - MinGridPos.Y) / gridunitSize + 1);
                int gridwideLOD2 = (int)Math.Floor((MaxGridPos.X - MinGridPos.X) / (gridunitSize * 10) + 1);
                int gridhighLOD2 = (int)Math.Floor((MaxGridPos.Y - MinGridPos.Y) / (gridunitSize * 10) + 1);
                int texwide      = 1024 / bitmapwidth;
                int texhigh      = 1024 / bitmapheight;
                int numtexLOD1   = (int)Math.Ceiling((gridwideLOD1 * gridhighLOD1) * 1.0 / (texwide * texhigh));
                int numtexLOD2   = (int)Math.Ceiling((gridwideLOD2 * gridhighLOD2) * 1.0 / (texwide * texhigh));

                List <TexturedQuadData> basetexturesLOD1 = Enumerable.Range(0, numtexLOD1).Select(i => new TexturedQuadData(null, null, new Bitmap(1024, 1024))).ToList();
                List <TexturedQuadData> basetexturesLOD2 = Enumerable.Range(0, numtexLOD2).Select(i => new TexturedQuadData(null, null, new Bitmap(1024, 1024))).ToList();

                for (float x = MinGridPos.X; x < MaxGridPos.X; x += gridunitSize)
                {
                    for (float z = MinGridPos.Y; z <= MaxGridPos.Y; z += gridunitSize)
                    {
                        int num   = (int)(Math.Floor((x - MinGridPos.X) / gridunitSize) * gridwideLOD1 + Math.Floor((z - MinGridPos.Y) / gridunitSize));
                        int tex_x = (num % texwide) * bitmapwidth;
                        int tex_y = ((num / texwide) % texhigh) * bitmapheight;
                        int tex_n = num / (texwide * texhigh);

                        //Console.WriteLine("num {0} tex_x {1} tex_y {2} txt_n {3}", num, tex_x, tex_y, tex_n);

                        DrawGridBitmap(basetexturesLOD1[tex_n].Texture, x, z, fnt, tex_x, tex_y);
                        datasetMapImgLOD1.Add(basetexturesLOD1[tex_n].Horz(
                                                  x, z,
                                                  x + textwidthly, z + textheightly,
                                                  tex_x, tex_y, tex_x + bitmapwidth, tex_y + bitmapheight
                                                  ));
                    }
                }

                for (float x = MinGridPos.X; x < MaxGridPos.X; x += gridunitSize * 10)
                {
                    for (float z = MinGridPos.Y; z <= MaxGridPos.Y; z += gridunitSize * 10)
                    {
                        int num   = (int)(Math.Floor((x - MinGridPos.X) / (gridunitSize * 10)) * gridwideLOD2 + Math.Floor((z - MinGridPos.Y) / (gridunitSize * 10)));
                        int tex_x = (num % texwide) * bitmapwidth;
                        int tex_y = ((num / texwide) % texhigh) * bitmapheight;
                        int tex_n = num / (texwide * texhigh);

                        DrawGridBitmap(basetexturesLOD2[tex_n].Texture, x, z, fnt, tex_x, tex_y);
                        datasetMapImgLOD2.Add(basetexturesLOD2[tex_n].Horz(
                                                  x, z,
                                                  x + textwidthly * 10, z + textheightly * 10,
                                                  tex_x, tex_y, tex_x + bitmapwidth, tex_y + bitmapheight
                                                  ));
                    }
                }

                _datasets.Add(datasetMapImgLOD1);
                _datasets.Add(datasetMapImgLOD2);
            }

            return(_datasets);
        }
        public List <IData3DCollection> AddGalMapObjectsToDataset(GalacticMapping galmap, Bitmap target, float widthly, float heightly, Vector3 rotation, bool namethem, Color textc, int gmosel)
        {
            var datasetbks = Data3DCollection <TexturedQuadData> .Create("galobj", Color.White, 1f);

            if (galmap != null && galmap.Loaded)
            {
                long gmotarget = TargetClass.GetTargetGMO();

                foreach (GalacticMapObject gmo in galmap.GalacticMapObjects)
                {
                    bool enabled = (gmosel & (1 << gmo.GalMapType.Index)) != 0;         // if selected
                    if (enabled && gmo.GalMapType.VisibleType.HasValue)
                    {
                        Bitmap touse = GalMapTypeIcons[gmo.GalMapType.VisibleType.Value] as Bitmap; // under our control, so must have it

                        if (touse != null && gmo.Points.Count > 0)                                  // if it has an image its a point object , and has co-ord
                        {
                            Vector3          pd          = gmo.Points[0].Convert();
                            string           tucachename = "GalMapType:" + gmo.GalMapType.TypeName;
                            TexturedQuadData tubasetex   = null;

                            if (_cachedTextures.ContainsKey(tucachename))
                            {
                                tubasetex = _cachedTextures[tucachename];
                            }
                            else
                            {
                                tubasetex = TexturedQuadData.FromBitmap(touse, pd, rotation, widthly, heightly);
                                _cachedTextures[tucachename] = tubasetex;
                            }


                            TexturedQuadData newtexture = TexturedQuadData.FromBaseTexture(tubasetex, pd, rotation, widthly, heightly);
                            newtexture.Tag  = gmo;
                            newtexture.Tag2 = 0;
                            datasetbks.Add(newtexture);

                            if (gmo.ID == gmotarget)
                            {
                                TexturedQuadData ntag = TexturedQuadData.FromBitmap(target, pd, rotation, widthly, heightly, 0, heightly * gmotargetoff);
                                ntag.Tag  = gmo;
                                ntag.Tag2 = 2;
                                datasetbks.Add(ntag);
                            }
                        }
                    }
                }

                if (namethem)
                {
                    bool useaggregate = true;

                    if (useaggregate)
                    {
                        foreach (GalMapType t in GalMapType.GalTypes)
                        {
                            bool enabled = (gmosel & (1 << t.Index)) != 0;         // if selected
                            if (enabled)
                            {
                                Bitmap                  bmp      = null;
                                TexturedQuadData        nbasetex = null;
                                List <TexturedQuadData> ntex     = new List <TexturedQuadData>();

                                string ncachename = "GalMapNames:" + t.TypeName + textc.ToString();
                                if (_cachedBitmaps.ContainsKey(ncachename) && _cachedTextures.ContainsKey(ncachename))
                                {
                                    bmp      = _cachedBitmaps[ncachename];
                                    nbasetex = _cachedTextures[ncachename];
                                    ntex     = nbasetex.Children.ToList();
                                }
                                else
                                {
                                    List <GalacticMapObject> tgmos = galmap.GalacticMapObjects.Where(o => o.GalMapType.TypeName == t.TypeName && o.Points.Count > 0).ToList();

                                    float            maxheight = 32;
                                    List <Rectangle> bounds    = new List <Rectangle>();
                                    List <float>     widths    = new List <float>();

                                    Bitmap stringstarmeasurebitmap = new Bitmap(1, 1);
                                    using (Graphics g = Graphics.FromImage(stringstarmeasurebitmap))
                                    {
                                        foreach (GalacticMapObject gmo in tgmos)
                                        {
                                            SizeF sz = g.MeasureString(gmo.Name, gmostarfont);
                                            if (sz.Height > maxheight)
                                            {
                                                maxheight = sz.Height;
                                            }
                                            widths.Add(sz.Width);
                                        }
                                    }

                                    int textheight = (int)(maxheight + 4);

                                    int x = 0;
                                    int y = 0;

                                    foreach (float twidth in widths)
                                    {
                                        int w = (int)(twidth + 4);

                                        if ((w + x) > 1024)
                                        {
                                            x = 0;
                                            y = y + textheight;

                                            if (((y + textheight) % 1024) < (y % 1024))
                                            {
                                                y = y + ((1024 - y) % 1024);
                                            }
                                        }

                                        bounds.Add(new Rectangle(x, y, w, textheight));
                                        x = x + w;
                                    }

                                    y = y + textheight;

                                    bmp      = new Bitmap(1024, y);
                                    nbasetex = new TexturedQuadData(null, null, bmp);

                                    using (Graphics g = Graphics.FromImage(bmp))
                                    {
                                        for (int i = 0; i < tgmos.Count; i++)
                                        {
                                            GalacticMapObject gmo       = tgmos[i];
                                            string            cachename = gmo.Name + textc.ToString();
                                            Vector3           pd        = gmo.Points[0].Convert();
                                            Rectangle         clip      = bounds[i];
                                            Point             pos       = clip.Location;
                                            g.SetClip(clip);
                                            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.None;
                                            using (Brush br = new SolidBrush(textc))
                                                g.DrawString(gmo.Name, gmostarfont, br, pos);
                                            g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.Default;

                                            TexturedQuadData tex = TexturedQuadData.FromBaseTexture(nbasetex, pd, rotation, clip,
                                                                                                    (widthly / 10 * gmo.Name.Length),
                                                                                                    (heightly / 3),
                                                                                                    0, heightly * gmonameoff);
                                            tex.Tag  = gmo;
                                            tex.Tag2 = 1;
                                            _cachedTextures[cachename] = tex;
                                            ntex.Add(tex);
                                        }
                                    }

                                    _cachedBitmaps[ncachename]  = bmp;
                                    _cachedTextures[ncachename] = nbasetex;
                                }

                                foreach (TexturedQuadData tex in ntex)
                                {
                                    datasetbks.Add(tex);
                                }
                            }
                        }
                    }
                    else
                    {
                        foreach (GalacticMapObject gmo in galmap.GalacticMapObjects)
                        {
                            bool enabled = (gmosel & (1 << gmo.GalMapType.Index)) != 0;         // if selected
                            if (enabled && gmo.Points.Count > 0)
                            {
                                Vector3 pd        = gmo.Points[0].Convert();
                                Bitmap  map       = null;
                                string  cachename = gmo.Name + textc.ToString();

                                if (_cachedBitmaps.ContainsKey(cachename))      // cache them, they take a long time to compute..
                                {
                                    map = _cachedBitmaps[cachename];
                                }
                                else
                                {
                                    map = DrawString(gmo.Name, textc, gmostarfont);
                                    _cachedBitmaps.Add(cachename, map);
                                }

                                TexturedQuadData ntext = TexturedQuadData.FromBitmap(map, pd, rotation,
                                                                                     (widthly / 10 * gmo.Name.Length),
                                                                                     (heightly / 3),
                                                                                     0, heightly * gmonameoff);
                                ntext.Tag  = gmo;
                                ntext.Tag2 = 1;
                                datasetbks.Add(ntext);
                            }
                        }
                    }
                }
            }

            _datasets.Add(datasetbks);

            return(_datasets);
        }
        public List <IData3DCollection> AddGalMapRegionsToDataset(GalacticMapping galmap, bool colourregions, int gmosel)
        {
            var polydataset    = new PolygonCollection("regpolys", Color.White, 1f, OpenTK.Graphics.OpenGL.PrimitiveType.Triangles);   // ORDER AND NUMBER v.Important
            var outlinedataset = new PolygonCollection("reglines", Color.White, 1f, OpenTK.Graphics.OpenGL.PrimitiveType.LineLoop);    // DrawStars picks them out in a particular order
            var datasetbks     = Data3DCollection <TexturedQuadData> .Create("regtext", Color.White, 1f);

            if (galmap != null && galmap.Loaded)
            {
                long gmotarget = TargetClass.GetTargetGMO();

                int cindex = 0;
                foreach (GalacticMapObject gmo in galmap.GalacticMapObjects)
                {
                    bool enabled = (gmosel & (1 << gmo.GalMapType.Index)) != 0;         // if selected

                    if (enabled && gmo.GalMapType.Group == GalMapType.GroupType.Regions)
                    {
                        string name = gmo.Name;

                        Color[] array = new Color[] { Color.Red, Color.Green, Color.Blue,
                                                      Color.Brown, Color.Crimson, Color.Coral,
                                                      Color.Aqua, Color.Yellow, Color.Violet,
                                                      Color.Sienna, Color.Silver, Color.Salmon,
                                                      Color.Pink, Color.AntiqueWhite, Color.Beige,
                                                      Color.DarkCyan, Color.DarkGray, Color.ForestGreen, Color.LightSkyBlue,
                                                      Color.Lime, Color.Maroon, Color.Olive, Color.SteelBlue };
                        Color c = array[cindex++ % array.Length];

                        List <Vector2> polygonxz = new List <Vector2>();                              // needs it in x/z and in vector2's
                        foreach (var pd in gmo.Points)
                        {
                            polygonxz.Add(new Vector2((float)pd.X, (float)pd.Z));                   // can be concave and wound the wrong way..
                        }
                        Vector2 size, avg;
                        Vector2 centre = PolygonTriangulator.Centre(polygonxz, out size, out avg);        // default geographic centre (min x/z + max x/z/2) used in case poly triangulate fails (unlikely)

                        List <List <Vector2> > polys = PolygonTriangulator.Triangulate(polygonxz, false); // cut into convex polygons first - because we want the biggest possible area for naming purposes
                        //Console.WriteLine("Region {0} decomposed to {1} ", name, polys.Count);

                        Vector2 bestpos  = centre;
                        Vector2 bestsize = new Vector2(250, 250 / 5);

                        if (polys.Count > 0)                                                     // just in case..
                        {
                            centre = PolygonTriangulator.Centroids(polys);                       // weighted mean of the centroids
                            //Bitmap map3 = DrawString(String.Format("O{0}", cindex - 1), Color.White, gmostarfont); TexturedQuadData ntext3 = TexturedQuadData.FromBitmap(map3, new PointData(centre.X, 0, centre.Y), TexturedQuadData.NoRotation, 2000, 500); datasetbks.Add(ntext3);

                            float mindist = float.MaxValue;

                            foreach (List <Vector2> points in polys)                         // now for every poly
                            {
                                if (colourregions)
                                {
                                    Color regcol = Color.FromArgb(64, c.R, c.G, c.B);

                                    if (points.Count == 3)                                    // already a triangle..
                                    {
                                        polydataset.Add(new Polygon(points, 1, regcol));
                                        //outlinedataset.Add(new Polygon(points, 1, Color.FromArgb(255, 255, 255, 0))); //DEBUG
                                    }
                                    else
                                    {
                                        List <List <Vector2> > polytri = PolygonTriangulator.Triangulate(points, true);    // cut into triangles not polygons

                                        foreach (List <Vector2> pt in polytri)
                                        {
                                            polydataset.Add(new Polygon(pt, 1, regcol));
                                            // outlinedataset.Add(new Polygon(pt, 1, Color.FromArgb(255, 255, 255, 0))); // DEBUG
                                        }
                                    }
                                }

                                //float area; Vector2 polycentrepos = PolygonTriangulator.Centroid(points,out area); Bitmap map2 = DrawString(String.Format("X") , Color.White, gmostarfont);  TexturedQuadData ntext2 = TexturedQuadData.FromBitmap(map2, new PointData(polycentrepos.X, 0, polycentrepos.Y), TexturedQuadData.NoRotation, 1000, 200); datasetbks.Add(ntext2);

                                PolygonTriangulator.FitInsideConvexPoly(points, centre, new Vector2(3000, 3000 / 5), new Vector2(200, 200),
                                                                        ref mindist, ref bestpos, ref bestsize, bestsize.X / 2);
                            }
                        }

                        Bitmap           map       = DrawString(gmo.Name, Color.White, gmostarfont);
                        PointData        bitmappos = new PointData(bestpos.X, 0, bestpos.Y);
                        TexturedQuadData ntext     = TexturedQuadData.FromBitmap(map, bitmappos, TexturedQuadData.NoRotation,
                                                                                 bestsize.X, bestsize.Y);

                        datasetbks.Add(ntext);

                        outlinedataset.Add(new Polygon(polygonxz, 1, Color.FromArgb(255, 128, 128, 128)));
                    }
                }
            }

            _datasets.Add(polydataset);
            _datasets.Add(outlinedataset);
            _datasets.Add(datasetbks);
            return(_datasets);
        }