From ad95233529791f1a40d4c47ce8c24252ebbd4eef Mon Sep 17 00:00:00 2001 From: yamamama Date: Sun, 8 Mar 2026 00:40:57 -0500 Subject: [PATCH] Fix object sloperoll issues --- src/p_user.c | 4 ++-- src/r_main.cpp | 27 +++++++++++++++++++++++++++ src/r_main.h | 2 ++ src/r_patchrotation.c | 4 ++-- 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/p_user.c b/src/p_user.c index f5a740e10..b12c21904 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -3884,8 +3884,8 @@ static angle_t P_GetCameraPitchRollAngle(mobj_t *mobj, player_t *viewPlayer) } else { - // Regular Mobjs don't air tilt. - viewingAngle = mobj->angle; + // For regular objects, use the camera; just not the *player's* camera. + viewingAngle = R_PointToAngleFloat(mobj->x, mobj->y); } pitchMul = -FINESINE(viewingAngle >> ANGLETOFINESHIFT); diff --git a/src/r_main.cpp b/src/r_main.cpp index d40a377d1..bc31300ef 100644 --- a/src/r_main.cpp +++ b/src/r_main.cpp @@ -14,6 +14,7 @@ /// See tables.c, too. #include +#include #include "doomdef.h" #include "g_game.h" @@ -51,6 +52,9 @@ extern consvar_t cv_debugrender_freezebsp; // Fineangles in the SCREENWIDTH wide window. #define FIELDOFVIEW 2048 +// Double-precision Pi value +#define DOUBLE_PI 3.141592653589793 + // increment every time a check is made size_t validcount = 1; @@ -387,6 +391,29 @@ angle_t R_PointToAngle2(fixed_t pviewx, fixed_t pviewy, fixed_t x, fixed_t y) 0; } +#define ANGLE_180_DOUBLE (static_cast(ANGLE_180)) +#define ANGLE_360_DOUBLE (ANGLE_180_DOUBLE * 2) + +// For absolute accuracy. Please don't use this outside of renderers. +angle_t R_PointToAngleFloat2(fixed_t x1, fixed_t y1, fixed_t x2, fixed_t y2) +{ + double deltax = FixedToDouble(x2 - x1); + double deltay = FixedToDouble(y2 - y1); + + // Converted to degrees + double _arctan = (atan2(deltay, deltax) * ANGLE_180_DOUBLE) / DOUBLE_PI; + + while (_arctan < 0) + { + _arctan += ANGLE_360_DOUBLE; + } + + return static_cast(_arctan); +} + +#undef ANGLE_180_DOUBLE +#undef ANGLE_360_DOUBLE + // // R_ScaleFromGlobalAngle // Returns the texture mapping scale for the current line (horizontal span) diff --git a/src/r_main.h b/src/r_main.h index 26bcecf97..dbc0b89c6 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -83,9 +83,11 @@ FUNCINLINE static ATTRINLINE INT32 R_PointOnSideFast(fixed_t x, fixed_t y, const INT32 R_PointOnSegSide(fixed_t x, fixed_t y, const seg_t *line); #define R_PointToAngle(x, y) R_PointToAngle2(viewx, viewy, x, y) +#define R_PointToAngleFloat(x, y) (R_PointToAngleFloat2(viewx, viewy, x, y)) angle_t R_PointToAnglePlayer(player_t *player, fixed_t x, fixed_t y); angle_t R_PointToAngle64(INT64 x, INT64 y); angle_t R_PointToAngle2(fixed_t px2, fixed_t py2, fixed_t px1, fixed_t py1); +angle_t R_PointToAngleFloat2(fixed_t x1, fixed_t y1, fixed_t x2, fixed_t y2); #define R_PointToDist(x, y) R_PointToDist2(viewx, viewy, x, y) #define R_PointToDist2(px2, py2, px1, py1) FixedHypot((px1) - (px2), (py1) - (py2)) diff --git a/src/r_patchrotation.c b/src/r_patchrotation.c index 581ce37af..251cfe141 100644 --- a/src/r_patchrotation.c +++ b/src/r_patchrotation.c @@ -38,8 +38,8 @@ angle_t R_GetPitchRollAngle(mobj_t *mobj, player_t *viewPlayer, interpmobjstate_ } else { - // Regular Mobjs don't air tilt. - viewingAngle = mobj->angle; + // For regular objects, use the camera; just not the *player's* camera. + viewingAngle = R_PointToAngleFloat(mobj->x, mobj->y); } pitchMul = -FINESINE(viewingAngle >> ANGLETOFINESHIFT);