From ff1ea95d86632c26f2cbc8177f7d0ba0a7690f99 Mon Sep 17 00:00:00 2001 From: biwa <6475593+biwa@users.noreply.github.com> Date: Sun, 16 Feb 2020 20:51:16 +0100 Subject: [PATCH] Drawing visual slope handles is (mostly) working now Also fixed some cases where slopes were applied incorrectly --- Source/Core/Rendering/VisualSlopeHandle.cs | 6 +- Source/Core/Resources/world3d.shader | 2 +- Source/Core/VisualModes/VisualSlope.cs | 76 ++++++++++++----- .../VisualModes/BaseVisualMode.cs | 6 ++ .../VisualModes/VisualSidedefSlope.cs | 84 ++++++++++++++----- 5 files changed, 126 insertions(+), 48 deletions(-) diff --git a/Source/Core/Rendering/VisualSlopeHandle.cs b/Source/Core/Rendering/VisualSlopeHandle.cs index 3f75375c..67bc6fe9 100644 --- a/Source/Core/Rendering/VisualSlopeHandle.cs +++ b/Source/Core/Rendering/VisualSlopeHandle.cs @@ -57,9 +57,9 @@ namespace CodeImp.DoomBuilder.Rendering public void ReloadResource() { WorldVertex v0 = new WorldVertex(0.0f, 0.0f, 0.5f); - WorldVertex v1 = new WorldVertex(0.0f, 1.0f, 0.5f); - WorldVertex v2 = new WorldVertex(8.0f, 1.0f, 0.5f); - WorldVertex v3 = new WorldVertex(8.0f, 0.0f, 0.5f); + WorldVertex v1 = new WorldVertex(1.0f, 0.0f, 0.5f); + WorldVertex v2 = new WorldVertex(1.0f, 8.0f, 0.5f); + WorldVertex v3 = new WorldVertex(0.0f, 8.0f, 0.5f); //WorldVertex v0 = new WorldVertex(0.0f, 0.0f, 0.5f); //WorldVertex v1 = new WorldVertex(32.0f, 0.0f, 0.5f); diff --git a/Source/Core/Resources/world3d.shader b/Source/Core/Resources/world3d.shader index f768c5a0..d4ee1edb 100755 --- a/Source/Core/Resources/world3d.shader +++ b/Source/Core/Resources/world3d.shader @@ -365,7 +365,7 @@ shader world3d_slope_handle extends world3d_vertex_color { vertex { - v2f.viewpos = view * world * vec4(in.Position.x, in.Position.y * slopeHandleLength, in.Position.z, 1.0); + v2f.viewpos = view * world * vec4(in.Position.x * slopeHandleLength, in.Position.y, in.Position.z, 1.0); gl_Position = projection * v2f.viewpos; v2f.Color = in.Color * vertexColor; v2f.UV = in.TextureCoordinate; diff --git a/Source/Core/VisualModes/VisualSlope.cs b/Source/Core/VisualModes/VisualSlope.cs index a052a37b..8297bffd 100644 --- a/Source/Core/VisualModes/VisualSlope.cs +++ b/Source/Core/VisualModes/VisualSlope.cs @@ -1,5 +1,6 @@ using System; using CodeImp.DoomBuilder.Geometry; +using CodeImp.DoomBuilder.Map; using CodeImp.DoomBuilder.Rendering; namespace CodeImp.DoomBuilder.VisualModes @@ -109,7 +110,16 @@ namespace CodeImp.DoomBuilder.VisualModes public virtual void Update() {} - public void SetPosition(Vector3D v1, Vector3D v2x, Vector3D v3x, Plane plane, float angle) + private Vector3D multi(Matrix m, Vector3D p) + { + return new Vector3D( + m.M11 * p.x + m.M12 * p.y + m.M13 * p.z + m.M14, + m.M21 * p.x + m.M22 * p.y + m.M23 * p.z + m.M24, + m.M31 * p.x + m.M32 * p.y + m.M33 * p.z + m.M34 + ); + } + + public void SetPosition(Line2D line, Plane plane) { //Matrix translate = Matrix.Translation(pos.x, pos.y, pos.z); //Matrix rotate = Matrix.RotationZ(angle); @@ -132,40 +142,64 @@ namespace CodeImp.DoomBuilder.VisualModes Vector3D v2 = new Vector3D(vec2[0], vec2[1], vec2[2]); */ - - Vector3D v2 = new Vector3D(-plane.Normal.z, plane.Normal.x, plane.Normal.y); - - v2 = Vector3D.CrossProduct(plane.Normal, v2x).GetNormal(); - - Vector3D v3 = Vector3D.CrossProduct(plane.Normal, v3x).GetNormal(); + Vector3D line_vector = Vector3D.CrossProduct(line.GetDelta().GetNormal(), plane.Normal); + Vector3D new_vector = Vector3D.CrossProduct(plane.Normal, line_vector); Matrix m = Matrix.Null; + m.M11 = new_vector.x; + m.M12 = new_vector.y; + m.M13 = new_vector.z; + + m.M21 = line_vector.x; + m.M22 = line_vector.y; + m.M23 = line_vector.z; + + m.M31 = plane.Normal.x; + m.M32 = plane.Normal.y; + m.M33 = plane.Normal.z; + + /* + m.M11 = new_vector.x; + m.M21 = new_vector.y; + m.M31 = new_vector.z; + + m.M12 = line_vector.x; + m.M22 = line_vector.y; + m.M32 = line_vector.z; + m.M13 = plane.Normal.x; m.M23 = plane.Normal.y; m.M33 = plane.Normal.z; - - m.M11 = v2.x; - m.M21 = v2.y; - m.M31 = v2.z; - - m.M12 = v3.x; - m.M22 = v3.y; - m.M32 = v3.z; + */ m.M44 = 1.0f; - v1.z = plane.GetZ(v1); - - - Matrix rotation = Matrix.RotationZ(angle); + Vector3D tp = new Vector3D(line.v1, plane.GetZ(line.v1)); //Matrix xrotate = Matrix.RotationX(90.0f); //Vector3 v = new Vector3(plane.Normal.x, plane.Normal.y, plane.Normal.z); // Matrix rotate = Matrix.RotationAxis(v, angle); //position = Matrix.Multiply(translate, planerotate); - position = Matrix.Multiply(m, Matrix.Multiply(rotation, Matrix.Translation(RenderDevice.V3(v1)))); - // position = m; + // position = Matrix.Multiply(m, Matrix.Multiply(rotation, Matrix.Translation(RenderDevice.V3(v1)))); + //position = m; + position = Matrix.Multiply(m, Matrix.Translation(RenderDevice.V3(tp))); + + /* + if (ld.Index == 0) + { + DebugConsole.WriteLine("Linedef: " + ld.ToString() + " | Plane normal: " + plane.Normal.ToString() + " | line_vector: " + line_vector.ToString() + " | new_vector: " + new_vector.ToString()); + + Vector3D mp = multi(position, new Vector3D(0.0f, 0.0f, 0.0f)); + DebugConsole.WriteLine(multi(position, mp).ToString()); + mp = multi(position, new Vector3D(16.0f, 0.0f, 0.0f)); + DebugConsole.WriteLine(multi(position, mp).ToString()); + mp = multi(position, new Vector3D(16.0f, 32.0f, 0.0f)); + DebugConsole.WriteLine(multi(position, mp).ToString()); + mp = multi(position, new Vector3D(0.0f, 32.0f, 0.0f)); + DebugConsole.WriteLine(multi(position, mp).ToString()); + } + */ } #endregion diff --git a/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs b/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs index e59a3765..8c59005e 100755 --- a/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs +++ b/Source/Plugins/BuilderModes/VisualModes/BaseVisualMode.cs @@ -18,6 +18,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics; using System.Linq; using System.Windows.Forms; using CodeImp.DoomBuilder.BuilderModes.Interface; @@ -474,6 +475,11 @@ namespace CodeImp.DoomBuilder.BuilderModes // Apply new target target = newtarget; + if(target.picked is VisualSlope) + { + Debug.WriteLine("Up: " + ((VisualSidedefSlope)target.picked).ToString()); + } + // Show target info if(updateinfo) ShowTargetInfo(); } diff --git a/Source/Plugins/BuilderModes/VisualModes/VisualSidedefSlope.cs b/Source/Plugins/BuilderModes/VisualModes/VisualSidedefSlope.cs index 53527e33..419a38bc 100644 --- a/Source/Plugins/BuilderModes/VisualModes/VisualSidedefSlope.cs +++ b/Source/Plugins/BuilderModes/VisualModes/VisualSidedefSlope.cs @@ -136,36 +136,39 @@ namespace CodeImp.DoomBuilder.VisualModes public void UpdatePosition() { - float angle; - Vector3D pos; - Vector3D v1, v2; + bool invertline = false; - if (sidedef.IsFront) + if (up) { - pos = sidedef.Line.End.Position; - pos.z = plane.GetZ(pos); - - v1 = sidedef.Line.Start.Position; - v2 = sidedef.Line.End.Position; - - angle = sidedef.Line.Angle + (float)Math.PI / 2.0f; - if (angle > (float)Math.PI * 2.0f) - angle -= 2.0f * (float)Math.PI ; + if (level.extrafloor && level.type == SectorLevelType.Ceiling) + { + if (sidedef.IsFront) + invertline = true; + } + else + { + if (!sidedef.IsFront) + invertline = true; + } } else { - pos = sidedef.Line.Start.Position; - pos.z = plane.GetZ(pos); - - v1 = sidedef.Line.End.Position; - v2 = sidedef.Line.Start.Position; - - angle = sidedef.Line.Angle - (float)Math.PI / 2.0f; - if (angle < 0.0f) - angle += 2.0f * (float)Math.PI; + if (level.extrafloor && level.type == SectorLevelType.Floor) + { + if (!sidedef.IsFront) + invertline = true; + } + else + { + if (sidedef.IsFront) + invertline = true; + } } - SetPosition(v1, sidedef.Line.Line.GetPerpendicular(), sidedef.Line.Line.GetDelta(), level.plane, /* (float)Math.PI * 1.5f + */ sidedef.Line.Angle); + if (invertline) + SetPosition(new Line2D(sidedef.Line.End.Position, sidedef.Line.Start.Position), level.plane); + else + SetPosition(sidedef.Line.Line, level.plane); } internal VisualSidedefSlope GetSmartPivotHandle(VisualSidedefSlope starthandle) @@ -301,6 +304,11 @@ namespace CodeImp.DoomBuilder.VisualModes return handle; } + public override string ToString() + { + return "Up: " + up.ToString() + " | level type: " + level.type.ToString(); + } + #endregion #region ================== Events @@ -358,9 +366,38 @@ namespace CodeImp.DoomBuilder.VisualModes foreach (SectorLevel l in levels) { + bool applytoceiling = false; Vector2D center = new Vector2D(l.sector.BBox.X + l.sector.BBox.Width / 2, l.sector.BBox.Y + l.sector.BBox.Height / 2); + if(l.extrafloor) + { + if (l.type == SectorLevelType.Floor) + applytoceiling = true; + } + else + { + if (l.type == SectorLevelType.Ceiling) + applytoceiling = true; + } + + if (applytoceiling) + { + Plane downplane = plane.GetInverted(); + l.sector.CeilSlope = downplane.Normal; + l.sector.CeilSlopeOffset = downplane.Offset; + l.sector.CeilHeight = (int)new Plane(l.sector.CeilSlope, l.sector.CeilSlopeOffset).GetZ(center); + } + else + { + l.sector.FloorSlope = plane.Normal; + l.sector.FloorSlopeOffset = plane.Offset; + l.sector.FloorHeight = (int)new Plane(l.sector.FloorSlope, l.sector.FloorSlopeOffset).GetZ(center); + } + + + + /* if (l.plane.Normal.z >= 0.0f && !l.extrafloor) { l.sector.FloorSlope = plane.Normal; @@ -374,6 +411,7 @@ namespace CodeImp.DoomBuilder.VisualModes l.sector.CeilSlopeOffset = downplane.Offset; l.sector.CeilHeight = (int)new Plane(l.sector.CeilSlope, l.sector.CeilSlopeOffset).GetZ(center); } + */ // Rebuild sector BaseVisualSector vs;