mirror of
https://git.do.srb2.org/STJr/UltimateZoneBuilder.git
synced 2025-01-18 14:31:50 +00:00
@ work on (G)ZDoom Editing plugin
This commit is contained in:
parent
5317ef1dc9
commit
939bceaa37
9 changed files with 84 additions and 34 deletions
|
@ -766,7 +766,7 @@ namespace CodeImp.DoomBuilder
|
|||
else
|
||||
{
|
||||
// Note in the log that we cannot find this file
|
||||
General.ErrorLogger.Add(ErrorType.Warning, "Cannot find the specified file \"" + curarg + "\"");
|
||||
General.WriteLogLine("Cannot find the specified file \"" + curarg + "\"");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,10 +82,13 @@ namespace CodeImp.DoomBuilder.Geometry
|
|||
}
|
||||
|
||||
/// <summary></summary>
|
||||
public Plane(Vector3D p1, Vector3D p2, Vector3D p3)
|
||||
public Plane(Vector3D p1, Vector3D p2, Vector3D p3, bool up)
|
||||
{
|
||||
this.normal = Vector3D.CrossProduct(p1 - p2, p3 - p2).GetNormal();
|
||||
this.offset = -Vector3D.DotProduct(normal, p2);
|
||||
|
||||
if((up && (this.normal.z < 0.0f)) || (!up && (this.normal.z > 0.0f)))
|
||||
this.normal.z = -this.normal.z;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
@ -95,13 +98,13 @@ namespace CodeImp.DoomBuilder.Geometry
|
|||
/// <summary>
|
||||
/// This tests for intersection using a position and direction
|
||||
/// </summary>
|
||||
public bool GetIntersection(Vector3D position, Vector3D direction, ref float u_ray)
|
||||
public bool GetIntersection(Vector3D from, Vector3D to, ref float u_ray)
|
||||
{
|
||||
float a = Vector3D.DotProduct(normal, direction);
|
||||
if(a != 0.0f)
|
||||
float w = Vector3D.DotProduct(normal, from - to);
|
||||
if(w != 0.0f)
|
||||
{
|
||||
float b = Vector3D.DotProduct(normal, position);
|
||||
u_ray = (offset - b) / a;
|
||||
float v = Vector3D.DotProduct(normal, from);
|
||||
u_ray = (v + offset) / w;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
@ -128,7 +131,23 @@ namespace CodeImp.DoomBuilder.Geometry
|
|||
float d = Vector3D.DotProduct(p, normal) + offset;
|
||||
return p - normal * d;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// This returns Z on the plane at X, Y
|
||||
/// </summary>
|
||||
public float GetZ(Vector2D pos)
|
||||
{
|
||||
return (d + a * pos.x + b * pos.y) / c;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This returns Z on the plane at X, Y
|
||||
/// </summary>
|
||||
public float GetZ(float x, float y)
|
||||
{
|
||||
return (d + a * x + b * y) / c;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This inverts the plane
|
||||
/// </summary>
|
||||
|
|
|
@ -52,6 +52,8 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
|
|||
// in a multiselection. The Changed property on the BaseVisualSector is
|
||||
// used to indicate a rebuild is needed.
|
||||
protected bool changed;
|
||||
|
||||
protected SectorLevel level;
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -65,8 +67,9 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
|
|||
#region ================== Constructor / Destructor
|
||||
|
||||
// Constructor
|
||||
public BaseVisualGeometrySector(BaseVisualMode mode, VisualSector vs) : base(vs)
|
||||
public BaseVisualGeometrySector(BaseVisualMode mode, VisualSector vs, SectorLevel level) : base(vs)
|
||||
{
|
||||
this.level = level;
|
||||
this.mode = mode;
|
||||
}
|
||||
|
||||
|
|
|
@ -144,15 +144,15 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
|
|||
|
||||
// Get sector data
|
||||
data = mode.GetSectorData(this.Sector);
|
||||
if(!data.Built) data.BuildLevels();
|
||||
if(!data.Built) data.BuildLevels(mode);
|
||||
|
||||
// Create floor
|
||||
if(floor == null) floor = new VisualFloor(mode, this);
|
||||
if(floor == null) floor = new VisualFloor(mode, this, data.Floor);
|
||||
floor.Setup();
|
||||
base.AddGeometry(floor);
|
||||
|
||||
// Create ceiling
|
||||
if(ceiling == null) ceiling = new VisualCeiling(mode, this);
|
||||
if(ceiling == null) ceiling = new VisualCeiling(mode, this, data.Ceiling);
|
||||
ceiling.Setup();
|
||||
base.AddGeometry(ceiling);
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
|
|||
floor = new SectorLevel(s, SectorLevelType.Floor);
|
||||
ceiling = new SectorLevel(s, SectorLevelType.Ceiling);
|
||||
floor.plane = new Plane(new Vector3D(0, 0, 1), sector.FloorHeight);
|
||||
ceiling.plane = new Plane(new Vector3D(0, 0, -1), sector.CeilHeight);
|
||||
ceiling.plane = new Plane(new Vector3D(0, 0, 1), sector.CeilHeight);
|
||||
|
||||
// Determine colors
|
||||
try
|
||||
|
@ -115,7 +115,7 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
|
|||
// Begin
|
||||
if(isbuilding) return;
|
||||
isbuilding = true;
|
||||
|
||||
|
||||
foreach(Linedef l in linedefs)
|
||||
{
|
||||
// Plane Align (see http://zdoom.org/wiki/Plane_Align)
|
||||
|
@ -138,35 +138,47 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
|
|||
// Align floor with back of line
|
||||
if((l.Args[0] == 1) && (l.Front.Sector == sector) && (l.Back != null))
|
||||
{
|
||||
Vector3D v1 = new Vector3D(foundv.Position.x, foundv.Position.y, sector.FloorHeight);
|
||||
Vector3D v1 = new Vector3D(l.End.Position.x, l.End.Position.y, l.Back.Sector.FloorHeight);
|
||||
Vector3D v2 = new Vector3D(l.Start.Position.x, l.Start.Position.y, l.Back.Sector.FloorHeight);
|
||||
Vector3D v3 = new Vector3D(l.End.Position.x, l.End.Position.y, l.Back.Sector.FloorHeight);
|
||||
floor.plane = new Plane(v1, v2, v3);
|
||||
Vector3D v3 = new Vector3D(foundv.Position.x, foundv.Position.y, sector.FloorHeight);
|
||||
if(l.SideOfLine(v3) < 0.0f)
|
||||
floor.plane = new Plane(v1, v2, v3, true);
|
||||
else
|
||||
floor.plane = new Plane(v2, v1, v3, true);
|
||||
}
|
||||
// Align floor with front of line
|
||||
else if((l.Args[0] == 2) && (l.Back.Sector == sector) && (l.Front != null))
|
||||
{
|
||||
Vector3D v1 = new Vector3D(foundv.Position.x, foundv.Position.y, sector.FloorHeight);
|
||||
Vector3D v1 = new Vector3D(l.End.Position.x, l.End.Position.y, l.Front.Sector.FloorHeight);
|
||||
Vector3D v2 = new Vector3D(l.Start.Position.x, l.Start.Position.y, l.Front.Sector.FloorHeight);
|
||||
Vector3D v3 = new Vector3D(l.End.Position.x, l.End.Position.y, l.Front.Sector.FloorHeight);
|
||||
floor.plane = new Plane(v1, v2, v3);
|
||||
Vector3D v3 = new Vector3D(foundv.Position.x, foundv.Position.y, sector.FloorHeight);
|
||||
if(l.SideOfLine(v3) < 0.0f)
|
||||
floor.plane = new Plane(v1, v2, v3, true);
|
||||
else
|
||||
floor.plane = new Plane(v2, v1, v3, true);
|
||||
}
|
||||
|
||||
// Align ceiling with back of line
|
||||
if((l.Args[1] == 1) && (l.Front.Sector == sector) && (l.Back != null))
|
||||
{
|
||||
Vector3D v1 = new Vector3D(foundv.Position.x, foundv.Position.y, sector.CeilHeight);
|
||||
Vector3D v1 = new Vector3D(l.End.Position.x, l.End.Position.y, l.Back.Sector.CeilHeight);
|
||||
Vector3D v2 = new Vector3D(l.Start.Position.x, l.Start.Position.y, l.Back.Sector.CeilHeight);
|
||||
Vector3D v3 = new Vector3D(l.End.Position.x, l.End.Position.y, l.Back.Sector.CeilHeight);
|
||||
ceiling.plane = new Plane(v1, v2, v3);
|
||||
Vector3D v3 = new Vector3D(foundv.Position.x, foundv.Position.y, sector.CeilHeight);
|
||||
if(l.SideOfLine(v3) > 0.0f)
|
||||
ceiling.plane = new Plane(v1, v2, v3, false);
|
||||
else
|
||||
ceiling.plane = new Plane(v2, v1, v3, false);
|
||||
}
|
||||
// Align ceiling with front of line
|
||||
else if((l.Args[1] == 2) && (l.Back.Sector == sector) && (l.Front != null))
|
||||
{
|
||||
Vector3D v1 = new Vector3D(foundv.Position.x, foundv.Position.y, sector.CeilHeight);
|
||||
Vector3D v1 = new Vector3D(l.End.Position.x, l.End.Position.y, l.Front.Sector.CeilHeight);
|
||||
Vector3D v2 = new Vector3D(l.Start.Position.x, l.Start.Position.y, l.Front.Sector.CeilHeight);
|
||||
Vector3D v3 = new Vector3D(l.End.Position.x, l.End.Position.y, l.Front.Sector.CeilHeight);
|
||||
ceiling.plane = new Plane(v1, v2, v3);
|
||||
Vector3D v3 = new Vector3D(foundv.Position.x, foundv.Position.y, sector.CeilHeight);
|
||||
if(l.SideOfLine(v3) > 0.0f)
|
||||
ceiling.plane = new Plane(v1, v2, v3, false);
|
||||
else
|
||||
ceiling.plane = new Plane(v2, v1, v3, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
|
|||
internal class SectorLevel : IComparable<SectorLevel>
|
||||
{
|
||||
// Center of sector to use for plane comparison
|
||||
public Vector3D center;
|
||||
public Vector2D center;
|
||||
|
||||
// Type of level
|
||||
public SectorLevelType type;
|
||||
|
@ -35,13 +35,13 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
|
|||
public SectorLevel(Sector s, SectorLevelType type)
|
||||
{
|
||||
this.type = type;
|
||||
this.center = new Vector3D(s.BBox.Left + s.BBox.Width / 2, s.BBox.Top + s.BBox.Height / 2, (s.FloorHeight + s.CeilHeight) / 2);
|
||||
this.center = new Vector2D(s.BBox.Left + s.BBox.Width / 2, s.BBox.Top + s.BBox.Height / 2);
|
||||
}
|
||||
|
||||
// Comparer
|
||||
public int CompareTo(SectorLevel other)
|
||||
{
|
||||
float delta = this.plane.ClosestOnPlane(center).z - other.plane.ClosestOnPlane(center).z;
|
||||
float delta = this.plane.GetZ(center) - other.plane.GetZ(center);
|
||||
|
||||
if(delta > 0.0f)
|
||||
return 1;
|
||||
|
|
|
@ -57,7 +57,7 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
|
|||
#region ================== Constructor / Setup
|
||||
|
||||
// Constructor
|
||||
public VisualCeiling(BaseVisualMode mode, VisualSector vs) : base(mode, vs)
|
||||
public VisualCeiling(BaseVisualMode mode, VisualSector vs, SectorLevel level) : base(mode, vs, level)
|
||||
{
|
||||
// We have no destructor
|
||||
GC.SuppressFinalize(this);
|
||||
|
@ -127,7 +127,7 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
|
|||
// Vertex coordinates
|
||||
verts[i].x = s.Triangles.Vertices[i].x;
|
||||
verts[i].y = s.Triangles.Vertices[i].y;
|
||||
verts[i].z = (float)s.CeilHeight;
|
||||
verts[i].z = Sector.Data.Ceiling.plane.GetZ(s.Triangles.Vertices[i]); //(float)s.CeilHeight;
|
||||
|
||||
// Texture coordinates
|
||||
Vector2D pos = s.Triangles.Vertices[i];
|
||||
|
|
|
@ -57,7 +57,7 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
|
|||
#region ================== Constructor / Setup
|
||||
|
||||
// Constructor
|
||||
public VisualFloor(BaseVisualMode mode, VisualSector vs) : base(mode, vs)
|
||||
public VisualFloor(BaseVisualMode mode, VisualSector vs, SectorLevel level) : base(mode, vs, level)
|
||||
{
|
||||
// We have no destructor
|
||||
GC.SuppressFinalize(this);
|
||||
|
@ -126,7 +126,7 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
|
|||
// Vertex coordinates
|
||||
verts[i].x = s.Triangles.Vertices[i].x;
|
||||
verts[i].y = s.Triangles.Vertices[i].y;
|
||||
verts[i].z = (float)s.FloorHeight;
|
||||
verts[i].z = Sector.Data.Floor.plane.GetZ(s.Triangles.Vertices[i]); //(float)s.FloorHeight;
|
||||
|
||||
// Texture coordinates
|
||||
Vector2D pos = s.Triangles.Vertices[i];
|
||||
|
@ -169,8 +169,24 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
|
|||
// This performs a fast test in object picking
|
||||
public override bool PickFastReject(Vector3D from, Vector3D to, Vector3D dir)
|
||||
{
|
||||
/*
|
||||
if(level.plane.GetIntersection(from, to, ref pickrayu))
|
||||
{
|
||||
if(pickrayu > 0.0f)
|
||||
{
|
||||
pickintersect = from + (to - from) * pickrayu;
|
||||
|
||||
// Intersection point within bbox?
|
||||
RectangleF bbox = Sector.Sector.BBox;
|
||||
return ((pickintersect.x >= bbox.Left) && (pickintersect.x <= bbox.Right) &&
|
||||
(pickintersect.y >= bbox.Top) && (pickintersect.y <= bbox.Bottom));
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
*/
|
||||
float planez = (float)Sector.Sector.FloorHeight;
|
||||
|
||||
|
||||
// Check if line crosses the z height
|
||||
if((from.z > planez) && (to.z < planez))
|
||||
{
|
||||
|
|
Binary file not shown.
Loading…
Reference in a new issue