Visual Mode: Fixed a problem where using visual sloping a slope handle around itself resulted in invalid slopes

This commit is contained in:
biwa 2022-03-05 10:37:00 +01:00
parent 61ee99c273
commit 69fb4ba413
2 changed files with 37 additions and 14 deletions

View file

@ -348,6 +348,13 @@ namespace CodeImp.DoomBuilder.VisualModes
} }
} }
// Can't pivot around itself
if(pivothandle == this)
{
General.Interface.DisplayStatus(Windows.StatusType.Warning, "Slope handle to modify can't be the same as the pivot handle");
return;
}
// User didn't set a pivot handle, try to find the smart pivot handle // User didn't set a pivot handle, try to find the smart pivot handle
if(pivothandle == null) if(pivothandle == null)
pivothandle = GetSmartPivotHandle(); pivothandle = GetSmartPivotHandle();
@ -356,18 +363,22 @@ namespace CodeImp.DoomBuilder.VisualModes
if (pivothandle == null) if (pivothandle == null)
return; return;
mode.CreateUndo("Change slope");
Plane originalplane = level.plane;
Plane pivotplane = ((BaseVisualSlope)pivothandle).Level.plane;
// Build a new plane. p1 and p2 are the points of the slope handle that is modified, with the changed amound added; p3 is on the line of the pivot handle // Build a new plane. p1 and p2 are the points of the slope handle that is modified, with the changed amound added; p3 is on the line of the pivot handle
Vector3D p1 = new Vector3D(sidedef.Line.Start.Position, originalplane.GetZ(sidedef.Line.Start.Position) + amount); Vector3D p1 = new Vector3D(sidedef.Line.Start.Position, level.plane.GetZ(sidedef.Line.Start.Position) + amount);
Vector3D p2 = new Vector3D(sidedef.Line.End.Position, originalplane.GetZ(sidedef.Line.End.Position) + amount); Vector3D p2 = new Vector3D(sidedef.Line.End.Position, level.plane.GetZ(sidedef.Line.End.Position) + amount);
Vector3D p3 = pivothandle.GetPivotPoint(); Vector3D p3 = pivothandle.GetPivotPoint();
Plane plane = new Plane(p1, p2, p3, true); Plane plane = new Plane(p1, p2, p3, true);
// Completely vertical planes are not possible. This can for example happen when trying to pivot around the slope handle on the opposite side of a line
if (Math.Abs(plane.a) == 1.0 || Math.Abs(plane.b) == 1.0)
{
General.Interface.DisplayStatus(Windows.StatusType.Warning, "Resulting plane is completely vertical, which is impossible. Aborting");
return;
}
mode.CreateUndo("Change slope");
// Apply slope to surfaces // Apply slope to surfaces
foreach (SectorLevel l in levels) foreach (SectorLevel l in levels)
ApplySlope(l, plane, mode); ApplySlope(l, plane, mode);

View file

@ -314,6 +314,13 @@ namespace CodeImp.DoomBuilder.VisualModes
} }
} }
// Can't pivot around itself
if (pivothandle == this)
{
General.Interface.DisplayStatus(Windows.StatusType.Warning, "Slope handle to modify can't be the same as the pivot handle");
return;
}
// User didn't set a pivot handle, try to find the smart pivot handle // User didn't set a pivot handle, try to find the smart pivot handle
if (pivothandle == null) if (pivothandle == null)
pivothandle = GetSmartPivotHandle(); pivothandle = GetSmartPivotHandle();
@ -322,10 +329,6 @@ namespace CodeImp.DoomBuilder.VisualModes
if (pivothandle == null) if (pivothandle == null)
return; return;
mode.CreateUndo("Change slope");
Plane originalplane = level.plane;
Vector3D p1, p2, p3; Vector3D p1, p2, p3;
if (pivothandle is VisualVertexSlope) if (pivothandle is VisualVertexSlope)
@ -336,19 +339,28 @@ namespace CodeImp.DoomBuilder.VisualModes
p3 = pivothandle.GetPivotPoint(); p3 = pivothandle.GetPivotPoint();
Vector2D perp = new Line2D(vertex.Position, p3).GetPerpendicular(); Vector2D perp = new Line2D(vertex.Position, p3).GetPerpendicular();
p1 = new Vector3D(vertex.Position, originalplane.GetZ(vertex.Position) + amount); p1 = new Vector3D(vertex.Position, level.plane.GetZ(vertex.Position) + amount);
p2 = new Vector3D(vertex.Position + perp, originalplane.GetZ(vertex.Position + perp) + amount); p2 = new Vector3D(vertex.Position + perp, level.plane.GetZ(vertex.Position + perp) + amount);
} }
else // VisualSidedefSlope else // VisualSidedefSlope
{ {
List<Vector3D> pivotpoints = ((VisualSidedefSlope)pivothandle).GetPivotPoints(); List<Vector3D> pivotpoints = ((VisualSidedefSlope)pivothandle).GetPivotPoints();
p1 = new Vector3D(vertex.Position, originalplane.GetZ(vertex.Position) + amount); p1 = new Vector3D(vertex.Position, level.plane.GetZ(vertex.Position) + amount);
p2 = pivotpoints[0]; p2 = pivotpoints[0];
p3 = pivotpoints[1]; p3 = pivotpoints[1];
} }
Plane plane = new Plane(p1, p2, p3, true); Plane plane = new Plane(p1, p2, p3, true);
// Completely vertical planes are not possible
if (Math.Abs(plane.a) == 1.0 || Math.Abs(plane.b) == 1.0)
{
General.Interface.DisplayStatus(Windows.StatusType.Warning, "Resulting plane is completely vertical, which is impossible. Aborting");
return;
}
mode.CreateUndo("Change slope");
// Apply slope to surfaces // Apply slope to surfaces
foreach (SectorLevel l in levels) foreach (SectorLevel l in levels)
VisualSidedefSlope.ApplySlope(l, plane, mode); VisualSidedefSlope.ApplySlope(l, plane, mode);