Beispiel #1
0
        // Segment changes
        private void segindex_ValueChanged(object sender, EventArgs e)
        {
            Seg     sg = mode.Segs[(int)segindex.Value];
            Linedef ld = null;             //mxd

            if (sg.lineindex != -1)
            {
                ld = General.Map.Map.GetLinedefByIndex(sg.lineindex);                                //mxd
            }
            lineindex.Text   = sg.lineindex.ToString();
            startvertex.Text = sg.startvertex + "  (" + mode.Vertices[sg.startvertex].x + ", " + mode.Vertices[sg.startvertex].y + ")";
            endvertex.Text   = sg.endvertex + "  (" + mode.Vertices[sg.endvertex].x + ", " + mode.Vertices[sg.endvertex].y + ")";
            segside.Text     = sg.leftside ? "Back" : "Front";
            segangle.Text    = Angle2D.RealToDoom(sg.angle) + "\u00B0";
            segoffset.Text   = sg.offset + " mp";

            if (ld != null)            //mxd
            {
                sideindex.Text   = sg.leftside ? ld.Back.Index.ToString() : ld.Front.Index.ToString();
                sectorindex.Text = sg.leftside ? ld.Back.Sector.Index.ToString() : ld.Front.Sector.Index.ToString();
            }
            else
            {
                sideindex.Text   = "None";
                sectorindex.Text = "None";
            }

            General.Interface.RedrawDisplay();
        }
Beispiel #2
0
        /// <summary>
        /// Build the polygon for a specific subsector
        /// </summary>
        private void BuildSubsectorPoly(int ss, IEnumerable <Split> nodesplits)
        {
            // Begin with a giant square polygon that covers the entire map
            List <Vector2D> poly = new List <Vector2D>(16);

            poly.Add(new Vector2D(-General.Map.FormatInterface.MaxCoordinate, General.Map.FormatInterface.MaxCoordinate));
            poly.Add(new Vector2D(General.Map.FormatInterface.MaxCoordinate, General.Map.FormatInterface.MaxCoordinate));
            poly.Add(new Vector2D(General.Map.FormatInterface.MaxCoordinate, -General.Map.FormatInterface.MaxCoordinate));
            poly.Add(new Vector2D(-General.Map.FormatInterface.MaxCoordinate, -General.Map.FormatInterface.MaxCoordinate));

            // Crop the polygon by the node tree splits
            foreach (Split s in nodesplits)
            {
                CropPolygon(poly, s);
            }

            // Crop the polygon by the subsector segs
            for (int i = 0; i < ssectors[ss].numsegs; i++)
            {
                Split s;
                Seg   sg = segs[ssectors[ss].firstseg + i];

                //mxd. Sanity check, because some segs in Doom maps refer to non-existing verts.
                if (sg.startvertex > verts.Length - 1 || sg.endvertex > verts.Length - 1)
                {
                    continue;
                }

                s.pos   = verts[sg.startvertex];
                s.delta = verts[sg.endvertex] - verts[sg.startvertex];
                CropPolygon(poly, s);
            }

            if (poly.Count > 1)
            {
                // Remove any zero-length lines
                Vector2D prevpoint = poly[0];
                for (int i = poly.Count - 1; i >= 0; i--)
                {
                    if (Vector2D.DistanceSq(poly[i], prevpoint) < 0.001f)
                    {
                        poly.RemoveAt(i);
                    }
                    else
                    {
                        prevpoint = poly[i];
                    }
                }
            }

            ssectors[ss].points = poly.ToArray();

            // Setup vertices for rendering
            if (poly.Count >= 3)
            {
                FlatVertex[] fverts   = new FlatVertex[(poly.Count - 2) * 3];
                int          intcolor = PixelColor.FromColor(Color.Gray).WithAlpha(100).ToInt();
                int          pi       = 0;
                for (int t = 0; t < (poly.Count - 2); t++)
                {
                    fverts[pi].x     = poly[0].x;
                    fverts[pi].y     = poly[0].y;
                    fverts[pi].c     = intcolor;
                    fverts[pi + 1].x = poly[t + 1].x;
                    fverts[pi + 1].y = poly[t + 1].y;
                    fverts[pi + 1].c = intcolor;
                    fverts[pi + 2].x = poly[t + 2].x;
                    fverts[pi + 2].y = poly[t + 2].y;
                    fverts[pi + 2].c = intcolor;
                    pi += 3;
                }
                ssectors[ss].vertices = fverts;
            }
        }
