- changed math utilities to floating point coordinate system.

This commit is contained in:
Christoph Oelckers 2022-01-30 14:55:36 +01:00
parent 8cc8ebf30c
commit 71943abed0
5 changed files with 27 additions and 25 deletions

View file

@ -357,10 +357,10 @@ inline double SquareDist(double lx1, double ly1, double lx2, double ly2)
inline DVector2 NearestPointLine(double px, double py, const walltype* wal)
{
double lx1 = wal->wall_int_pos().X;
double ly1 = wal->wall_int_pos().Y;
double lx2 = wal->point2Wall()->wall_int_pos().X;
double ly2 = wal->point2Wall()->wall_int_pos().Y;
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);
@ -374,10 +374,10 @@ inline DVector2 NearestPointLine(double px, double py, const walltype* wal)
inline double SquareDistToWall(double px, double py, const walltype* wal, DVector2* point = nullptr)
{
double lx1 = wal->wall_int_pos().X;
double ly1 = wal->wall_int_pos().Y;
double lx2 = wal->point2Wall()->wall_int_pos().X;
double ly2 = wal->point2Wall()->wall_int_pos().Y;
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);

View file

@ -463,9 +463,8 @@ retry:
return -1;
DVector2 intersect;
SquareDistToWall(x1s * 16., y1s * -16., &wall[line2], &intersect);
intersect.X *= (1 / 16.);
intersect.Y *= (1 / -16.);
SquareDistToWall(x1s, -y1s, &wall[line2], &intersect);
intersect.Y = -intersect.Y;
if (d3 < max_overlap)
{

View file

@ -50,12 +50,15 @@ DCoreActor* wall_to_sprite_actors[8]; // gets updated each frame. Todo: Encapsul
static walltype* IsOnWall(tspritetype* tspr, int height, DVector2& outpos)
{
double maxorthdist = 3; // maximum orthogonal distance to be considered an attached sprite.
double maxdistsq = 3 * 3;
double maxorthdist = 3 * maptoworld; // maximum orthogonal distance to be considered an attached sprite.
double maxdistsq = maxorthdist * maxorthdist;
walltype* best = nullptr;
auto sect = tspr->sectp;
float tx = tspr->pos.X * (float)inttoworld;
float ty = tspr->pos.Y * (float)inttoworld;
for(auto& wal : wallsofsector(sect))
{
// Intentionally include two sided walls. Even on them the sprite should be projected onto the wall for better results.
@ -71,7 +74,7 @@ static walltype* IsOnWall(tspritetype* tspr, int height, DVector2& outpos)
// In Wanton Destruction's airplane level there's such a sprite assigned to the wrong sector.
if (d.X == 0)
{
double newdist = fabs(tspr->pos.X - wal.wall_int_pos().X);
double newdist = fabs(tx - wal.pos.X);
if (newdist < maxorthdist)
{
maxorthdist = newdist;
@ -80,7 +83,7 @@ static walltype* IsOnWall(tspritetype* tspr, int height, DVector2& outpos)
}
else if (d.Y == 0)
{
double newdist = fabs(tspr->pos.Y - wal.wall_int_pos().Y);
double newdist = fabs(ty - wal.pos.Y);
if (newdist < maxorthdist)
{
maxorthdist = newdist;
@ -89,7 +92,7 @@ static walltype* IsOnWall(tspritetype* tspr, int height, DVector2& outpos)
}
else
{
double wdist = SquareDistToWall(tspr->pos.X, tspr->pos.Y, &wal, &outpos);
double wdist = SquareDistToWall(tx, ty, &wal, &outpos);
if (wdist <= maxdistsq)
{
return &wal;
@ -1140,12 +1143,12 @@ void HWWall::ProcessWallSprite(HWDrawInfo* di, tspritetype* spr, sectortype* sec
if (walldist)
{
// project the sprite right onto the wall.
auto v1 = NearestPointLine(pos[0].X, pos[0].Y, walldist);
auto v2 = NearestPointLine(pos[1].X, pos[1].Y, walldist);
glseg.x1 = v1.X * (1 / 16.f);
glseg.y1 = v1.Y * (1 / -16.f);
glseg.x2 = v2.X * (1 / 16.f);
glseg.y2 = v2.Y * (1 / -16.f);
auto v1 = NearestPointLine(glseg.x1, -glseg.y1, walldist);
auto v2 = NearestPointLine(glseg.x2, -glseg.y2, walldist);
glseg.x1 = v1.X;
glseg.y1 = -v1.Y;
glseg.x2 = v2.X;
glseg.y2 = -v2.Y;
}

View file

@ -772,7 +772,7 @@ BitArray GetClosestSpriteSectors(sectortype* pSector, int x, int y, int nDist, T
BitArray sectorMap(sector.Size()); // this gets returned to the caller.
sectorMap.Zero();
sectorMap.Set(sectnum(pSector));
double nDist4sq = 256. * nDist * nDist; // (nDist * 16)^2 - * 16 to account for Build's 28.4 fixed point format.
double nDist4sq = nDist * nDist; // (nDist * 16)^2 - * 16 to account for Build's 28.4 fixed point format.
BFSSectorSearch search(pSector);
@ -792,7 +792,7 @@ BitArray GetClosestSpriteSectors(sectortype* pSector, int x, int y, int nDist, T
}
else // new method using proper math and no bad shortcut.
{
double dist1 = SquareDistToWall(x, y, &wal);
double dist1 = SquareDistToWall(x * inttoworld, y * inttoworld, &wal);
withinRange = dist1 <= nDist4sq;
}
if (withinRange) // if new sector is within range, add it to the processing queue

View file

@ -254,7 +254,7 @@ void AddFlash(sectortype* pSector, int x, int y, int z, int val)
if (!var_18)
{
walldist = (((int)sqrt(SquareDistToWall(x, y, &wal))) >> 4) - 255;
walldist = (int)sqrt(SquareDistToWall(x * inttoworld, y * inttoworld, &wal)) - 255;
}
if (walldist < 0)