mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2026-04-27 04:21:47 +00:00
Refactor R_PointToAnglePlayer
This commit is contained in:
parent
b3cee8b8fc
commit
82fa875502
1 changed files with 20 additions and 38 deletions
58
src/r_main.c
58
src/r_main.c
|
|
@ -318,18 +318,7 @@ INT32 R_PointOnSegSide(fixed_t x, fixed_t y, seg_t *line)
|
||||||
|
|
||||||
angle_t R_PointToAngle(fixed_t x, fixed_t y)
|
angle_t R_PointToAngle(fixed_t x, fixed_t y)
|
||||||
{
|
{
|
||||||
return (y -= viewy, (x -= viewx) || y) ?
|
return R_PointToAngle2(viewx, viewy, x, y);
|
||||||
x >= 0 ?
|
|
||||||
y >= 0 ?
|
|
||||||
(x > y) ? tantoangle[SlopeDiv(y,x)] : // octant 0
|
|
||||||
ANGLE_90-tantoangle[SlopeDiv(x,y)] : // octant 1
|
|
||||||
x > (y = -y) ? 0-tantoangle[SlopeDiv(y,x)] : // octant 8
|
|
||||||
ANGLE_270+tantoangle[SlopeDiv(x,y)] : // octant 7
|
|
||||||
y >= 0 ? (x = -x) > y ? ANGLE_180-tantoangle[SlopeDiv(y,x)] : // octant 3
|
|
||||||
ANGLE_90 + tantoangle[SlopeDiv(x,y)] : // octant 2
|
|
||||||
(x = -x) > (y = -y) ? ANGLE_180+tantoangle[SlopeDiv(y,x)] : // octant 4
|
|
||||||
ANGLE_270-tantoangle[SlopeDiv(x,y)] : // octant 5
|
|
||||||
0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Similar to R_PointToAngle, but requires an additional player_t argument.
|
// Similar to R_PointToAngle, but requires an additional player_t argument.
|
||||||
|
|
@ -338,33 +327,26 @@ angle_t R_PointToAngle(fixed_t x, fixed_t y)
|
||||||
angle_t R_PointToAnglePlayer(player_t *player, fixed_t x, fixed_t y)
|
angle_t R_PointToAnglePlayer(player_t *player, fixed_t x, fixed_t y)
|
||||||
{
|
{
|
||||||
fixed_t refx = viewx, refy = viewy;
|
fixed_t refx = viewx, refy = viewy;
|
||||||
camera_t *cam = &camera[0];
|
camera_t *cam = NULL;
|
||||||
|
UINT8 i;
|
||||||
// Check for splitscreen players and get their cam if possible.
|
|
||||||
if (player == &players[displayplayers[1]])
|
for (i = 0; i < r_splitscreen; i++)
|
||||||
cam = &camera[1];
|
{
|
||||||
else if (player == &players[displayplayers[2]])
|
if (player == &players[displayplayers[i]])
|
||||||
cam = &camera[2];
|
{
|
||||||
else if (player == &players[displayplayers[3]])
|
cam = &camera[i];
|
||||||
cam = &camera[3];
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// use whatever cam we found's coordinates.
|
// use whatever cam we found's coordinates.
|
||||||
refx = cam->x;
|
if (cam != NULL)
|
||||||
refy = cam->y;
|
{
|
||||||
|
refx = cam->x;
|
||||||
// Now do whatever tehe fuck is this hellish maths from R_PointToAngle while swapping viewx/viewy for our refx/refy
|
refy = cam->y;
|
||||||
return (y -= refy, (x -= refx) || y) ?
|
}
|
||||||
x >= 0 ?
|
|
||||||
y >= 0 ?
|
return R_PointToAngle2(refx, refy, x, y);
|
||||||
(x > y) ? tantoangle[SlopeDiv(y,x)] : // octant 0
|
|
||||||
ANGLE_90-tantoangle[SlopeDiv(x,y)] : // octant 1
|
|
||||||
x > (y = -y) ? 0-tantoangle[SlopeDiv(y,x)] : // octant 8
|
|
||||||
ANGLE_270+tantoangle[SlopeDiv(x,y)] : // octant 7
|
|
||||||
y >= 0 ? (x = -x) > y ? ANGLE_180-tantoangle[SlopeDiv(y,x)] : // octant 3
|
|
||||||
ANGLE_90 + tantoangle[SlopeDiv(x,y)] : // octant 2
|
|
||||||
(x = -x) > (y = -y) ? ANGLE_180+tantoangle[SlopeDiv(y,x)] : // octant 4
|
|
||||||
ANGLE_270-tantoangle[SlopeDiv(x,y)] : // octant 5
|
|
||||||
0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This version uses 64-bit variables to avoid overflows with large values.
|
// This version uses 64-bit variables to avoid overflows with large values.
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue