From 5eb4ed83918c2d77774f0cb38d47a2d5dba4c87f Mon Sep 17 00:00:00 2001 From: "James R." Date: Wed, 13 Sep 2023 00:27:06 -0700 Subject: [PATCH] R_FindPlane: fix offsets rotation overflow for non-sloped planes --- src/r_plane.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/r_plane.cpp b/src/r_plane.cpp index 4153590ba..5cb69f607 100644 --- a/src/r_plane.cpp +++ b/src/r_plane.cpp @@ -397,12 +397,20 @@ visplane_t *R_FindPlane(fixed_t height, INT32 picnum, INT32 lightlevel, { if (plangle != 0) { + // Must use 64-bit math to avoid an overflow! + INT64 vx = xoff + viewx; + INT64 vy = yoff - viewy; + // Add the view offset, rotated by the plane angle. - fixed_t cosinecomponent = FINECOSINE(plangle>>ANGLETOFINESHIFT); - fixed_t sinecomponent = FINESINE(plangle>>ANGLETOFINESHIFT); - fixed_t oldxoff = xoff; - xoff = FixedMul(xoff,cosinecomponent)+FixedMul(yoff,sinecomponent); - yoff = -FixedMul(oldxoff,sinecomponent)+FixedMul(yoff,cosinecomponent); + float ang = ANG2RAD(plangle); + float x = vx / (float)FRACUNIT; + float y = vy / (float)FRACUNIT; + + vx = (x * cos(ang) + y * sin(ang)) * FRACUNIT; + vy = (-x * sin(ang) + y * cos(ang)) * FRACUNIT; + + xoff = vx; + yoff = vy; } else {