- merge NearestPointLine into NearestPointOnWall

This commit is contained in:
Christoph Oelckers 2022-09-16 19:59:10 +02:00
parent c44fd07f37
commit f5e6503b26
2 changed files with 8 additions and 22 deletions

View file

@ -462,7 +462,7 @@ inline double SquareDist(double lx1, double ly1, double lx2, double ly2)
return dx * dx + dy * dy;
}
inline DVector2 NearestPointLine(double px, double py, const walltype* wal)
inline DVector2 NearestPointOnWall(double px, double py, const walltype* wal, bool clamp = true)
{
double lx1 = wal->pos.X;
double ly1 = wal->pos.Y;
@ -474,25 +474,11 @@ inline DVector2 NearestPointLine(double px, double py, const walltype* wal)
if (wall_length == 0) return { lx1, ly1 };
double t = ((px - lx1) * (lx2 - lx1) + (py - ly1) * (ly2 - ly1)) / wall_length;
double xx = lx1 + t * (lx2 - lx1);
double yy = ly1 + t * (ly2 - ly1);
return { xx, yy };
}
inline DVector2 NearestPointOnWall(double px, double py, const walltype* wal)
{
double lx1 = wal->pos.X;
double ly1 = wal->pos.Y;
double lx2 = wal->point2Wall()->pos.X;
double ly2 = wal->point2Wall()->pos.Y;
double wall_length = SquareDist(lx1, ly1, lx2, ly2);
if (wall_length == 0) return { lx1, ly1 };
double t = ((px - lx1) * (lx2 - lx1) + (py - ly1) * (ly2 - ly1)) / wall_length;
if (t <= 0) return { lx1, ly1 };
if (t >= 1) return { lx2, ly2 };
if (clamp)
{
if (t <= 0) return { lx1, ly1 };
if (t >= 1) return { lx2, ly2 };
}
double xx = lx1 + t * (lx2 - lx1);
double yy = ly1 + t * (ly2 - ly1);
return { xx, yy };

View file

@ -1174,8 +1174,8 @@ void HWWall::ProcessWallSprite(HWDrawInfo* di, tspritetype* spr, sectortype* sec
if (walldist)
{
// project the sprite right onto the wall.
auto v1 = NearestPointLine(glseg.x1, -glseg.y1, walldist);
auto v2 = NearestPointLine(glseg.x2, -glseg.y2, walldist);
auto v1 = NearestPointOnWall(glseg.x1, -glseg.y1, walldist, false);
auto v2 = NearestPointOnWall(glseg.x2, -glseg.y2, walldist, false);
glseg.x1 = v1.X;
glseg.y1 = -v1.Y;
glseg.x2 = v2.X;