- flip backwards oriented wall sprites before submitting them to the render list.

Backwards orientation will break the translucent object sorter so this needs to be sorted out beforehand.
This commit is contained in:
Christoph Oelckers 2021-04-20 00:28:52 +02:00
parent d34070b8ae
commit d078b511b8
2 changed files with 17 additions and 1 deletions

View file

@ -91,6 +91,12 @@ inline double PointOnLineSide(const DVector2 &pos, const walltype *line)
return (pos.X - WallStartX(line)) * WallDelta(line).Y - (pos.Y - WallStartY(line)) * WallDelta(line).X;
}
template<class T>
inline double PointOnLineSide(const TVector2<T>& pos, const TVector2<T>& linestart, const TVector2<T>& lineend)
{
return (pos.X - linestart.X) * (lineend.Y - linestart.Y) - (pos.Y - linestart.Y) * (lineend.X - linestart.X);
}
inline int sectorofwall(int wallNum)
{
if ((unsigned)wallNum < (unsigned)numwalls) return wall[wallNum].sector;

View file

@ -1089,7 +1089,6 @@ void HWWall::ProcessWallSprite(HWDrawInfo* di, spritetype* spr, sectortype* sect
zbottom[0] = zbottom[1] = (sprz) * (1 / -256.);
ztop[0] = ztop[1] = (sprz - ((height * spr->yrepeat) << 2)) * (1 / -256.);
// Clip sprites to ceilings/floors
float origz = ztop[0];
float polyh = (zbottom[0] - origz);
@ -1113,5 +1112,16 @@ void HWWall::ProcessWallSprite(HWDrawInfo* di, spritetype* spr, sectortype* sect
zbottom[0] = zbottom[1] = floorz;
}
}
// If the sprite is backward, flip it around so that we have guaranteed orientation when this is about to be sorted.
if (PointOnLineSide(di->Viewpoint.Pos.XY(), DVector2(glseg.x1, glseg.y1), DVector2(glseg.x2, glseg.y2)) < 0)
{
std::swap(glseg.x1, glseg.x2);
std::swap(glseg.y1, glseg.y2);
// z is always the same on both sides.
std::swap(tcs[LOLFT], tcs[LORGT]);
std::swap(tcs[UPLFT], tcs[UPRGT]);
}
PutWall(di, spriteHasTranslucency(sprite));
}