From 050148216080f5e4ba4e9494b6c74a10dfc731d4 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 10 Oct 2022 23:11:54 +0200 Subject: [PATCH] - added missing distance check for sprites to hitscan. --- source/build/src/clip.cpp | 8 +++++--- source/common/utility/vectors.h | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/source/build/src/clip.cpp b/source/build/src/clip.cpp index 0b6d23512..1c49648b1 100644 --- a/source/build/src/clip.cpp +++ b/source/build/src/clip.cpp @@ -1247,10 +1247,12 @@ int hitscan(const vec3_t& start, const sectortype* startsect, const vec3_t& dire case 0: { auto v = hitinfo.hitpos; - if (intersectSprite(actor, DVector3(sv->X * inttoworld, sv->Y * inttoworld, sv->Z * zinttoworld), - DVector3(vx * inttoworld, vy * inttoworld, vz * zinttoworld), v, 0) ) + DVector3 start(sv->X * inttoworld, sv->Y * inttoworld, sv->Z * zinttoworld); + DVector3 direction(vx * inttoworld, vy * inttoworld, vz * zinttoworld); + if (intersectSprite(actor, start, direction, v, 0)) { - hit_set(&hitinfo, sec, nullptr, actor, v.X * worldtoint, v.Y * worldtoint, v.Z * zworldtoint); + if ((v.XY() - start.XY()).Sum() < (hitinfo.hitpos.XY() - start.XY()).Sum()) + hit_set(&hitinfo, sec, nullptr, actor, v.X * worldtoint, v.Y * worldtoint, v.Z * zworldtoint); } break; diff --git a/source/common/utility/vectors.h b/source/common/utility/vectors.h index 28a4fdcc9..a11f72a15 100644 --- a/source/common/utility/vectors.h +++ b/source/common/utility/vectors.h @@ -310,13 +310,13 @@ struct TVector2 } // Returns a vector rotated 90 degrees clockwise. - TVector2 Rotated90CW() + TVector2 Rotated90CW() const { return TVector2(Y, -X); } // Returns a vector rotated 90 degrees counterclockwise. - TVector2 Rotated90CCW() + TVector2 Rotated90CCW() const { return TVector2(-Y, X); }