- cleanup of bvectan family of functions.

This can be greatly simplified to a single bvectangbam function using atan2 directly.
This commit is contained in:
Christoph Oelckers 2021-04-10 12:54:29 +02:00
parent b4d89cbac3
commit 057b8a7354
4 changed files with 10 additions and 48 deletions

View file

@ -3315,7 +3315,7 @@ void renderPrepareMirror(int32_t dax, int32_t day, int32_t daz, fixed_t daang, f
*tposx = (x << 1) + Scale(dx, i, j) - dax;
*tposy = (y << 1) + Scale(dy, i, j) - day;
*tang = ((bvectangq16(dx, dy) << 1) - daang) & 0x7FFFFFF;
*tang = ((bvectangbam(dx, dy).asq16() << 1) - daang) & 0x7FFFFFF;
inpreparemirror = 1;

View file

@ -502,54 +502,11 @@ inline FSerializer &Serialize(FSerializer &arc, const char *key, fixedhoriz &obj
//---------------------------------------------------------------------------
//
// Double-precision implementation of `getangle()` with associated wrappers and helper functions.
// High precision vector angle function, mainly for the renderer.
//
//---------------------------------------------------------------------------
inline double bradarangf(double vect)
{
return atan(vect) * BRadAngScale;
}
inline double bvectangf(int32_t x, int32_t y)
{
if ((x | y) == 0)
{
return 0;
}
else if (x == 0)
{
return 512 + ((y < 0) << 10);
}
else if (y == 0)
{
return ((x < 0) << 10);
}
else if (x == y)
{
return 256 + ((x < 0) << 10);
}
else if (x == -y)
{
return 768 + ((x > 0) << 10);
}
else if (abs(x) > abs(y))
{
return fmod(bradarangf(double(y) / x) + ((x < 0) << 10), 2048.);
}
else
{
return fmod(bradarangf(double(x) / -y) + 512 + ((y < 0) << 10), 2048.);
}
}
inline int32_t bvectang(int32_t x, int32_t y)
{
return xs_CRoundToInt(bvectangf(x, y));
}
inline fixed_t bvectangq16(int32_t x, int32_t y)
{
return FloatToFixed(bvectangf(x, y));
}
inline binangle bvectangbam(int32_t x, int32_t y)
{
return bamang(xs_CRoundToUInt(bvectangf(x, y) * BAMUNIT));
return radang(atan2(y, x));
}

View file

@ -574,7 +574,10 @@ bool HWMirrorPortal::Setup(HWDrawInfo *di, FRenderState &rstate, Clipper *clippe
int newx = int((x << 1) + Scale(dx, i, j) - view.x);
int newy = int((y << 1) + Scale(dy, i, j) - view.y);
auto newan = bamang(int64_t((bvectangf(dx, dy) * (BAMUNIT << 1)) - vp.RotAngle) & 0xFFFFFFFF);
auto myan = bvectangbam(dx, dy);
auto newan = myan + myan - bamang(vp.RotAngle);
vp.RotAngle = newan.asbam();
vp.SectNums = nullptr;
vp.SectCount = line->sector;

View file

@ -7148,7 +7148,9 @@ domovethings(void)
// auto tracking mode for single player multi-game
if (numplayers <= 1 && PlayerTrackingMode && pnum == screenpeek && screenpeek != myconnectindex)
{
Player[screenpeek].angle.settarget(bvectangf(Player[myconnectindex].posx - Player[screenpeek].posx, Player[myconnectindex].posy - Player[screenpeek].posy));
int deltax = Player[myconnectindex].posx - Player[screenpeek].posx;
int deltay = Player[myconnectindex].posy - Player[screenpeek].posy;
Player[screenpeek].angle.settarget(bvectangbam(deltax, deltay));
}
if (!TEST(pp->Flags, PF_DEAD))