Skip to content

Commit

Permalink
- use float wall positions in portal code.
Browse files Browse the repository at this point in the history
  • Loading branch information
coelckers committed Feb 15, 2022
1 parent b641456 commit 4e2a9f6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 21 deletions.
2 changes: 1 addition & 1 deletion source/core/binaryangle.h
Expand Up @@ -365,7 +365,7 @@ inline FSerializer &Serialize(FSerializer &arc, const char *key, fixedhoriz &obj
//
//---------------------------------------------------------------------------

inline binangle bvectangbam(int32_t x, int32_t y)
inline binangle bvectangbam(double x, double y)
{
return radang(atan2(y, x));
}
Expand Down
4 changes: 2 additions & 2 deletions source/core/gamefuncs.cpp
Expand Up @@ -67,8 +67,8 @@ bool calcChaseCamPos(int* px, int* py, int* pz, DCoreActor* act, sectortype** ps
{
// Push you a little bit off the wall
*psect = hitinfo.hitSector;
daang = bvectangbam(hitinfo.hitWall->point2Wall()->wall_int_pos().X - hitinfo.hitWall->wall_int_pos().X,
hitinfo.hitWall->point2Wall()->wall_int_pos().Y - hitinfo.hitWall->wall_int_pos().Y);
daang = bvectangbam(hitinfo.hitWall->point2Wall()->pos.X - hitinfo.hitWall->pos.X,
hitinfo.hitWall->point2Wall()->pos.Y - hitinfo.hitWall->pos.Y);
newdist = nx * daang.bsin() + ny * -daang.bcos();

if (abs(nx) > abs(ny))
Expand Down
35 changes: 17 additions & 18 deletions source/core/rendering/scene/hw_portal.cpp
Expand Up @@ -524,22 +524,21 @@ bool HWMirrorPortal::Setup(HWDrawInfo *di, FRenderState &rstate, Clipper *clippe

di->mClipPortal = this;

int x = line->wall_int_pos().X;
int y = line->wall_int_pos().Y;
int dx = line->point2Wall()->wall_int_pos().X - x;
int dy = line->point2Wall()->wall_int_pos().Y - y;
double x = line->pos.X;
double y = line->pos.Y;
double dx = line->point2Wall()->pos.X - x;
double dy = line->point2Wall()->pos.Y - y;

// this can overflow so use 64 bit math.
const int64_t j = int64_t(dx) * dx + int64_t(dy) * dy;
const double j = dx * dx + dy * dy;
if (j == 0)
return false;

vec2_t view = { int(vp.Pos.X * 16), int(vp.Pos.Y * -16) };
DVector2 view = { vp.Pos.X, -vp.Pos.Y };

int64_t i = ((int64_t(view.X) - x) * dx + (int64_t(view.Y) - y) * dy) << 1;
double i = ((view.X - x) * dx + (view.Y - y) * dy) * 2;

int newx = int((x << 1) + Scale(dx, i, j) - view.X);
int newy = int((y << 1) + Scale(dy, i, j) - view.Y);
double newx = x * 2 + dx * i / j - view.X;
double newy = y * 2 + dy * i / j - view.Y;

auto myan = bvectangbam(dx, dy);
auto newan = myan + myan - bamang(vp.RotAngle);
Expand All @@ -548,8 +547,8 @@ bool HWMirrorPortal::Setup(HWDrawInfo *di, FRenderState &rstate, Clipper *clippe
vp.SectNums = nullptr;
vp.SectCount = line->sector;

vp.Pos.X = newx / 16.f;
vp.Pos.Y = newy / -16.f;
vp.Pos.X = newx;
vp.Pos.Y = -newy;
vp.HWAngles.Yaw = -90.f + newan.asdeg();

double FocalTangent = tan(vp.FieldOfView.Radians() / 2);
Expand All @@ -565,8 +564,8 @@ bool HWMirrorPortal::Setup(HWDrawInfo *di, FRenderState &rstate, Clipper *clippe

ClearClipper(di, clipper);

auto startan = bvectangbam(line->wall_int_pos().X - newx, line->wall_int_pos().Y - newy);
auto endan = bvectangbam(line->point2Wall()->wall_int_pos().X - newx, line->point2Wall()->wall_int_pos().Y - newy);
auto startan = bvectangbam(line->pos.X - newx, line->pos.Y - newy);
auto endan = bvectangbam(line->point2Wall()->pos.X - newx, line->point2Wall()->pos.Y - newy);
clipper->RestrictVisibleRange(endan, startan); // we check the line from the backside so angles are reversed.
return true;
}
Expand Down Expand Up @@ -674,8 +673,8 @@ bool HWLineToSpritePortal::Setup(HWDrawInfo* di, FRenderState& rstate, Clipper*
DVector2 destcenter ={ camera->spr.pos.X / 16.f, camera->spr.pos.Y / -16.f };
DVector2 npos = vp.Pos - srccenter + destcenter;

int origx = vp.Pos.X * 16;
int origy = vp.Pos.Y * -16;
double origx = vp.Pos.X;
double origy = vp.Pos.Y;

vp.SectNums = nullptr;
vp.SectCount = camera->sectno();
Expand All @@ -687,8 +686,8 @@ bool HWLineToSpritePortal::Setup(HWDrawInfo* di, FRenderState& rstate, Clipper*

ClearClipper(di, clipper);

auto startan = bvectangbam(origin->wall_int_pos().X - origx, origin->wall_int_pos().Y - origy);
auto endan = bvectangbam(origin->point2Wall()->wall_int_pos().X - origx, origin->point2Wall()->wall_int_pos().Y - origy);
auto startan = bvectangbam(origin->pos.X - origx, origin->pos.Y - origy);
auto endan = bvectangbam(origin->point2Wall()->pos.X - origx, origin->point2Wall()->pos.Y - origy);
clipper->RestrictVisibleRange(startan, endan);
return true;
}
Expand Down

0 comments on commit 4e2a9f6

Please sign in to comment.