From f5e6503b26b87deccc21cc03631b93e98d032cea Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Fri, 16 Sep 2022 19:59:10 +0200 Subject: [PATCH] - merge NearestPointLine into NearestPointOnWall --- source/core/gamefuncs.h | 26 ++++++------------------ source/core/rendering/scene/hw_walls.cpp | 4 ++-- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/source/core/gamefuncs.h b/source/core/gamefuncs.h index b701dc4dd..b99f6bc78 100644 --- a/source/core/gamefuncs.h +++ b/source/core/gamefuncs.h @@ -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 }; diff --git a/source/core/rendering/scene/hw_walls.cpp b/source/core/rendering/scene/hw_walls.cpp index d70dd02d7..f0112dd3b 100644 --- a/source/core/rendering/scene/hw_walls.cpp +++ b/source/core/rendering/scene/hw_walls.cpp @@ -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;