Beispiel #3
0
        // Draw the display
        public override void OnRedrawDisplay()
        {
            base.OnRedrawDisplay();

            if (form == null)
            {
                return;
            }

            if (renderer.StartPlotter(true))
            {
                if (form.SelectedTab == 0)
                {
                    // Render all subsectors in original color
                    for (int si = 0; si < ssectors.Length; si++)
                    {
                        Subsector s = ssectors[si];
                        PlotSubsectorLines(s.points, PixelColor.FromColor(Color.Gray));
                    }

                    if (mouseinssector > -1)
                    {
                        PlotSubsectorLines(ssectors[mouseinssector].points, General.Colors.Highlight);
                    }

                    // Draw additional vertices
                    if (form.ShowSegsVertices)
                    {
                        for (int i = General.Map.Map.Vertices.Count; i < verts.Length; i++)
                        {
                            renderer.PlotVertexAt(verts[i], ColorCollection.VERTICES);
                        }
                    }
                }

                if (form.SelectedTab == 1)
                {
                    renderer.PlotLinedefSet(General.Map.Map.Linedefs);

                    // Render selected node split
                    if ((form.ViewSplitIndex >= 0) && (form.ViewSplitIndex < nodes.Length))
                    {
                        Node n = nodes[form.ViewSplitIndex];

                        // Draw parent splits
                        int parentsplit = n.parent;
                        while (parentsplit > -1)
                        {
                            Node pn = nodes[parentsplit];
                            renderer.PlotLine(pn.linestart, pn.linestart + pn.linedelta, General.Colors.Selection);
                            parentsplit = pn.parent;
                        }

                        // Draw this split
                        renderer.PlotLine(n.linestart, n.linestart + n.linedelta, General.Colors.Highlight);
                    }
                }

                if (form.SelectedTab == 2)
                {
                    renderer.PlotLinedefSet(General.Map.Map.Linedefs);

                    // Render selected subsector
                    if ((form.ViewSubsectorIndex >= 0) && (form.ViewSubsectorIndex < ssectors.Length))
                    {
                        Subsector s = ssectors[form.ViewSubsectorIndex];
                        PlotSubsectorLines(s.points, General.Colors.Highlight);
                    }

                    // Draw selected segment
                    if (form.ViewSegIndex > -1)
                    {
                        Seg sg = segs[form.ViewSegIndex];
                        renderer.PlotLine(verts[sg.startvertex], verts[sg.endvertex], General.Colors.Selection);
                    }
                }

                renderer.Finish();
            }

            if (renderer.StartOverlay(true))
            {
                switch (form.SelectedTab)
                {
                case 0:
                    if (mouseinssector > -1)
                    {
                        // Render all subsectors in original color
                        for (int si = 0; si < ssectors.Length; si++)
                        {
                            Subsector s = ssectors[si];
                            DrawSubsectorArea(s.vertices);
                        }
                        DrawSubsectorArea(ssectors[mouseinssector].vertices, General.Colors.Highlight);
                    }
                    else
                    {
                        // Render all subsectors with distinct colors
                        for (int si = 0; si < ssectors.Length; si++)
                        {
                            Subsector  s     = ssectors[si];
                            PixelColor color = distinctcolors[si % distinctcolors.Count];
                            DrawSubsectorArea(s.vertices, color);
                        }
                    }
                    break;

                case 1:
                    if ((form.ViewSplitIndex >= 0) && (form.ViewSplitIndex < nodes.Length))
                    {
                        Node n = nodes[form.ViewSplitIndex];

                        // Draw areas. We draw these first, because they would otherwise erase any splits we want to show.
                        DrawSplitArea(n.leftbox, form.ViewSplitIndex, true, new PixelColor(100, 50, 80, 255));
                        DrawSplitArea(n.rightbox, form.ViewSplitIndex, false, new PixelColor(100, 20, 220, 20));

                        // Draw parent splits
                        int parentsplit = n.parent;
                        while (parentsplit > -1)
                        {
                            Node pn = nodes[parentsplit];
                            renderer.RenderLine(pn.linestart, pn.linestart + pn.linedelta, 1f, General.Colors.Selection, true);
                            parentsplit = pn.parent;
                        }

                        // Draw this split
                        renderer.RenderLine(n.linestart, n.linestart + n.linedelta, 1f, General.Colors.Highlight, true);
                    }
                    break;

                case 2:
                    if ((form.ViewSubsectorIndex >= 0) && (form.ViewSubsectorIndex < ssectors.Length))
                    {
                        Subsector s = ssectors[form.ViewSubsectorIndex];

                        // Draw area
                        DrawSubsectorArea(s.vertices, General.Colors.Highlight);

                        // Draw selected segment
                        if (form.ViewSegIndex > -1)
                        {
                            Seg sg = segs[form.ViewSegIndex];
                            renderer.RenderLine(verts[sg.startvertex], verts[sg.endvertex], 1f, General.Colors.Selection, true);
                        }
                    }
                    break;
                }

                renderer.Finish();
            }

            renderer.Present();
        }