little bit more on geometry drawing (still unfinished)

This commit is contained in:
codeimp 2008-05-06 21:31:20 +00:00
parent 3e5d429393
commit c43f0dc3a6
2 changed files with 43 additions and 6 deletions

View file

@ -175,7 +175,8 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
ld.Marked = true;
ld.Selected = true;
newlines.Add(ld);
ld.UpdateCache();
// Should we split this line to merge with intersecting lines?
if(points[i - 1].stitch || points[i].stitch)
{
@ -230,9 +231,40 @@ namespace CodeImp.DoomBuilder.BuilderModes.Editing
\***************************************************/
// Mark our new vertices that need to merge and merge them with themselves
// This completes the self intersections for which splits were made in step 1.
foreach(Vertex v in mergeverts) v.Marked = true;
MapSet.JoinVertices(mergeverts, mergeverts, true, MapSet.STITCH_DISTANCE);
// In step 3 we will make sectors on the front sides and join sectors on the
// back sides, but because the user could have drawn counterclockwise or just
// some weird polygon this could result in problems. The following code adjusts
// the direction of all new lines so that their front (right) side is facing
// the interior of the new drawn polygon.
map.Update(true, false);
foreach(Linedef ld in newlines)
{
// Find closest path starting with the front of this linedef
List<LinedefSide> pathlines = SectorTools.FindClosestPath(ld, true);
if(pathlines != null)
{
// Make polygon
LinedefTracePath tracepath = new LinedefTracePath(pathlines);
Polygon pathpoly = tracepath.MakePolygon();
// Check if the front of the line is outside the polygon
if(!pathpoly.Intersect(ld.GetSidePoint(true)))
{
// TODO: Maybe we also need to trace from the back side of the line
// here and see if that side lies in the interior? Just to make
// sure this flip will really help?
// We must flip this linedef to face the interior
ld.FlipVertices();
ld.FlipSidedefs();
}
}
}
// Perform standard geometry stitching between new and existing geometry
// The marked vertices indicate the new geometry
map.StitchGeometry();

View file

@ -62,6 +62,9 @@ namespace CodeImp.DoomBuilder.Geometry
{
List<LinedefSide> alllines = new List<LinedefSide>();
// TODO: Right now this will fail when it has found inner lines
// So fix it to make it find the outer lines first!
// Find the outer lines
Polygon p = FindOuterLines(line, front, alllines);
if(p != null)
@ -152,7 +155,7 @@ namespace CodeImp.DoomBuilder.Geometry
foundlinefront = (foundline.SideOfLine(foundv.Position + testpos) < 0.0f);
// Find inner path
List<LinedefSide> innerlines = FindInnerMostPath(foundline, foundlinefront);
List<LinedefSide> innerlines = FindClosestPath(foundline, foundlinefront);
if(innerlines != null)
{
// Make polygon
@ -179,7 +182,7 @@ namespace CodeImp.DoomBuilder.Geometry
private static Polygon FindOuterLines(Linedef line, bool front, List<LinedefSide> alllines)
{
// Find inner path
List<LinedefSide> pathlines = FindInnerMostPath(line, front);
List<LinedefSide> pathlines = FindClosestPath(line, front);
if(pathlines != null)
{
// Keep the lines
@ -201,9 +204,11 @@ namespace CodeImp.DoomBuilder.Geometry
return null;
}
// This finds the inner path from the beginning of a line to the end of the line.
// Returns null when no path could be found.
private static List<LinedefSide> FindInnerMostPath(Linedef start, bool front)
/// <summary>
/// This finds the closest path from the beginning of a line to the end of the line.
/// Returns null when no path could be found.
/// </summary>
public static List<LinedefSide> FindClosestPath(Linedef start, bool front)
{
List<LinedefSide> path = new List<LinedefSide>();
Dictionary<Linedef, int> tracecount = new Dictionary<Linedef, int>();