- floatified HitScan and use a proper vector calculation for hitscangoal.

This should be on the trace, not use a totally different direction.
This commit is contained in:
Christoph Oelckers 2022-09-27 15:46:46 +02:00
parent 2fe5655394
commit 1d8dccca04
2 changed files with 15 additions and 11 deletions

View file

@ -284,19 +284,17 @@ bool IntersectRay(int wx, int wy, int wdx, int wdy, int x1, int y1, int z1, int
//
//---------------------------------------------------------------------------
int HitScan_(DBloodActor* actor, int z, int dx, int dy, int dz, unsigned int nMask, int nRange)
int HitScan(DBloodActor* actor, double z, const DVector3& vect, unsigned int nMask, double nRange)
{
double zz = z * zinttoworld;
assert(actor != nullptr);
assert(dx != 0 || dy != 0);
assert(!vect.XY().isZero());
gHitInfo.clearObj();
auto bakCstat = actor->spr.cstat;
actor->spr.cstat &= ~CSTAT_SPRITE_BLOCK_HITSCAN;
DVector2 hitscangoal;
if (nRange) hitscangoal = actor->spr.pos.XY() + actor->spr.angle.ToVector() * nRange;
if (nRange > 0) hitscangoal = actor->spr.pos.XY() + vect.XY().Resized(nRange);
else hitscangoal.Zero();
hitscan(DVector3(actor->spr.pos.XY(), zz), actor->sector(), DVector3(dx, dy, dz) * inttoworld, gHitInfo, nMask, &hitscangoal);
hitscan(DVector3(actor->spr.pos.XY(), z), actor->sector(), vect, gHitInfo, nMask, &hitscangoal);
actor->spr.cstat = bakCstat;
if (gHitInfo.actor() != nullptr)
@ -314,7 +312,7 @@ int HitScan_(DBloodActor* actor, int z, int dx, int dy, int dz, unsigned int nMa
return 4;
}
if (gHitInfo.hitSector != nullptr)
return 1 + (zz < gHitInfo.hitpos.Z);
return 1 + (z < gHitInfo.hitpos.Z);
return -1;
}
@ -335,7 +333,7 @@ int VectorScan(DBloodActor* actor, double nOffset, double nZOffset, const DVecto
actor->spr.cstat &= ~CSTAT_SPRITE_BLOCK_HITSCAN;
DVector2 hitscangoal;
if (nRange) hitscangoal = actor->spr.pos.XY() + actor->spr.angle.ToVector() * nRange;
if (nRange > 0) hitscangoal = actor->spr.pos.XY() + vel.XY().Resized(nRange);
else hitscangoal.Zero();
hitscan(pos, actor->sector(), vel, gHitInfo, CLIPMASK1, &hitscangoal);

View file

@ -36,14 +36,20 @@ bool CheckProximity(DBloodActor* pSprite, const DVector3& pos, sectortype* pSect
bool CheckProximityPoint(int nX1, int nY1, int nZ1, int nX2, int nY2, int nZ2, int nDist);
[[deprecated]] int GetWallAngle(walltype* pWall);
bool IntersectRay(int wx, int wy, int wdx, int wdy, int x1, int y1, int z1, int x2, int y2, int z2, int* ix, int* iy, int* iz);
int HitScan_(DBloodActor* pSprite, int z, int dx, int dy, int dz, unsigned int nMask, int a8);
int HitScan(DBloodActor* pSprite, double z, const DVector3& pos, unsigned int nMask, double range = 0);
inline int HitScan_(DBloodActor* pSprite, int z, int dx, int dy, int dz, unsigned int nMask, int a8)
{
return HitScan(pSprite, z * zinttoworld, DVector3(dx, dy, dz) * inttoworld, nMask, a8 * inttoworld);
}
inline int HitScan_(DBloodActor* pSprite, double z, int dx, int dy, int dz, unsigned int nMask, int a8)
{
return HitScan_(pSprite, int(z * zworldtoint), dx, dy, dz, nMask, a8);
return HitScan(pSprite, z, DVector3(dx, dy, dz) * inttoworld, nMask, a8 * inttoworld);
}
inline int HitScan_(DBloodActor* pSprite, double z, const DVector3& pos, unsigned int nMask, int a8)
{
return HitScan_(pSprite, int(z * zworldtoint), int(pos.X * worldtoint), int(pos.Y * worldtoint), int(pos.Z * zworldtoint), nMask, a8);
return HitScan(pSprite, z, pos, nMask, a8 * inttoworld);
}
int VectorScan(DBloodActor* pSprite, double nOffset, double nZOffset, const DVector3& vel, double nRange, int ac);