Drawing visual slope handles is (mostly) working now

Also fixed some cases where slopes were applied incorrectly
This commit is contained in:
biwa 2020-02-16 20:51:16 +01:00
parent d9cfc04e2e
commit ff1ea95d86
5 changed files with 126 additions and 48 deletions

View file

@ -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);

View file

@ -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;

View file

@ -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 = 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

View file

@ -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();
}

View file

@ -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
{
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 (!sidedef.IsFront)
invertline = true;
}
}
else
{
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;