diff --git a/Source/Builder.csproj b/Source/Builder.csproj index 924d9cd7..d6cd3614 100644 --- a/Source/Builder.csproj +++ b/Source/Builder.csproj @@ -116,8 +116,7 @@ - - + diff --git a/Source/BuilderModes/ClassicModes/DrawGeometryMode.cs b/Source/BuilderModes/ClassicModes/DrawGeometryMode.cs index 1b682aea..ecfacc2f 100644 --- a/Source/BuilderModes/ClassicModes/DrawGeometryMode.cs +++ b/Source/BuilderModes/ClassicModes/DrawGeometryMode.cs @@ -488,14 +488,14 @@ namespace CodeImp.DoomBuilder.BuilderModes { // Find the shortest, closest path between these lines List> paths = new List>(8); - paths.Add(SectorTools.FindClosestPath(l1, true, l2, true, true)); - paths.Add(SectorTools.FindClosestPath(l1, true, l2, false, true)); - paths.Add(SectorTools.FindClosestPath(l1, false, l2, true, true)); - paths.Add(SectorTools.FindClosestPath(l1, false, l2, false, true)); - paths.Add(SectorTools.FindClosestPath(l2, true, l1, true, true)); - paths.Add(SectorTools.FindClosestPath(l2, true, l1, false, true)); - paths.Add(SectorTools.FindClosestPath(l2, false, l1, true, true)); - paths.Add(SectorTools.FindClosestPath(l2, false, l1, false, true)); + paths.Add(Tools.FindClosestPath(l1, true, l2, true, true)); + paths.Add(Tools.FindClosestPath(l1, true, l2, false, true)); + paths.Add(Tools.FindClosestPath(l1, false, l2, true, true)); + paths.Add(Tools.FindClosestPath(l1, false, l2, false, true)); + paths.Add(Tools.FindClosestPath(l2, true, l1, true, true)); + paths.Add(Tools.FindClosestPath(l2, true, l1, false, true)); + paths.Add(Tools.FindClosestPath(l2, false, l1, true, true)); + paths.Add(Tools.FindClosestPath(l2, false, l1, false, true)); foreach(List p in paths) if((p != null) && ((shortestpath == null) || (p.Count < shortestpath.Count))) shortestpath = p; @@ -591,7 +591,7 @@ namespace CodeImp.DoomBuilder.BuilderModes foreach(Linedef ld in newlines) { // Find closest path starting with the front of this linedef - List pathlines = SectorTools.FindClosestPath(ld, true, true); + List pathlines = Tools.FindClosestPath(ld, true, true); if(pathlines != null) { // Make polygon @@ -606,7 +606,7 @@ namespace CodeImp.DoomBuilder.BuilderModes // flip the line if it is not helping. // Find closest path starting with the back of this linedef - pathlines = SectorTools.FindClosestPath(ld, false, true); + pathlines = Tools.FindClosestPath(ld, false, true); if(pathlines != null) { // Make polygon @@ -658,13 +658,13 @@ namespace CodeImp.DoomBuilder.BuilderModes if(!frontsdone[i]) { // Find a way to create a sector here - List sectorlines = SectorTools.FindPotentialSectorAt(ld, true); + List sectorlines = Tools.FindPotentialSectorAt(ld, true); if(sectorlines != null) { sidescreated = true; // Make the new sector - Sector newsector = SectorTools.MakeSector(sectorlines); + Sector newsector = Tools.MakeSector(sectorlines); // Go for all sidedefs in this new sector foreach(Sidedef sd in newsector.Sidedefs) @@ -690,7 +690,7 @@ namespace CodeImp.DoomBuilder.BuilderModes if(!backsdone[i]) { // Find a way to create a sector here - List sectorlines = SectorTools.FindPotentialSectorAt(ld, false); + List sectorlines = Tools.FindPotentialSectorAt(ld, false); if(sectorlines != null) { // We don't always want to create a new sector on the back sides @@ -716,7 +716,7 @@ namespace CodeImp.DoomBuilder.BuilderModes sidescreated = true; // Join the new sector - Sector newsector = SectorTools.JoinSector(sectorlines, joinsidedef); + Sector newsector = Tools.JoinSector(sectorlines, joinsidedef); // Go for all sidedefs in this new sector foreach(Sidedef sd in newsector.Sidedefs) diff --git a/Source/BuilderModes/ClassicModes/EditSelectionMode.cs b/Source/BuilderModes/ClassicModes/EditSelectionMode.cs index ffddb345..11f3a360 100644 --- a/Source/BuilderModes/ClassicModes/EditSelectionMode.cs +++ b/Source/BuilderModes/ClassicModes/EditSelectionMode.cs @@ -432,10 +432,6 @@ namespace CodeImp.DoomBuilder.BuilderModes // This checks and returns the grip the mouse pointer is in private Grip CheckMouseGrip() { - // Make polygon from corners - Polygon rectpoly = new Polygon(); - rectpoly.AddRange(corners); - if(PointInRectF(resizegrips[0], mousemappos)) return Grip.SizeN; else if(PointInRectF(resizegrips[2], mousemappos)) @@ -452,7 +448,7 @@ namespace CodeImp.DoomBuilder.BuilderModes return Grip.RotateRB; else if(PointInRectF(rotategrips[3], mousemappos)) return Grip.RotateLB; - else if(rectpoly.Intersect(mousemappos)) + else if(Tools.PointInPolygon(corners, mousemappos)) return Grip.Main; else return Grip.None; diff --git a/Source/BuilderModes/ClassicModes/MakeSectorMode.cs b/Source/BuilderModes/ClassicModes/MakeSectorMode.cs index 6c96a6fb..4b353913 100644 --- a/Source/BuilderModes/ClassicModes/MakeSectorMode.cs +++ b/Source/BuilderModes/ClassicModes/MakeSectorMode.cs @@ -154,7 +154,7 @@ namespace CodeImp.DoomBuilder.BuilderModes // Find new sector General.Interface.SetCursor(Cursors.AppStarting); nearestside = newnearest; - allsides = SectorTools.FindPotentialSectorAt(mousemappos); + allsides = Tools.FindPotentialSectorAt(mousemappos); if(allsides != null) { alllines = new List(allsides.Count); @@ -289,7 +289,7 @@ namespace CodeImp.DoomBuilder.BuilderModes General.Interface.SetCursor(Cursors.WaitCursor); General.Settings.FindDefaultDrawSettings(); General.Map.UndoRedo.CreateUndo("Make Sector", UndoGroup.None, 0); - Sector s = SectorTools.MakeSector(allsides); + Sector s = Tools.MakeSector(allsides); General.Interface.SetCursor(Cursors.Default); // Quickly flash this sector to indicate it was created @@ -334,7 +334,7 @@ namespace CodeImp.DoomBuilder.BuilderModes General.Interface.SetCursor(Cursors.WaitCursor); General.Settings.FindDefaultDrawSettings(); General.Map.UndoRedo.CreateUndo("Make Sector", UndoGroup.None, 0); - Sector s = SectorTools.MakeSector(allsides); + Sector s = Tools.MakeSector(allsides); General.Interface.SetCursor(Cursors.Default); // Edit the sector diff --git a/Source/BuilderModes/ClassicModes/SectorsMode.cs b/Source/BuilderModes/ClassicModes/SectorsMode.cs index 09c56335..532145ee 100644 --- a/Source/BuilderModes/ClassicModes/SectorsMode.cs +++ b/Source/BuilderModes/ClassicModes/SectorsMode.cs @@ -56,6 +56,9 @@ namespace CodeImp.DoomBuilder.BuilderModes protected Sector highlighted; private Association highlightasso = new Association(); + // TEST: + private Vector2D labelpos; + // Interface protected bool editpressed; @@ -151,6 +154,12 @@ namespace CodeImp.DoomBuilder.BuilderModes // New association highlights something? if((s != null) && (s.Tag > 0)) completeredraw = true; + // TEST: + if(s != null) + { + labelpos = Tools.FindLabelPosition(s, 30.0f / renderer.Scale); + } + // If we're changing associations, then we // need to redraw the entire display if(completeredraw) @@ -181,7 +190,7 @@ namespace CodeImp.DoomBuilder.BuilderModes // Render highlighted item if((highlighted != null) && !highlighted.IsDisposed) renderer.PlotSector(highlighted, General.Colors.Highlight); - + /* // Render highlighted things if(highlighted != null) @@ -191,8 +200,15 @@ namespace CodeImp.DoomBuilder.BuilderModes // Done renderer.Finish(); - renderer.Present(); } + + // TEST: + if(renderer.StartOverlay(true)) + { + renderer.RenderRectangleFilled(new RectangleF(labelpos.x - 5, labelpos.y - 5, 10, 10), General.Colors.Indication, true); + renderer.Finish(); + } + renderer.Present(); } // Show highlight info @@ -337,6 +353,7 @@ namespace CodeImp.DoomBuilder.BuilderModes { if((highlighted != null) && !highlighted.IsDisposed) BuilderPlug.Me.RenderReverseAssociations(renderer, highlightasso); if(selecting) RenderMultiSelection(); + renderer.RenderRectangleFilled(new RectangleF(labelpos.x - 5, labelpos.y - 5, 10, 10), General.Colors.Indication, true); renderer.Finish(); } diff --git a/Source/Geometry/Polygon.cs b/Source/Geometry/Polygon.cs deleted file mode 100644 index f82a7210..00000000 --- a/Source/Geometry/Polygon.cs +++ /dev/null @@ -1,101 +0,0 @@ - -#region ================== Copyright (c) 2007 Pascal vd Heiden - -/* - * Copyright (c) 2007 Pascal vd Heiden, www.codeimp.com - * This program is released under GNU General Public License - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ - -#endregion - -#region ================== Namespaces - -using System; -using System.Collections; -using System.Collections.Generic; -using System.Globalization; -using System.Text; -using CodeImp.DoomBuilder.Geometry; -using CodeImp.DoomBuilder.Rendering; -using SlimDX.Direct3D9; -using System.Drawing; -using CodeImp.DoomBuilder.Map; - -#endregion - -namespace CodeImp.DoomBuilder.Geometry -{ - public class Polygon : List - { - #region ================== Variables - - #endregion - - #region ================== Properties - - #endregion - - #region ================== Constructors - - // Constructor - public Polygon() - { - // Initialize - } - - #endregion - - #region ================== Methods - - // Point inside the polygon? - // See: http://local.wasp.uwa.edu.au/~pbourke/geometry/insidepoly/ - public bool Intersect(Vector2D p) - { - float miny, maxy, maxx, xint; - Vector2D v1 = base[base.Count - 1]; - Vector2D v2; - int index = 0; - uint c = 0; - - // Go for all vertices - while(index < base.Count) - { - // Get next vertex - v2 = base[index]; - - // Determine min/max values - miny = Math.Min(v1.y, v2.y); - maxy = Math.Max(v1.y, v2.y); - maxx = Math.Max(v1.x, v2.x); - - // Check for intersection - if((p.y > miny) && (p.y <= maxy)) - { - if(p.x <= maxx) - { - if(v1.y != v2.y) - { - xint = (p.y - v1.y) * (v2.x - v1.x) / (v2.y - v1.y) + v1.x; - if((v1.x == v2.x) || (p.x <= xint)) c++; - } - } - } - - // Move to next - v1 = v2; - index++; - } - - // Inside this polygon? - return (c & 0x00000001UL) != 0; - } - - #endregion - } -} diff --git a/Source/Geometry/SectorTools.cs b/Source/Geometry/Tools.cs similarity index 90% rename from Source/Geometry/SectorTools.cs rename to Source/Geometry/Tools.cs index 78a054ea..d43a1b8f 100644 --- a/Source/Geometry/SectorTools.cs +++ b/Source/Geometry/Tools.cs @@ -33,10 +33,9 @@ using CodeImp.DoomBuilder.IO; namespace CodeImp.DoomBuilder.Geometry { /// - /// This makes a sector from all surrounding lines from a given coordinate. - /// Automatically finds the sidedef/sector properties from surrounding sectors/sidedefs. + /// Tools to work with geometry. /// - public static class SectorTools + public static class Tools { #region ================== Structures @@ -53,6 +52,46 @@ namespace CodeImp.DoomBuilder.Geometry #endregion + #region ================== Polygons and Triangles + + // Point inside the polygon? + // See: http://local.wasp.uwa.edu.au/~pbourke/geometry/insidepoly/ + public static bool PointInPolygon(ICollection polygon, Vector2D point) + { + Vector2D v1 = General.GetByIndex(polygon, polygon.Count - 1); + uint c = 0; + + // Go for all vertices + foreach(Vector2D v2 in polygon) + { + // Determine min/max values + float miny = Math.Min(v1.y, v2.y); + float maxy = Math.Max(v1.y, v2.y); + float maxx = Math.Max(v1.x, v2.x); + + // Check for intersection + if((point.y > miny) && (point.y <= maxy)) + { + if(point.x <= maxx) + { + if(v1.y != v2.y) + { + float xint = (point.y - v1.y) * (v2.x - v1.x) / (v2.y - v1.y) + v1.x; + if((v1.x == v2.x) || (point.x <= xint)) c++; + } + } + } + + // Move to next + v1 = v2; + } + + // Inside this polygon? + return (c & 0x00000001UL) != 0; + } + + #endregion + #region ================== Pathfinding /// @@ -588,47 +627,6 @@ namespace CodeImp.DoomBuilder.Geometry Vector2D foundpoint = new Vector2D(); float founddist = 0.0f; - // Calculate grid numbers - RectangleF bbox = s.CreateBBox(); - int nodesx = (int)(bbox.Width / resolution); - int nodesy = (int)(bbox.Height / resolution); - - // Make list of linedefs - List lines = new List(s.Sidedefs.Count); - foreach(Sidedef sd in s.Sidedefs) lines.Add(sd.Line); - - // Scan the polygon - for(int x = 0; x < nodesx; x++) - { - for(int y = 0; y < nodesy; y++) - { - // Calculate absolute point - Vector2D p = new Vector2D(bbox.X + (float)x * resolution, - bbox.Y + (float)y * resolution); - - // Point inside sector? - Linedef ld = MapSet.NearestLinedef(lines, p); - Sidedef sd = (ld.SideOfLine(p) < 0) ? ld.Front : ld.Back; - if((sd != null) && (sd.Sector == s)) - { - // Go for all linedefs to calculate the smallest distance - float mindist = int.MaxValue; - foreach(Linedef l in lines) - { - float dist = l.DistanceToSq(p, true); - if(dist < mindist) mindist = dist; - } - - // Better match? - if(mindist > founddist) - { - foundpoint = p; - founddist = mindist; - } - } - } - } - return foundpoint; }