public static LuaVertex NearestVertex(LuaVector2D pos) { Vertex v = MapSet.NearestVertex(General.Map.Map.Vertices, pos.vec); if (v == null) { return null; } return new LuaVertex(v); }
// Constructor to start dragging immediately protected void StartDrag(Vector2D dragstartmappos) { // Initialize this.dragstartmappos = dragstartmappos; Cursor.Current = Cursors.AppStarting; // We don't want to record this for undoing while we move the geometry around. // This will be set back to normal when we're done. General.Map.UndoRedo.IgnorePropChanges = true; // Make list of selected vertices selectedverts = General.Map.Map.GetMarkedVertices(true); // Make list of non-selected vertices // This will be used for snapping to nearest items unselectedverts = General.Map.Map.GetMarkedVertices(false); // Get the nearest vertex for snapping dragitem = MapSet.NearestVertex(selectedverts, dragstartmappos); // Lines to snap to snaptolines = General.Map.Map.LinedefsFromMarkedVertices(true, false, false); // Make old positions list // We will use this as reference to move the vertices, or to move them back on cancel oldpositions = new List <Vector2D>(selectedverts.Count); foreach (Vertex v in selectedverts) { oldpositions.Add(v.Position); } // Also keep old position of the dragged item dragitemposition = dragitem.Position; // Keep view information lastoffsetx = renderer.OffsetX; lastoffsety = renderer.OffsetY; lastscale = renderer.Scale; // Make list of unstable lines only // These will have their length displayed during the drag unstablelines = MapSet.UnstableLinedefsFromVertices(selectedverts); // Make text labels labels = new LineLengthLabel[unstablelines.Count]; int index = 0; foreach (Linedef l in unstablelines) { labels[index++] = new LineLengthLabel(l.Start.Position, l.End.Position); } Cursor.Current = Cursors.Default; }
/// <summary> /// This is called when the thing must be tested for line intersection. This should perform /// accurate hit detection and set u_ray to the position on the ray where this hits the geometry. /// </summary> public override bool PickAccurate(Vector3D from, Vector3D to, Vector3D dir, ref double u_ray) { u_ray = pickrayu; Sidedef sd = MapSet.NearestSidedef(sector.Sidedefs, pickintersect); Vertex v = MapSet.NearestVertex(new Vertex[] { sd.Line.Start, sd.Line.End }, pickintersect); if (v == vertex) { double side = sd.Line.SideOfLine(pickintersect); if ((side <= 0.0f && sd.IsFront) || (side > 0.0f && !sd.IsFront)) { return(true); } } return(false); }
// Constructor to start dragging immediately protected void StartDrag(Vector2D dragstartmappos) { // Initialize this.dragstartmappos = dragstartmappos; Cursor.Current = Cursors.AppStarting; // We don't want to record this for undoing while we move the geometry around. // This will be set back to normal when we're done. General.Map.UndoRedo.IgnorePropChanges = true; // Make list of selected vertices and things selectedverts = General.Map.Map.GetMarkedVertices(true); selectedthings = General.Map.Map.GetSelectedThings(true); //mxd thingstodrag = (BuilderPlug.Me.SyncronizeThingEdit ? selectedthings : new List <Thing>()); //mxd // Make list of non-selected vertices and things // Non-selected vertices will be used for snapping to nearest items unselectedverts = General.Map.Map.GetMarkedVertices(false); unselectedthings = new List <Thing>(); //mxd foreach (Thing t in General.Map.ThingsFilter.VisibleThings) { if (!t.Selected) { unselectedthings.Add(t); } } // Get the nearest vertex for snapping dragitem = MapSet.NearestVertex(selectedverts, dragstartmappos); //mxd. Get drag offset dragstartoffset = General.Map.Grid.SnappedToGrid(dragitem.Position) - dragitem.Position; // Lines to snap to snaptolines = General.Map.Map.LinedefsFromMarkedVertices(true, false, false); // Make old positions list // We will use this as reference to move the vertices, or to move them back on cancel oldpositions = new List <Vector2D>(selectedverts.Count); foreach (Vertex v in selectedverts) { oldpositions.Add(v.Position); } //mxd oldthingpositions = new List <Vector2D>(thingstodrag.Count); foreach (Thing t in thingstodrag) { oldthingpositions.Add(t.Position); } // Also keep old position of the dragged item dragitemposition = dragitem.Position; // Keep view information lastoffsetx = renderer.OffsetX; lastoffsety = renderer.OffsetY; lastscale = renderer.Scale; // Make list of unstable lines only // These will have their length displayed during the drag unstablelines = MapSet.UnstableLinedefsFromVertices(selectedverts); //mxd. Collect selected sectors if (General.Map.UDMF) { ICollection <Linedef> selectedLines = General.Map.Map.LinedefsFromMarkedVertices(false, true, false); List <Sector> affectedSectors = new List <Sector>(); foreach (Linedef l in selectedLines) { if (l.Front != null && l.Front.Sector != null && !affectedSectors.Contains(l.Front.Sector)) { affectedSectors.Add(l.Front.Sector); } if (l.Back != null && l.Back.Sector != null && !affectedSectors.Contains(l.Back.Sector)) { affectedSectors.Add(l.Back.Sector); } } selectedsectors = new List <Sector>(); foreach (Sector s in affectedSectors) { bool selected = true; foreach (Sidedef side in s.Sidedefs) { if (!selectedLines.Contains(side.Line)) { selected = false; break; } } if (selected) { selectedsectors.Add(s); } } } // Make text labels labels = new LineLengthLabel[unstablelines.Count]; int index = 0; foreach (Linedef l in unstablelines) { labels[index++] = new LineLengthLabel(l.Start.Position, l.End.Position); } Cursor.Current = Cursors.Default; }
// Constructor to start dragging immediately protected void StartDrag(Vector2D dragstartmappos) { // Initialize this.dragstartmappos = dragstartmappos; Cursor.Current = Cursors.AppStarting; // Make list of selected vertices selectedverts = General.Map.Map.GetMarkedVertices(true); // ano - protection in case of inconsistent selection state // (sectors selected with linedefs or verts selected) if (selectedverts.Count == 0) { ICollection <Sector> selectedsectors = General.Map.Map.GetSelectedSectors(true); foreach (Sector s in selectedsectors) { foreach (Sidedef side in s.Sidedefs) { side.Line.Selected = true; } } ICollection <Linedef> selectedlines = General.Map.Map.GetSelectedLinedefs(true); foreach (Linedef l in selectedlines) { l.Start.Selected = true; l.End.Selected = true; l.Start.Marked = true; l.End.Marked = true; } selectedverts = General.Map.Map.GetMarkedVertices(true); if (selectedverts.Count == 0) { // ano - failed to find any geometry worth dragging Cursor.Current = Cursors.Default; cancelled = true; General.Editing.ChangeMode(General.Editing.PreviousStableMode.Name); return; } } // We don't want to record this for undoing while we move the geometry around. // This will be set back to normal when we're done. General.Map.UndoRedo.IgnorePropChanges = true; // Make list of non-selected vertices // This will be used for snapping to nearest items unselectedverts = General.Map.Map.GetMarkedVertices(false); // Get the nearest vertex for snapping dragitem = MapSet.NearestVertex(selectedverts, dragstartmappos); // Lines to snap to snaptolines = General.Map.Map.LinedefsFromMarkedVertices(true, false, false); // Make old positions list // We will use this as reference to move the vertices, or to move them back on cancel oldpositions = new List <Vector2D>(selectedverts.Count); foreach (Vertex v in selectedverts) { oldpositions.Add(v.Position); } // Also keep old position of the dragged item dragitemposition = dragitem.Position; // Keep view information lastoffsetx = renderer.OffsetX; lastoffsety = renderer.OffsetY; lastscale = renderer.Scale; // Make list of unstable lines only // These will have their length displayed during the drag unstablelines = MapSet.UnstableLinedefsFromVertices(selectedverts); // Make text labels labels = new LineLengthLabel[unstablelines.Count]; int index = 0; foreach (Linedef l in unstablelines) { labels[index++] = new LineLengthLabel(l.Start.Position, l.End.Position); } Cursor.Current = Cursors.Default; }