add a bit of vertical tolerance to neartag's sprite check.

This is not pitch aware and can cause problems with very small sprites on occasion.
This commit is contained in:
Christoph Oelckers 2023-05-20 09:01:46 +02:00
parent 1d0b763844
commit 4e6023ea34
2 changed files with 8 additions and 4 deletions

View file

@ -523,7 +523,7 @@ int testpointinquad(const DVector2& pt, const DVector2* quad)
//
//==========================================================================
double intersectSprite(DCoreActor* actor, const DVector3& start, const DVector3& direction, DVector3& result, double maxfactor)
double intersectSprite(DCoreActor* actor, const DVector3& start, const DVector3& direction, DVector3& result, double maxfactor, double tolerance = 0)
{
auto end = start + direction;
if (direction.XY().isZero()) return false;
@ -537,12 +537,17 @@ double intersectSprite(DCoreActor* actor, const DVector3& start, const DVector3&
auto sprwidth = tex->GetDisplayWidth() * actor->spr.scale.X * 0.5;
auto point = start + direction * factor;
if (actor->time == 283)
{
int a = 0;
}
// Using proper distance here, Build originally used the sum of x- and y-distance
if ((point.XY() - actor->spr.pos.XY()).LengthSquared() > sprwidth * sprwidth * 0.5) return -1; // too far away
double siz, hitz = actor->spr.pos.Z + actor->GetOffsetAndHeight(siz);
if (point.Z < hitz - siz || point.Z > hitz)
if (point.Z < hitz - siz - tolerance || point.Z > hitz + tolerance)
return -1;
result = point;
@ -1123,7 +1128,7 @@ void neartag(const DVector3& pos, sectortype* startsect, DAngle angle, HitInfoBa
if (checkTag(&actor->spr))
{
DVector3 spot;
double newfactor = intersectSprite(actor, pos, v, spot, factor - 1. / 65536.);
double newfactor = intersectSprite(actor, pos, v, spot, factor - 1. / 65536., 1);
if (newfactor > 0)
{
factor = newfactor;

View file

@ -208,7 +208,6 @@ extern double cameradist, cameraclock;
bool calcChaseCamPos(DVector3& ppos, DCoreActor* pspr, sectortype** psectnum, const DRotator& angles, double const interpfrac, double const backamp);
int getslopeval(sectortype* sect, const DVector3& pos, double bazez);
bool cansee(const DVector3& start, sectortype* sect1, const DVector3& end, sectortype* sect2);
double intersectSprite(DCoreActor* actor, const DVector3& start, const DVector3& direction, DVector3& result, double maxfactor);
double intersectWallSprite(DCoreActor* actor, const DVector3& start, const DVector3& direction, DVector3& result, double maxfactor, bool checktex = false);
double intersectFloorSprite(DCoreActor* actor, const DVector3& start, const DVector3& direction, DVector3& result, double maxfactor);
double intersectSlopeSprite(DCoreActor* actor, const DVector3& start, const DVector3& direction, DVector3& result, double maxfactor);