Changed, Thing Edit Form: floor slopes are now taken into account when changing thing's absolute Z position (currently, only slopes, created using sector planes, vertex height offsets and "Plane_Align" (181) action are supported).

Changed, Thing Info panel: floor slopes are now taken into account when showing thing's Z position (same plane type limitations as above).
Changed, Thing Info panel: thing position is now shown as "X, Y, Z (abs. Z)".
This commit is contained in:
MaxED 2015-04-15 12:49:28 +00:00
parent 9c959d21d1
commit 84b2fee819
6 changed files with 211 additions and 59 deletions

View file

@ -72,7 +72,7 @@ namespace CodeImp.DoomBuilder.Controls
// label5
//
label5.AutoSize = true;
label5.Location = new System.Drawing.Point(165, 64);
label5.Location = new System.Drawing.Point(165, 79);
label5.Name = "label5";
label5.Size = new System.Drawing.Size(37, 13);
label5.TabIndex = 8;
@ -150,7 +150,7 @@ namespace CodeImp.DoomBuilder.Controls
//
this.anglecontrol.Angle = 0;
this.anglecontrol.AngleOffset = 0;
this.anglecontrol.Location = new System.Drawing.Point(235, 58);
this.anglecontrol.Location = new System.Drawing.Point(235, 73);
this.anglecontrol.Name = "anglecontrol";
this.anglecontrol.Size = new System.Drawing.Size(24, 24);
this.anglecontrol.TabIndex = 38;
@ -276,7 +276,7 @@ namespace CodeImp.DoomBuilder.Controls
// angle
//
this.angle.AutoSize = true;
this.angle.Location = new System.Drawing.Point(206, 64);
this.angle.Location = new System.Drawing.Point(206, 79);
this.angle.Name = "angle";
this.angle.Size = new System.Drawing.Size(25, 13);
this.angle.TabIndex = 11;
@ -353,6 +353,7 @@ namespace CodeImp.DoomBuilder.Controls
//
this.spritetex.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.Default;
this.spritetex.Dock = System.Windows.Forms.DockStyle.Fill;
this.spritetex.Highlighted = false;
this.spritetex.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
this.spritetex.Location = new System.Drawing.Point(0, 0);
this.spritetex.Name = "spritetex";

View file

@ -52,7 +52,6 @@ namespace CodeImp.DoomBuilder.Controls
LinedefActionInfo act = null;
string actioninfo;
string zinfo;
float zvalue;
// Show/hide stuff depending on format
bool hasArgs = General.Map.FormatInterface.HasActionArgs;
@ -92,30 +91,18 @@ namespace CodeImp.DoomBuilder.Controls
// Determine z info to show
t.DetermineSector();
if(ti.AbsoluteZ)
if(ti.AbsoluteZ || t.Sector == null)
{
zvalue = t.Position.z;
zinfo = t.Position.z.ToString(CultureInfo.InvariantCulture) + " (abs.)"; //mxd
}
else
{
if(t.Sector != null)
{
// Hangs from ceiling?
if(ti.Hangs)
{
zvalue = t.Sector.CeilHeight - t.Position.z - ti.Height; //mxd
}
else
{
zvalue = t.Sector.FloorHeight + t.Position.z;
}
}
// Hangs from ceiling?
if(ti.Hangs)
zinfo = (t.Position.z - ti.Height) + " (" + ((float)Math.Round(Sector.GetCeilingPlane(t.Sector).GetZ(t.Position) - t.Position.z - ti.Height, General.Map.FormatInterface.VertexDecimals)).ToString(CultureInfo.InvariantCulture) + ")"; //mxd
else
{
zvalue = t.Position.z;
}
zinfo = t.Position.z + " (" + ((float)Math.Round(Sector.GetFloorPlane(t.Sector).GetZ(t.Position) + t.Position.z, General.Map.FormatInterface.VertexDecimals)).ToString(CultureInfo.InvariantCulture) + ")"; //mxd
}
zinfo = zvalue.ToString(CultureInfo.InvariantCulture); //mxd
// Thing info
infopanel.Text = " Thing " + t.Index + " ";

View file

