3D floor slopes are now maintained when dragging their control sectors (#1057)

This commit is contained in:
9sphere 2024-06-16 11:47:38 +02:00 committed by GitHub
parent 6c9b3b5d91
commit 8f7104c23d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -432,7 +432,6 @@ namespace CodeImp.DoomBuilder.BuilderModes
//mxd. Update floor/ceiling texture offsets and slopes?
if (General.Map.UDMF)
{
Dictionary<Sector, List<Sector>> threedfloorcontrolsectors = new Dictionary<Sector, List<Sector>>();
Vector2D offset = dragitem.Position - dragitemposition;
// Sectors may've been created/removed when applying dragging...
@ -441,6 +440,9 @@ namespace CodeImp.DoomBuilder.BuilderModes
// Sectors that have to be updated. They contain the dragged sectors, but also 3D floor control sectors
HashSet<Sector> updatesectors = new HashSet<Sector>(draggedsectors);
// Keep track of control sectors in general, and control sectors relevant to other dragged sectors
HashSet<Sector> controlsectors = new HashSet<Sector>();
HashSet<Sector> addcontrolsectors = new HashSet<Sector>();
// Check if the dragged sectors are referenced as 3D floors, and add the control sectors to the list of
// sectors that need updating
@ -449,12 +451,18 @@ namespace CodeImp.DoomBuilder.BuilderModes
if (ld.Action != 160) // Action 160 defines a 3D floor
continue;
if (ld.Args[0] == 0) // First argument of the action is the sector tag. 0 is not a valid value
continue;
controlsectors.Add(ld.Front.Sector);
foreach (Sector s in draggedsectors)
{
if (ld.Args[0] == 0 || !s.Tags.Contains(ld.Args[0])) // First argument of the action is the sector tag. 0 is not a valid value
if (!s.Tags.Contains(ld.Args[0]))
continue;
updatesectors.Add(ld.Front.Sector);
addcontrolsectors.Add(ld.Front.Sector);
}
}
@ -462,6 +470,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
foreach (Sector s in updatesectors)
{
bool updateoffsets = (draggedsectors.Contains(s) && BuilderPlug.Me.LockSectorTextureOffsetsWhileDragging) || (!draggedsectors.Contains(s) && BuilderPlug.Me.Lock3DFloorSectorTextureOffsetsWhileDragging);
bool updateslopes = !((controlsectors.Contains(s) ^ addcontrolsectors.Contains(s)) && draggedsectors.Contains(s));
// Update texture offsets
if (updateoffsets)
@ -524,20 +533,23 @@ namespace CodeImp.DoomBuilder.BuilderModes
}
}
// Update floor slope?
if (s.FloorSlope.GetLengthSq() > 0 && !double.IsNaN(s.FloorSlopeOffset / s.FloorSlope.z))
if (updateslopes)
{
Plane floor = new Plane(s.FloorSlope, s.FloorSlopeOffset);
Vector2D center = new Vector2D(s.BBox.X + s.BBox.Width / 2, s.BBox.Y + s.BBox.Height / 2);
s.FloorSlopeOffset = -Vector3D.DotProduct(s.FloorSlope, new Vector3D(center + offset, floor.GetZ(center)));
}
// Update floor slope?
if (s.FloorSlope.GetLengthSq() > 0 && !double.IsNaN(s.FloorSlopeOffset / s.FloorSlope.z))
{
Plane floor = new Plane(s.FloorSlope, s.FloorSlopeOffset);
Vector2D center = new Vector2D(s.BBox.X + s.BBox.Width / 2, s.BBox.Y + s.BBox.Height / 2);
s.FloorSlopeOffset = -Vector3D.DotProduct(s.FloorSlope, new Vector3D(center + offset, floor.GetZ(center)));
}
// Update ceiling slope?
if (s.CeilSlope.GetLengthSq() > 0 && !double.IsNaN(s.CeilSlopeOffset / s.CeilSlope.z))
{
Plane ceiling = new Plane(s.CeilSlope, s.CeilSlopeOffset);
Vector2D center = new Vector2D(s.BBox.X + s.BBox.Width / 2, s.BBox.Y + s.BBox.Height / 2);
s.CeilSlopeOffset = -Vector3D.DotProduct(s.CeilSlope, new Vector3D(center + offset, ceiling.GetZ(center)));
// Update ceiling slope?
if (s.CeilSlope.GetLengthSq() > 0 && !double.IsNaN(s.CeilSlopeOffset / s.CeilSlope.z))
{
Plane ceiling = new Plane(s.CeilSlope, s.CeilSlopeOffset);
Vector2D center = new Vector2D(s.BBox.X + s.BBox.Width / 2, s.BBox.Y + s.BBox.Height / 2);
s.CeilSlopeOffset = -Vector3D.DotProduct(s.CeilSlope, new Vector3D(center + offset, ceiling.GetZ(center)));
}
}
}
}