Visual Mode: almost-correct slope skewing on FOF sides

This commit is contained in:
sphere 2021-10-24 17:21:10 +02:00
parent 8ef05744f9
commit 03c008a174

View file

@ -161,27 +161,76 @@ namespace CodeImp.DoomBuilder.BuilderModes
// the values are stored in a TexturePlane)
// NOTE: I use a small bias for the floor height, because if the difference in
// height is 0 then the TexturePlane doesn't work!
TexturePlane tp = new TexturePlane();
float floorbias = (sourcetopheight == sourcebottomheight) ? 1.0f : 0.0f;
Vector3D vlt, vlb, vrt, vrb;
Vector2D tlt, tlb, trt, trb;
bool skew = General.Map.SRB2 && sourceside.Line.IsFlagSet(General.Map.Config.UpperUnpeggedFlag);
tp.trb.x = tp.tlt.x + Sidedef.Line.Length;
tp.trb.y = tp.tlt.y + (sourcetopheight - sourcebottomheight) + floorbias;
float topheight = skew ? extrafloor.Ceiling.plane.GetZ(vl) : sourcetopheight;
float bottomheight = skew ? extrafloor.Floor.plane.GetZ(vl) : sourcebottomheight;
float floorbias = (topheight == bottomheight) ? 1.0f : 0.0f;
tlt.x = tlb.x = 0;
trt.x = trb.x = Sidedef.Line.Length;
tlt.y = trt.y = 0;
tlb.y = trb.y = (topheight - bottomheight) + floorbias;
float topheight2 = skew ? topheight : sourcetopheight;
float bottomheight2 = skew ? bottomheight : sourcebottomheight;
// Correct to account for slopes
if (General.Map.SRB2)
{
float slant;
float texturevpeg;
if (!skew)
{
slant = 0;
texturevpeg = 0;
}
else if (!IsLowerUnpegged())
{
slant = extrafloor.Floor.plane.GetZ(vr) - extrafloor.Floor.plane.GetZ(vl);
texturevpeg = (sourcetopheight - sourcebottomheight) % Math.Abs(tsz.y);
}
else
{
slant = extrafloor.Ceiling.plane.GetZ(vr) - extrafloor.Ceiling.plane.GetZ(vl);
texturevpeg = 0;
}
topheight2 = topheight + slant;
bottomheight2 = bottomheight + slant;
tlt.y = trt.y = texturevpeg;
tlb.y = trb.y = texturevpeg + (topheight - bottomheight) + floorbias;
}
// Apply texture offset
tp.tlt += tof;
tp.trb += tof;
tlt += tof;
tlb += tof;
trb += tof;
trt += tof;
// Transform pixel coordinates to texture coordinates
tp.tlt /= tsz;
tp.trb /= tsz;
tlt /= tsz;
tlb /= tsz;
trb /= tsz;
trt /= tsz;
// Left top and right bottom of the geometry that
tp.vlt = new Vector3D(vl.x, vl.y, sourcetopheight);
tp.vrb = new Vector3D(vr.x, vr.y, sourcebottomheight + floorbias);
// Geometry coordinates
vlt = new Vector3D(vl.x, vl.y, topheight + floorbias);
vlb = new Vector3D(vl.x, vl.y, bottomheight + floorbias);
vrb = new Vector3D(vr.x, vr.y, bottomheight2);
vrt = new Vector3D(vr.x, vr.y, topheight2 + floorbias);
// Make the right-top coordinates
tp.trt = new Vector2D(tp.trb.x, tp.tlt.y);
tp.vrt = new Vector3D(tp.vrb.x, tp.vrb.y, tp.vlt.z);
TexturePlane tp = new TexturePlane();
tp.tlt = IsLowerUnpegged() ? tlb : tlt;
tp.trb = trb;
tp.trt = trt;
tp.vlt = IsLowerUnpegged() ? vlb : vlt;
tp.vrb = vrb;
tp.vrt = vrt;
//mxd. Get ceiling and floor heights. Use our and neighbour sector's data
SectorData sdo = mode.GetSectorData(Sidedef.Other.Sector);