@ -596,6 +596,166 @@ namespace CodeImp.DoomBuilder.Map
General.Map.IsChanged = true;
}
//mxd
public static Geometry.Plane GetFloorPlane(Sector s)
{
if(General.Map.UDMF)
{
// UDMF Sector slope?
if(s.FloorSlope.GetLengthSq() > 0 && !float.IsNaN(s.FloorSlopeOffset / s.FloorSlope.z))
return new Geometry.Plane(s.FloorSlope, s.FloorSlopeOffset);
if(s.sidedefs.Count == 3)
{
Geometry.Plane floor = new Geometry.Plane(new Vector3D(0, 0, 1), -s.FloorHeight);
Vector3D[] verts = new Vector3D[3];
bool sloped = false;
int index = 0;
// Check vertices
foreach(Sidedef sd in s.Sidedefs)
{
Vertex v = sd.IsFront ? sd.Line.End : sd.Line.Start;
//create "normal" vertices
verts[index] = new Vector3D(v.Position);
// Check floor
if(!float.IsNaN(v.ZFloor))
{
//vertex offset is absolute
verts[index].z = v.ZFloor;
sloped = true;
}
else
{
verts[index].z = floor.GetZ(v.Position);
}
index++;
}
// Have slope?
return (sloped ? new Geometry.Plane(verts[0], verts[1], verts[2], true) : floor);
}
}
// Have line slope?
foreach (Sidedef side in s.sidedefs)
{
// Carbon copy of EffectLineSlope class here...
if(side.Line.Action == 181 && ((side.Line.Args[0] == 1 && side == side.Line.Front) || side.Line.Args[0] == 2) && side.Other != null)
{
Linedef l = side.Line;
// Find the vertex furthest from the line
Vertex foundv = null;
float founddist = -1.0f;
foreach(Sidedef sd in s.Sidedefs)
{
Vertex v = sd.IsFront ? sd.Line.Start : sd.Line.End;
float d = l.DistanceToSq(v.Position, false);
if(d > founddist)
{
foundv = v;
founddist = d;
}
}
Vector3D v1 = new Vector3D(l.Start.Position.x, l.Start.Position.y, side.Other.Sector.FloorHeight);
Vector3D v2 = new Vector3D(l.End.Position.x, l.End.Position.y, side.Other.Sector.FloorHeight);
Vector3D v3 = new Vector3D(foundv.Position.x, foundv.Position.y, s.FloorHeight);
return (l.SideOfLine(v3) < 0.0f ? new Geometry.Plane(v1, v2, v3, true) : new Geometry.Plane(v2, v1, v3, true));
}
}
//TODO: other types of slopes...
// Normal (flat) floor plane
return new Geometry.Plane(new Vector3D(0, 0, 1), -s.FloorHeight);
}
//mxd
public static Geometry.Plane GetCeilingPlane(Sector s)
{
if(General.Map.UDMF)
{
// UDMF Sector slope?
if(s.CeilSlope.GetLengthSq() > 0 && !float.IsNaN(s.CeilSlopeOffset / s.CeilSlope.z))
return new Geometry.Plane(s.CeilSlope, s.CeilSlopeOffset);
if(s.sidedefs.Count == 3)
{
Geometry.Plane ceiling = new Geometry.Plane(new Vector3D(0, 0, -1), s.CeilHeight);
Vector3D[] verts = new Vector3D[3];
bool sloped = false;
int index = 0;
// Check vertices
foreach(Sidedef sd in s.Sidedefs)
{
Vertex v = sd.IsFront ? sd.Line.End : sd.Line.Start;
//create "normal" vertices
verts[index] = new Vector3D(v.Position);
// Check floor
if(!float.IsNaN(v.ZCeiling))
{
//vertex offset is absolute
verts[index].z = v.ZCeiling;
sloped = true;
}
else
{
verts[index].z = ceiling.GetZ(v.Position);
}
index++;
}
// Have slope?
return (sloped ? new Geometry.Plane(verts[0], verts[2], verts[1], false) : ceiling);
}
}
// Have line slope?
foreach(Sidedef side in s.sidedefs)
{
// Carbon copy of EffectLineSlope class here...
if(side.Line.Action == 181 && ((side.Line.Args[1] == 1 && side == side.Line.Front) || side.Line.Args[1] == 2) && side.Other != null)
{
Linedef l = side.Line;
// Find the vertex furthest from the line
Vertex foundv = null;
float founddist = -1.0f;
foreach(Sidedef sd in s.Sidedefs)
{
Vertex v = sd.IsFront ? sd.Line.Start : sd.Line.End;
float d = l.DistanceToSq(v.Position, false);
if(d > founddist)
{
foundv = v;
founddist = d;
}
}
Vector3D v1 = new Vector3D(l.Start.Position.x, l.Start.Position.y, side.Other.Sector.CeilHeight);
Vector3D v2 = new Vector3D(l.End.Position.x, l.End.Position.y, side.Other.Sector.CeilHeight);
Vector3D v3 = new Vector3D(foundv.Position.x, foundv.Position.y, s.CeilHeight);
return (l.SideOfLine(v3) > 0.0f ? new Geometry.Plane(v1, v2, v3, false) : new Geometry.Plane(v2, v1, v3, false));
}
}
//TODO: other types of slopes...
// Normal (flat) ceiling plane
return new Geometry.Plane(new Vector3D(0, 0, -1), s.CeilHeight);
}
// String representation
public override string ToString()
{

View file

@ -50,7 +50,7 @@ namespace CodeImp.DoomBuilder.Windows
private bool preventchanges;
private bool preventmapchange; //mxd
private bool undocreated; //mxd
private static bool useAbsoluteHeight; //mxd
private static bool useabsoluteheight; //mxd
private List<ThingProperties> thingprops; //mxd
//mxd. Window setup stuff
@ -178,15 +178,15 @@ namespace CodeImp.DoomBuilder.Windows
// Coordination
angle.Text = ft.AngleDoom.ToString();
zlabel.Text = useAbsoluteHeight ? "Z:" : "Height:"; //mxd
cbAbsoluteHeight.Checked = useAbsoluteHeight; //mxd
zlabel.Text = useabsoluteheight ? "Z:" : "Height:"; //mxd
cbAbsoluteHeight.Checked = useabsoluteheight; //mxd
//mxd
ft.DetermineSector();
int floorheight = (ft.Sector != null ? ft.Sector.FloorHeight :0);
float floorheight = (ft.Sector != null ? Sector.GetFloorPlane(ft.Sector).GetZ(ft.Position) : 0);
posX.Text = ((int)ft.Position.x).ToString();
posY.Text = ((int)ft.Position.y).ToString();
posZ.Text = useAbsoluteHeight ? ((int)ft.Position.z + floorheight).ToString() : ((int)ft.Position.z).ToString();
posZ.Text = (useabsoluteheight ? ((int)Math.Round(ft.Position.z + floorheight)).ToString() : ((int)ft.Position.z).ToString());
posX.ButtonStep = General.Map.Grid.GridSize;
posY.ButtonStep = General.Map.Grid.GridSize;
posZ.ButtonStep = General.Map.Grid.GridSize;
@ -239,9 +239,10 @@ namespace CodeImp.DoomBuilder.Windows
//mxd. Position
if(((int)t.Position.x).ToString() != posX.Text) posX.Text = "";
if(((int)t.Position.y).ToString() != posY.Text) posY.Text = "";
if (useAbsoluteHeight && t.Sector != null)
if (useabsoluteheight && t.Sector != null)
{
if(((int)t.Position.z + t.Sector.FloorHeight).ToString() != posZ.Text) posZ.Text = "";
if(((int)Math.Round(Sector.GetFloorPlane(t.Sector).GetZ(t.Position) + t.Position.z)).ToString() != posZ.Text)
posZ.Text = "";
}
else if(((int)t.Position.z).ToString() != posZ.Text)
{
@ -532,24 +533,25 @@ namespace CodeImp.DoomBuilder.Windows
private void cbAbsoluteHeight_CheckedChanged(object sender, EventArgs e)
{
if(preventchanges) return;
MakeUndo(); //mxd
MakeUndo();
useAbsoluteHeight = cbAbsoluteHeight.Checked;
zlabel.Text = (useAbsoluteHeight ? "Z:" : "Height:");
useabsoluteheight = cbAbsoluteHeight.Checked;
zlabel.Text = (useabsoluteheight ? "Z:" : "Height:");
preventchanges = true;
//update label text
Thing ft = General.GetByIndex(things, 0);
float z = ft.Position.z;
if(useAbsoluteHeight && ft.Sector != null) z += ft.Sector.FloorHeight;
posZ.Text = z.ToString();
if(useabsoluteheight && ft.Sector != null) z += Sector.GetFloorPlane(ft.Sector).GetZ(ft.Position);
posZ.Text = ((float)Math.Round(z, General.Map.FormatInterface.VertexDecimals)).ToString();
foreach(Thing t in things)
{
z = t.Position.z;
if(useAbsoluteHeight && t.Sector != null) z += t.Sector.FloorHeight;
if (posZ.Text != z.ToString())
if(useabsoluteheight && t.Sector != null) z += Sector.GetFloorPlane(t.Sector).GetZ(t.Position);
string ztext = ((float)Math.Round(z, General.Map.FormatInterface.VertexDecimals)).ToString();
if(posZ.Text != ztext)
{
posZ.Text = "";
break;
@ -629,8 +631,8 @@ namespace CodeImp.DoomBuilder.Windows
foreach(Thing t in things)
{
float z = posZ.GetResultFloat(thingprops[i++].Z);
if(useAbsoluteHeight && !posZ.CheckIsRelative() && t.Sector != null)
z -= t.Sector.FloorHeight;
if(useabsoluteheight && !posZ.CheckIsRelative() && t.Sector != null)
z -= (float)Math.Round(Sector.GetFloorPlane(t.Sector).GetZ(t.Position.x, t.Position.y), General.Map.FormatInterface.VertexDecimals);
t.Move(new Vector3D(t.Position.x, t.Position.y, z));
}
}

View file

@ -50,7 +50,7 @@ namespace CodeImp.DoomBuilder.Windows
private bool preventchanges;
private bool preventmapchange; //mxd
private bool undocreated; //mxd
private static bool useAbsoluteHeight;
private static bool useabsoluteheight; //mxd
private string arg0str;
private bool haveArg0Str;
private List<ThingProperties> thingprops; //mxd
@ -187,14 +187,14 @@ namespace CodeImp.DoomBuilder.Windows
// Coordination
angle.Text = ft.AngleDoom.ToString();
cbAbsoluteHeight.Checked = useAbsoluteHeight; //mxd
cbAbsoluteHeight.Checked = useabsoluteheight; //mxd
//mxd
ft.DetermineSector();
int floorheight = (ft.Sector != null ? ft.Sector.FloorHeight : 0);
float floorheight = (ft.Sector != null ? Sector.GetFloorPlane(ft.Sector).GetZ(ft.Position) : 0);
posX.Text = (ft.Position.x).ToString();
posY.Text = (ft.Position.y).ToString();
posZ.Text = useAbsoluteHeight ? (ft.Position.z + floorheight).ToString() : (ft.Position.z).ToString();
posZ.Text = (useabsoluteheight ? ((float)Math.Round(ft.Position.z + floorheight, General.Map.FormatInterface.VertexDecimals)).ToString() : (ft.Position.z).ToString());
posX.ButtonStep = General.Map.Grid.GridSize;
posY.ButtonStep = General.Map.Grid.GridSize;
posZ.ButtonStep = General.Map.Grid.GridSize;
@ -257,9 +257,10 @@ namespace CodeImp.DoomBuilder.Windows
//mxd. Position
if((t.Position.x).ToString() != posX.Text) posX.Text = "";
if((t.Position.y).ToString() != posY.Text) posY.Text = "";
if(useAbsoluteHeight && t.Sector != null)
if(useabsoluteheight && t.Sector != null)
{
if((t.Position.z + t.Sector.FloorHeight).ToString() != posZ.Text) posZ.Text = "";
if(((float)Math.Round(Sector.GetFloorPlane(t.Sector).GetZ(t.Position) + t.Position.z, General.Map.FormatInterface.VertexDecimals)).ToString() != posZ.Text)
posZ.Text = "";
}
else if((t.Position.z).ToString() != posZ.Text)
{
@ -695,23 +696,24 @@ namespace CodeImp.DoomBuilder.Windows
private void cbAbsoluteHeight_CheckedChanged(object sender, EventArgs e)
{
if(preventchanges) return;
MakeUndo(); //mxd
MakeUndo();
useAbsoluteHeight = cbAbsoluteHeight.Checked;
useabsoluteheight = cbAbsoluteHeight.Checked;
preventchanges = true;
//update label text
Thing ft = General.GetByIndex(things, 0);
float z = ft.Position.z;
if(useAbsoluteHeight && ft.Sector != null) z += ft.Sector.FloorHeight;
posZ.Text = z.ToString();
if(useabsoluteheight && ft.Sector != null) z += Sector.GetFloorPlane(ft.Sector).GetZ(ft.Position);
posZ.Text = ((float)Math.Round(z, General.Map.FormatInterface.VertexDecimals)).ToString();
foreach(Thing t in things)
{
z = t.Position.z;
if(useAbsoluteHeight && t.Sector != null) z += t.Sector.FloorHeight;
if(posZ.Text != z.ToString())
if(useabsoluteheight && t.Sector != null) z += Sector.GetFloorPlane(t.Sector).GetZ(t.Position);
string ztext = ((float)Math.Round(z, General.Map.FormatInterface.VertexDecimals)).ToString();
if(posZ.Text != ztext)
{
posZ.Text = "";
break;
@ -791,8 +793,8 @@ namespace CodeImp.DoomBuilder.Windows
foreach(Thing t in things)
{
float z = posZ.GetResultFloat(thingprops[i++].Z);
if(useAbsoluteHeight && !posZ.CheckIsRelative() && t.Sector != null)
z -= t.Sector.FloorHeight;
if(useabsoluteheight && !posZ.CheckIsRelative() && t.Sector != null)
z -= (float)Math.Round(Sector.GetFloorPlane(t.Sector).GetZ(t.Position.x, t.Position.y), General.Map.FormatInterface.VertexDecimals);
t.Move(new Vector3D(t.Position.x, t.Position.y, z));
}
}

View file

@ -10,12 +10,12 @@ namespace CodeImp.DoomBuilder.BuilderModes
internal class EffectLineSlope : SectorEffect
{
// Linedef that is used to create this effect
private Linedef linedef;
private readonly Linedef l;
// Constructor
public EffectLineSlope(SectorData data, Linedef sourcelinedef) : base(data)
{
linedef = sourcelinedef;
l = sourcelinedef;
// New effect added: This sector needs an update!
if(data.Mode.VisualSectorExists(data.Sector))
@ -28,7 +28,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
// This makes sure we are updated with the source linedef information
public override void Update()
{
Linedef l = linedef;
if(l.Front == null || l.Back == null) return; //mxd
// Find the vertex furthest from the line
Vertex foundv = null;
@ -45,7 +45,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
}
// Align floor with back of line
if((l.Args[0] == 1) && (l.Front.Sector == data.Sector) && (l.Back != null))
if((l.Args[0] == 1) && (l.Front.Sector == data.Sector))
{
Vector3D v1 = new Vector3D(l.Start.Position.x, l.Start.Position.y, l.Back.Sector.FloorHeight);
Vector3D v2 = new Vector3D(l.End.Position.x, l.End.Position.y, l.Back.Sector.FloorHeight);
@ -58,7 +58,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
sd.AddUpdateSector(data.Sector, true);
}
// Align floor with front of line
else if((l.Args[0] == 2) && (l.Back.Sector == data.Sector) && (l.Front != null))
else if((l.Args[0] == 2) && (l.Back.Sector == data.Sector))
{
Vector3D v1 = new Vector3D(l.Start.Position.x, l.Start.Position.y, l.Front.Sector.FloorHeight);
Vector3D v2 = new Vector3D(l.End.Position.x, l.End.Position.y, l.Front.Sector.FloorHeight);
@ -72,7 +72,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
}
// Align ceiling with back of line
if((l.Args[1] == 1) && (l.Front.Sector == data.Sector) && (l.Back != null))
if((l.Args[1] == 1) && (l.Front.Sector == data.Sector))
{
Vector3D v1 = new Vector3D(l.Start.Position.x, l.Start.Position.y, l.Back.Sector.CeilHeight);
Vector3D v2 = new Vector3D(l.End.Position.x, l.End.Position.y, l.Back.Sector.CeilHeight);
@ -85,7 +85,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
sd.AddUpdateSector(data.Sector, true);
}
// Align ceiling with front of line
else if((l.Args[1] == 2) && (l.Back.Sector == data.Sector) && (l.Front != null))
else if((l.Args[1] == 2) && (l.Back.Sector == data.Sector))
{
Vector3D v1 = new Vector3D(l.Start.Position.x, l.Start.Position.y, l.Front.Sector.CeilHeight);
Vector3D v2 = new Vector3D(l.End.Position.x, l.End.Position.y, l.Front.Sector.CeilHeight);