@ work on (G)ZDoom Editing plugin

This commit is contained in:
codeimp 2010-09-04 11:19:37 +00:00
parent 5317ef1dc9
commit 939bceaa37
9 changed files with 84 additions and 34 deletions

View file

@ -766,7 +766,7 @@ namespace CodeImp.DoomBuilder
else else
{ {
// Note in the log that we cannot find this file // 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 + "\"");
} }
} }
} }

View file

@ -82,10 +82,13 @@ namespace CodeImp.DoomBuilder.Geometry
} }
/// <summary></summary> /// <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.normal = Vector3D.CrossProduct(p1 - p2, p3 - p2).GetNormal();
this.offset = -Vector3D.DotProduct(normal, p2); 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 #endregion
@ -95,13 +98,13 @@ namespace CodeImp.DoomBuilder.Geometry
/// <summary> /// <summary>
/// This tests for intersection using a position and direction /// This tests for intersection using a position and direction
/// </summary> /// </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); float w = Vector3D.DotProduct(normal, from - to);
if(a != 0.0f) if(w != 0.0f)
{ {
float b = Vector3D.DotProduct(normal, position); float v = Vector3D.DotProduct(normal, from);
u_ray = (offset - b) / a; u_ray = (v + offset) / w;
return true; return true;
} }
else else
@ -128,7 +131,23 @@ namespace CodeImp.DoomBuilder.Geometry
float d = Vector3D.DotProduct(p, normal) + offset; float d = Vector3D.DotProduct(p, normal) + offset;
return p - normal * d; 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> /// <summary>
/// This inverts the plane /// This inverts the plane
/// </summary> /// </summary>

View file

@ -52,6 +52,8 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
// in a multiselection. The Changed property on the BaseVisualSector is // in a multiselection. The Changed property on the BaseVisualSector is
// used to indicate a rebuild is needed. // used to indicate a rebuild is needed.
protected bool changed; protected bool changed;
protected SectorLevel level;
#endregion #endregion
@ -65,8 +67,9 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
#region ================== Constructor / Destructor #region ================== Constructor / Destructor
// Constructor // 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; this.mode = mode;
} }

View file

@ -144,15 +144,15 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
// Get sector data // Get sector data
data = mode.GetSectorData(this.Sector); data = mode.GetSectorData(this.Sector);
if(!data.Built) data.BuildLevels(); if(!data.Built) data.BuildLevels(mode);
// Create floor // Create floor
if(floor == null) floor = new VisualFloor(mode, this); if(floor == null) floor = new VisualFloor(mode, this, data.Floor);
floor.Setup(); floor.Setup();
base.AddGeometry(floor); base.AddGeometry(floor);
// Create ceiling // Create ceiling
if(ceiling == null) ceiling = new VisualCeiling(mode, this); if(ceiling == null) ceiling = new VisualCeiling(mode, this, data.Ceiling);
ceiling.Setup(); ceiling.Setup();
base.AddGeometry(ceiling); base.AddGeometry(ceiling);

View file

@ -69,7 +69,7 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
floor = new SectorLevel(s, SectorLevelType.Floor); floor = new SectorLevel(s, SectorLevelType.Floor);
ceiling = new SectorLevel(s, SectorLevelType.Ceiling); ceiling = new SectorLevel(s, SectorLevelType.Ceiling);
floor.plane = new Plane(new Vector3D(0, 0, 1), sector.FloorHeight); 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 // Determine colors
try try
@ -115,7 +115,7 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
// Begin // Begin
if(isbuilding) return; if(isbuilding) return;
isbuilding = true; isbuilding = true;
foreach(Linedef l in linedefs) foreach(Linedef l in linedefs)
{ {
// Plane Align (see http://zdoom.org/wiki/Plane_Align) // Plane Align (see http://zdoom.org/wiki/Plane_Align)
@ -138,35 +138,47 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
// Align floor with back of line // Align floor with back of line
if((l.Args[0] == 1) && (l.Front.Sector == sector) && (l.Back != null)) 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 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); Vector3D v3 = new Vector3D(foundv.Position.x, foundv.Position.y, sector.FloorHeight);
floor.plane = new Plane(v1, v2, v3); 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 // Align floor with front of line
else if((l.Args[0] == 2) && (l.Back.Sector == sector) && (l.Front != null)) 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 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); Vector3D v3 = new Vector3D(foundv.Position.x, foundv.Position.y, sector.FloorHeight);
floor.plane = new Plane(v1, v2, v3); 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 // Align ceiling with back of line
if((l.Args[1] == 1) && (l.Front.Sector == sector) && (l.Back != null)) 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 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); Vector3D v3 = new Vector3D(foundv.Position.x, foundv.Position.y, sector.CeilHeight);
ceiling.plane = new Plane(v1, v2, v3); 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 // Align ceiling with front of line
else if((l.Args[1] == 2) && (l.Back.Sector == sector) && (l.Front != null)) 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 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); Vector3D v3 = new Vector3D(foundv.Position.x, foundv.Position.y, sector.CeilHeight);
ceiling.plane = new Plane(v1, v2, v3); if(l.SideOfLine(v3) > 0.0f)
ceiling.plane = new Plane(v1, v2, v3, false);
else
ceiling.plane = new Plane(v2, v1, v3, false);
} }
} }
} }

View file

@ -16,7 +16,7 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
internal class SectorLevel : IComparable<SectorLevel> internal class SectorLevel : IComparable<SectorLevel>
{ {
// Center of sector to use for plane comparison // Center of sector to use for plane comparison
public Vector3D center; public Vector2D center;
// Type of level // Type of level
public SectorLevelType type; public SectorLevelType type;
@ -35,13 +35,13 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
public SectorLevel(Sector s, SectorLevelType type) public SectorLevel(Sector s, SectorLevelType type)
{ {
this.type = 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 // Comparer
public int CompareTo(SectorLevel other) 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) if(delta > 0.0f)
return 1; return 1;

View file

@ -57,7 +57,7 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
#region ================== Constructor / Setup #region ================== Constructor / Setup
// Constructor // 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 // We have no destructor
GC.SuppressFinalize(this); GC.SuppressFinalize(this);
@ -127,7 +127,7 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
// Vertex coordinates // Vertex coordinates
verts[i].x = s.Triangles.Vertices[i].x; verts[i].x = s.Triangles.Vertices[i].x;
verts[i].y = s.Triangles.Vertices[i].y; 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 // Texture coordinates
Vector2D pos = s.Triangles.Vertices[i]; Vector2D pos = s.Triangles.Vertices[i];

View file

@ -57,7 +57,7 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
#region ================== Constructor / Setup #region ================== Constructor / Setup
// Constructor // 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 // We have no destructor
GC.SuppressFinalize(this); GC.SuppressFinalize(this);
@ -126,7 +126,7 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
// Vertex coordinates // Vertex coordinates
verts[i].x = s.Triangles.Vertices[i].x; verts[i].x = s.Triangles.Vertices[i].x;
verts[i].y = s.Triangles.Vertices[i].y; 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 // Texture coordinates
Vector2D pos = s.Triangles.Vertices[i]; Vector2D pos = s.Triangles.Vertices[i];
@ -169,8 +169,24 @@ namespace CodeImp.DoomBuilder.GZDoomEditing
// This performs a fast test in object picking // This performs a fast test in object picking
public override bool PickFastReject(Vector3D from, Vector3D to, Vector3D dir) 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; float planez = (float)Sector.Sector.FloorHeight;
// Check if line crosses the z height // Check if line crosses the z height
if((from.z > planez) && (to.z < planez)) if((from.z > planez) && (to.z < planez))
{ {

Binary file not shown.