From d62a62834626a1dd4bf828c2002ffa57a9364546 Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Thu, 30 Mar 2017 21:57:36 +0100 Subject: [PATCH 01/12] Consistency between software off-slope and GL on+off-slope flat alignment! (Software slopes are now MORE broken with respect to this, but that comes later.) --- src/hardware/hw_main.c | 18 +++++++++--------- src/p_spec.c | 6 ++---- src/r_plane.c | 9 ++++++--- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 7bc12ba75..67eb5d41a 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -641,13 +641,13 @@ static void HWR_RenderPlane(sector_t *sector, extrasubsector_t *xsub, boolean is { scrollx = FIXED_TO_FLOAT(FOFsector->floor_xoffs)/fflatsize; scrolly = FIXED_TO_FLOAT(FOFsector->floor_yoffs)/fflatsize; - angle = FOFsector->floorpic_angle>>ANGLETOFINESHIFT; + angle = FOFsector->floorpic_angle; } else // it's a ceiling { scrollx = FIXED_TO_FLOAT(FOFsector->ceiling_xoffs)/fflatsize; scrolly = FIXED_TO_FLOAT(FOFsector->ceiling_yoffs)/fflatsize; - angle = FOFsector->ceilingpic_angle>>ANGLETOFINESHIFT; + angle = FOFsector->ceilingpic_angle; } } else if (gr_frontsector) @@ -656,24 +656,24 @@ static void HWR_RenderPlane(sector_t *sector, extrasubsector_t *xsub, boolean is { scrollx = FIXED_TO_FLOAT(gr_frontsector->floor_xoffs)/fflatsize; scrolly = FIXED_TO_FLOAT(gr_frontsector->floor_yoffs)/fflatsize; - angle = gr_frontsector->floorpic_angle>>ANGLETOFINESHIFT; + angle = gr_frontsector->floorpic_angle; } else // it's a ceiling { scrollx = FIXED_TO_FLOAT(gr_frontsector->ceiling_xoffs)/fflatsize; scrolly = FIXED_TO_FLOAT(gr_frontsector->ceiling_yoffs)/fflatsize; - angle = gr_frontsector->ceilingpic_angle>>ANGLETOFINESHIFT; + angle = gr_frontsector->ceilingpic_angle; } } if (angle) // Only needs to be done if there's an altered angle { - + angle = InvAngle(angle)>>ANGLETOFINESHIFT; // This needs to be done so that it scrolls in a different direction after rotation like software - tempxsow = FLOAT_TO_FIXED(scrollx); + /*tempxsow = FLOAT_TO_FIXED(scrollx); tempytow = FLOAT_TO_FIXED(scrolly); scrollx = (FIXED_TO_FLOAT(FixedMul(tempxsow, FINECOSINE(angle)) - FixedMul(tempytow, FINESINE(angle)))); - scrolly = (FIXED_TO_FLOAT(FixedMul(tempxsow, FINESINE(angle)) + FixedMul(tempytow, FINECOSINE(angle)))); + scrolly = (FIXED_TO_FLOAT(FixedMul(tempxsow, FINESINE(angle)) + FixedMul(tempytow, FINECOSINE(angle))));*/ // This needs to be done so everything aligns after rotation // It would be done so that rotation is done, THEN the translation, but I couldn't get it to rotate AND scroll like software does @@ -687,7 +687,7 @@ static void HWR_RenderPlane(sector_t *sector, extrasubsector_t *xsub, boolean is { // Hurdler: add scrolling texture on floor/ceiling v3d->sow = (float)((pv->x / fflatsize) - flatxref + scrollx); - v3d->tow = (float)(flatyref - (pv->y / fflatsize) + scrolly); + v3d->tow = (float)(-(pv->y / fflatsize) + flatyref - scrolly); //v3d->sow = (float)(pv->x / fflatsize); //v3d->tow = (float)(pv->y / fflatsize); @@ -698,7 +698,7 @@ static void HWR_RenderPlane(sector_t *sector, extrasubsector_t *xsub, boolean is tempxsow = FLOAT_TO_FIXED(v3d->sow); tempytow = FLOAT_TO_FIXED(v3d->tow); v3d->sow = (FIXED_TO_FLOAT(FixedMul(tempxsow, FINECOSINE(angle)) - FixedMul(tempytow, FINESINE(angle)))); - v3d->tow = (FIXED_TO_FLOAT(-FixedMul(tempxsow, FINESINE(angle)) - FixedMul(tempytow, FINECOSINE(angle)))); + v3d->tow = (FIXED_TO_FLOAT(FixedMul(tempxsow, FINESINE(angle)) + FixedMul(tempytow, FINECOSINE(angle)))); } //v3d->sow = (float)(v3d->sow - flatxref + scrollx); diff --git a/src/p_spec.c b/src/p_spec.c index ddcdfbd53..01518d658 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -5763,10 +5763,8 @@ void P_SpawnSpecials(INT32 fromnetsave) } else // Otherwise, set calculated offsets such that line's v1 is the apparent origin { - fixed_t cosinecomponent = FINECOSINE(flatangle>>ANGLETOFINESHIFT); - fixed_t sinecomponent = FINESINE(flatangle>>ANGLETOFINESHIFT); - xoffs = (-FixedMul(lines[i].v1->x, cosinecomponent) % MAXFLATSIZE) + (FixedMul(lines[i].v1->y, sinecomponent) % MAXFLATSIZE); // No danger of overflow thanks to the strategically placed modulo operations. - yoffs = (FixedMul(lines[i].v1->x, sinecomponent) % MAXFLATSIZE) + (FixedMul(lines[i].v1->y, cosinecomponent) % MAXFLATSIZE); // Ditto. + xoffs = -lines[i].v1->x; + yoffs = -lines[i].v1->y; } for (s = -1; (s = P_FindSectorFromLineTag(lines + i, s)) >= 0 ;) diff --git a/src/r_plane.c b/src/r_plane.c index 11dd79d41..e882fa48c 100644 --- a/src/r_plane.c +++ b/src/r_plane.c @@ -448,9 +448,12 @@ visplane_t *R_FindPlane(fixed_t height, INT32 picnum, INT32 lightlevel, if (plangle != 0) { // Add the view offset, rotated by the plane angle. - angle_t angle = plangle>>ANGLETOFINESHIFT; - xoff += FixedMul(viewx,FINECOSINE(angle))-FixedMul(viewy,FINESINE(angle)); - yoff += -FixedMul(viewx,FINESINE(angle))-FixedMul(viewy,FINECOSINE(angle)); + fixed_t cosinecomponent = FINECOSINE(plangle>>ANGLETOFINESHIFT); + fixed_t sinecomponent = FINESINE(plangle>>ANGLETOFINESHIFT); + fixed_t interxoff = xoff + viewx; + fixed_t interyoff = yoff + viewy; + xoff = FixedMul(interxoff,cosinecomponent)-FixedMul(interyoff,sinecomponent); + yoff = -FixedMul(interxoff,sinecomponent)-FixedMul(interyoff,cosinecomponent); } else { From b924a7d902c65990c2f480880acb306292ec53eb Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Thu, 30 Mar 2017 21:57:36 +0100 Subject: [PATCH 02/12] Interesting consideration: flat angle wasn't used to determine seperate visplanes. This is obviously incorrect behaviour. Enabling this restriction makes flat alignment on slopes ALMOST work identically to normal, but not quite. Also, made the fudge a const, since it may as well be one. --- src/r_plane.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/r_plane.c b/src/r_plane.c index e882fa48c..534e78c26 100644 --- a/src/r_plane.c +++ b/src/r_plane.c @@ -486,6 +486,7 @@ visplane_t *R_FindPlane(fixed_t height, INT32 picnum, INT32 lightlevel, && !pfloor && !check->ffloor && check->viewx == viewx && check->viewy == viewy && check->viewz == viewz && check->viewangle == viewangle + && check->plangle == plangle #ifdef ESLOPE && check->slope == slope #endif @@ -954,10 +955,11 @@ void R_DrawSinglePlane(visplane_t *pl) floatv3_t p, m, n; float ang; float vx, vy, vz; - float fudge; // compiler complains when P_GetZAt is used in FLOAT_TO_FIXED directly // use this as a temp var to store P_GetZAt's return value each time fixed_t temp; + // Okay, look, don't ask me why this works, but without this setup there's a disgusting-looking misalignment with the textures. -Red + const float fudge = ((1<slope->o.x + (1 << (31-nflatshiftup))) & ~((1 << (32-nflatshiftup))-1); yoffs += (pl->slope->o.y + (1 << (31-nflatshiftup))) & ~((1 << (32-nflatshiftup))-1); - // Okay, look, don't ask me why this works, but without this setup there's a disgusting-looking misalignment with the textures. -Red - fudge = ((1< Date: Thu, 30 Mar 2017 21:57:36 +0100 Subject: [PATCH 03/12] Minor refactor. --- src/r_plane.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/r_plane.c b/src/r_plane.c index 534e78c26..8d24c2f7d 100644 --- a/src/r_plane.c +++ b/src/r_plane.c @@ -445,20 +445,18 @@ visplane_t *R_FindPlane(fixed_t height, INT32 picnum, INT32 lightlevel, #ifdef ESLOPE if (slope); else // Don't mess with this right now if a slope is involved #endif - if (plangle != 0) - { - // Add the view offset, rotated by the plane angle. - fixed_t cosinecomponent = FINECOSINE(plangle>>ANGLETOFINESHIFT); - fixed_t sinecomponent = FINESINE(plangle>>ANGLETOFINESHIFT); - fixed_t interxoff = xoff + viewx; - fixed_t interyoff = yoff + viewy; - xoff = FixedMul(interxoff,cosinecomponent)-FixedMul(interyoff,sinecomponent); - yoff = -FixedMul(interxoff,sinecomponent)-FixedMul(interyoff,cosinecomponent); - } - else { xoff += viewx; yoff -= viewy; + if (plangle != 0) + { + // 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); + } } // This appears to fix the Nimbus Ruins sky bug. From d5ba29eb9b4b0d9879f224f2f887e112e2701696 Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Thu, 30 Mar 2017 21:57:36 +0100 Subject: [PATCH 04/12] Get plane scrolling effects working the same on and off slopes in both renderers again. --- src/hardware/hw_main.c | 2 +- src/p_spec.c | 4 ++-- src/r_plane.c | 2 ++ 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 67eb5d41a..25d1a93b1 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -687,7 +687,7 @@ static void HWR_RenderPlane(sector_t *sector, extrasubsector_t *xsub, boolean is { // Hurdler: add scrolling texture on floor/ceiling v3d->sow = (float)((pv->x / fflatsize) - flatxref + scrollx); - v3d->tow = (float)(-(pv->y / fflatsize) + flatyref - scrolly); + v3d->tow = (float)(-(pv->y / fflatsize) + flatyref + scrolly); //v3d->sow = (float)(pv->x / fflatsize); //v3d->tow = (float)(pv->y / fflatsize); diff --git a/src/p_spec.c b/src/p_spec.c index 01518d658..ef74b0ae5 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -5759,12 +5759,12 @@ void P_SpawnSpecials(INT32 fromnetsave) if (lines[i].flags & ML_NOKNUX) // Set offset through x and y texture offsets if NOKNUX flag is set { xoffs = sides[lines[i].sidenum[0]].textureoffset; - yoffs = sides[lines[i].sidenum[0]].rowoffset; + yoffs = -sides[lines[i].sidenum[0]].rowoffset; } else // Otherwise, set calculated offsets such that line's v1 is the apparent origin { xoffs = -lines[i].v1->x; - yoffs = -lines[i].v1->y; + yoffs = lines[i].v1->y; } for (s = -1; (s = P_FindSectorFromLineTag(lines + i, s)) >= 0 ;) diff --git a/src/r_plane.c b/src/r_plane.c index 8d24c2f7d..19bd85ad2 100644 --- a/src/r_plane.c +++ b/src/r_plane.c @@ -959,6 +959,8 @@ void R_DrawSinglePlane(visplane_t *pl) // Okay, look, don't ask me why this works, but without this setup there's a disgusting-looking misalignment with the textures. -Red const float fudge = ((1< Date: Thu, 30 Mar 2017 21:57:36 +0100 Subject: [PATCH 05/12] Woops, need to ensure functional equivalence to what came before. --- src/p_spec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/p_spec.c b/src/p_spec.c index ef74b0ae5..cbea1fb39 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -5759,7 +5759,7 @@ void P_SpawnSpecials(INT32 fromnetsave) if (lines[i].flags & ML_NOKNUX) // Set offset through x and y texture offsets if NOKNUX flag is set { xoffs = sides[lines[i].sidenum[0]].textureoffset; - yoffs = -sides[lines[i].sidenum[0]].rowoffset; + yoffs = sides[lines[i].sidenum[0]].rowoffset; } else // Otherwise, set calculated offsets such that line's v1 is the apparent origin { From 0ff036c2e24e6493d65bfeeae580d14bb00f4e78 Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Thu, 30 Mar 2017 21:57:36 +0100 Subject: [PATCH 06/12] Some progress! http://i.imgur.com/yVPJQpp.png Previously, both were visual garbage. So it's gettin' there. --- src/r_plane.c | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/src/r_plane.c b/src/r_plane.c index 19bd85ad2..08e6e2e4f 100644 --- a/src/r_plane.c +++ b/src/r_plane.c @@ -959,13 +959,42 @@ void R_DrawSinglePlane(visplane_t *pl) // Okay, look, don't ask me why this works, but without this setup there's a disgusting-looking misalignment with the textures. -Red const float fudge = ((1<plangle & (ANGLE_90-1)); + yoffs *= 1; - xoffs &= ((1 << (32-nflatshiftup))-1); - yoffs &= ((1 << (32-nflatshiftup))-1); +#define incorporateorigin(originx, originy) xoffs &= ((1 << (32-nflatshiftup))-1);\ +yoffs &= ((1 << (32-nflatshiftup))-1);\ +xoffs -= (originx + (1 << (31-nflatshiftup))) & ~((1 << (32-nflatshiftup))-1);\ +yoffs += (originy + (1 << (31-nflatshiftup))) & ~((1 << (32-nflatshiftup))-1) - xoffs -= (pl->slope->o.x + (1 << (31-nflatshiftup))) & ~((1 << (32-nflatshiftup))-1); - yoffs += (pl->slope->o.y + (1 << (31-nflatshiftup))) & ~((1 << (32-nflatshiftup))-1); + if (hack != 0) + { + if (hack >= ANGLE_45) + hack = InvAngle(hack); + { + const fixed_t cosinecomponent = FINECOSINE(hack>>ANGLETOFINESHIFT); + const fixed_t sinecomponent = FINESINE(hack>>ANGLETOFINESHIFT); + + const fixed_t ox = FixedMul(pl->slope->o.x,cosinecomponent)+FixedMul(pl->slope->o.y,sinecomponent); + const fixed_t oy = -FixedMul(pl->slope->o.x,sinecomponent)+FixedMul(pl->slope->o.y,cosinecomponent); + + fixed_t oldxoffs = xoffs; + xoffs = FixedMul(xoffs,cosinecomponent)+FixedMul(yoffs,sinecomponent); + yoffs = -FixedMul(oldxoffs,sinecomponent)+FixedMul(yoffs,cosinecomponent); + + incorporateorigin(ox, oy); + + oldxoffs = xoffs; + xoffs = FixedMul(xoffs,cosinecomponent)+FixedMul(yoffs,-sinecomponent); // negative sine for opposite direction + yoffs = -FixedMul(oldxoffs,-sinecomponent)+FixedMul(yoffs,cosinecomponent); // ditto + } + } + else + { + incorporateorigin(pl->slope->o.x, pl->slope->o.y); + } +#undef incorporateorigin xoffs = (fixed_t)(xoffs*fudge); yoffs = (fixed_t)(yoffs/fudge); From ab34bd231bb701cc08001186cbb780a43f5de0fb Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Thu, 30 Mar 2017 21:57:36 +0100 Subject: [PATCH 07/12] No need for oldxoffs. --- src/r_plane.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/r_plane.c b/src/r_plane.c index 08e6e2e4f..0612dd50e 100644 --- a/src/r_plane.c +++ b/src/r_plane.c @@ -979,15 +979,15 @@ yoffs += (originy + (1 << (31-nflatshiftup))) & ~((1 << (32-nflatshiftup))-1) const fixed_t ox = FixedMul(pl->slope->o.x,cosinecomponent)+FixedMul(pl->slope->o.y,sinecomponent); const fixed_t oy = -FixedMul(pl->slope->o.x,sinecomponent)+FixedMul(pl->slope->o.y,cosinecomponent); - fixed_t oldxoffs = xoffs; + temp = xoffs; xoffs = FixedMul(xoffs,cosinecomponent)+FixedMul(yoffs,sinecomponent); - yoffs = -FixedMul(oldxoffs,sinecomponent)+FixedMul(yoffs,cosinecomponent); + yoffs = -FixedMul(temp,sinecomponent)+FixedMul(yoffs,cosinecomponent); incorporateorigin(ox, oy); - oldxoffs = xoffs; + temp = xoffs; xoffs = FixedMul(xoffs,cosinecomponent)+FixedMul(yoffs,-sinecomponent); // negative sine for opposite direction - yoffs = -FixedMul(oldxoffs,-sinecomponent)+FixedMul(yoffs,cosinecomponent); // ditto + yoffs = -FixedMul(temp,-sinecomponent)+FixedMul(yoffs,cosinecomponent); // ditto } } else From 54e0a0c17da0331a2e3981783da60766d6480611 Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Sun, 9 Apr 2017 15:22:42 +0100 Subject: [PATCH 08/12] Reeeeeeeeeeeeeed fix ur slops Recreated my previous code using floats in case the issue was overflowing that could be mitigated using floating point precision - but still doesn't work. Pulling my hair out. --- src/r_plane.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/r_plane.c b/src/r_plane.c index 0612dd50e..8a9c08370 100644 --- a/src/r_plane.c +++ b/src/r_plane.c @@ -963,6 +963,8 @@ void R_DrawSinglePlane(visplane_t *pl) yoffs *= 1; +#define ANG2RAD(angle) ((float)((angle)*M_PI)/ANGLE_180) + #define incorporateorigin(originx, originy) xoffs &= ((1 << (32-nflatshiftup))-1);\ yoffs &= ((1 << (32-nflatshiftup))-1);\ xoffs -= (originx + (1 << (31-nflatshiftup))) & ~((1 << (32-nflatshiftup))-1);\ @@ -970,6 +972,37 @@ yoffs += (originy + (1 << (31-nflatshiftup))) & ~((1 << (32-nflatshiftup))-1) if (hack != 0) { + /*ang = ANG2RAD(hack); + { + double mod, oxf, oyf, tempf, xoffsf, yoffsf; + + mod = FIXED_TO_FLOAT((1 << (32-nflatshiftup))); + + tempf = FIXED_TO_FLOAT(pl->slope->o.x); + oyf = FIXED_TO_FLOAT(pl->slope->o.y); + oxf = tempf * cos(ang) + oyf * sin(ang) + mod/2; + oyf = -(tempf * sin(ang)) + oyf * cos(ang) + mod/2; + + oxf -= fmod(oxf, mod); + oyf -= fmod(oyf, mod); + + tempf = FIXED_TO_FLOAT(xoffs); + yoffsf = FIXED_TO_FLOAT(yoffs); + xoffsf = tempf * cos(ang) + yoffsf * sin(ang); + yoffsf = -(tempf * sin(ang)) + yoffsf * cos(ang); + + xoffsf = fmod(xoffsf, mod); + yoffsf = fmod(yoffsf, mod); + + xoffsf -= oxf; + yoffsf += oyf; + + oxf = xoffsf * cos(ang) - yoffsf * sin(ang); + oyf = xoffsf * sin(ang) + yoffsf * cos(ang); + + xoffs = FLOAT_TO_FIXED(oxf); + yoffs = FLOAT_TO_FIXED(oyf); + }*/ if (hack >= ANGLE_45) hack = InvAngle(hack); { @@ -1006,8 +1039,6 @@ yoffs += (originy + (1 << (31-nflatshiftup))) & ~((1 << (32-nflatshiftup))-1) temp = P_GetZAt(pl->slope, pl->viewx, pl->viewy); zeroheight = FIXED_TO_FLOAT(temp); -#define ANG2RAD(angle) ((float)((angle)*M_PI)/ANGLE_180) - // p is the texture origin in view space // Don't add in the offsets at this stage, because doing so can result in // errors if the flat is rotated. From 8ee8bd532bab83de1ea6f4e703517ddaab8bd135 Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Mon, 10 Apr 2017 10:51:52 +0100 Subject: [PATCH 09/12] Got it rendering slopes far away from the origin properly at the expense of having weird offsets near it. Still experimenting, but closer than ever before. --- src/r_plane.c | 77 ++++++++++++++++----------------------------------- 1 file changed, 24 insertions(+), 53 deletions(-) diff --git a/src/r_plane.c b/src/r_plane.c index 8a9c08370..ae4e5369c 100644 --- a/src/r_plane.c +++ b/src/r_plane.c @@ -963,71 +963,40 @@ void R_DrawSinglePlane(visplane_t *pl) yoffs *= 1; -#define ANG2RAD(angle) ((float)((angle)*M_PI)/ANGLE_180) - -#define incorporateorigin(originx, originy) xoffs &= ((1 << (32-nflatshiftup))-1);\ -yoffs &= ((1 << (32-nflatshiftup))-1);\ -xoffs -= (originx + (1 << (31-nflatshiftup))) & ~((1 << (32-nflatshiftup))-1);\ -yoffs += (originy + (1 << (31-nflatshiftup))) & ~((1 << (32-nflatshiftup))-1) - if (hack != 0) { - /*ang = ANG2RAD(hack); - { - double mod, oxf, oyf, tempf, xoffsf, yoffsf; + const fixed_t cosinecomponent = FINECOSINE(hack>>ANGLETOFINESHIFT); + const fixed_t sinecomponent = FINESINE(hack>>ANGLETOFINESHIFT); - mod = FIXED_TO_FLOAT((1 << (32-nflatshiftup))); + const fixed_t mod = ((1 << (32-nflatshiftup)) - 1); - tempf = FIXED_TO_FLOAT(pl->slope->o.x); - oyf = FIXED_TO_FLOAT(pl->slope->o.y); - oxf = tempf * cos(ang) + oyf * sin(ang) + mod/2; - oyf = -(tempf * sin(ang)) + oyf * cos(ang) + mod/2; + fixed_t ox = (FixedMul(pl->slope->o.x,cosinecomponent) & mod) + (FixedMul(pl->slope->o.y,sinecomponent) & mod) + (1 << (31-nflatshiftup)); + fixed_t oy = (-FixedMul(pl->slope->o.x,sinecomponent) & mod) + (FixedMul(pl->slope->o.y,cosinecomponent) & mod) + (1 << (31-nflatshiftup)); - oxf -= fmod(oxf, mod); - oyf -= fmod(oyf, mod); + temp = ox & mod; + oy &= mod; + ox = FixedMul(temp,cosinecomponent)+FixedMul(oy,-sinecomponent); // negative sine for opposite direction + oy = -FixedMul(temp,-sinecomponent)+FixedMul(oy,cosinecomponent); - tempf = FIXED_TO_FLOAT(xoffs); - yoffsf = FIXED_TO_FLOAT(yoffs); - xoffsf = tempf * cos(ang) + yoffsf * sin(ang); - yoffsf = -(tempf * sin(ang)) + yoffsf * cos(ang); + temp = xoffs; + xoffs = (FixedMul(xoffs,cosinecomponent) & mod) + (FixedMul(yoffs,sinecomponent) & mod); + yoffs = (-FixedMul(temp,sinecomponent) & mod) + (FixedMul(yoffs,cosinecomponent) & mod); - xoffsf = fmod(xoffsf, mod); - yoffsf = fmod(yoffsf, mod); + temp = xoffs & mod; + yoffs &= mod; + xoffs = FixedMul(temp,cosinecomponent)+FixedMul(yoffs,-sinecomponent); // ditto + yoffs = -FixedMul(temp,-sinecomponent)+FixedMul(yoffs,cosinecomponent); - xoffsf -= oxf; - yoffsf += oyf; - - oxf = xoffsf * cos(ang) - yoffsf * sin(ang); - oyf = xoffsf * sin(ang) + yoffsf * cos(ang); - - xoffs = FLOAT_TO_FIXED(oxf); - yoffs = FLOAT_TO_FIXED(oyf); - }*/ - if (hack >= ANGLE_45) - hack = InvAngle(hack); - { - const fixed_t cosinecomponent = FINECOSINE(hack>>ANGLETOFINESHIFT); - const fixed_t sinecomponent = FINESINE(hack>>ANGLETOFINESHIFT); - - const fixed_t ox = FixedMul(pl->slope->o.x,cosinecomponent)+FixedMul(pl->slope->o.y,sinecomponent); - const fixed_t oy = -FixedMul(pl->slope->o.x,sinecomponent)+FixedMul(pl->slope->o.y,cosinecomponent); - - temp = xoffs; - xoffs = FixedMul(xoffs,cosinecomponent)+FixedMul(yoffs,sinecomponent); - yoffs = -FixedMul(temp,sinecomponent)+FixedMul(yoffs,cosinecomponent); - - incorporateorigin(ox, oy); - - temp = xoffs; - xoffs = FixedMul(xoffs,cosinecomponent)+FixedMul(yoffs,-sinecomponent); // negative sine for opposite direction - yoffs = -FixedMul(temp,-sinecomponent)+FixedMul(yoffs,cosinecomponent); // ditto - } + xoffs -= (pl->slope->o.x - ox); + yoffs += (pl->slope->o.y - oy); } else { - incorporateorigin(pl->slope->o.x, pl->slope->o.y); + xoffs &= ((1 << (32-nflatshiftup))-1); + yoffs &= ((1 << (32-nflatshiftup))-1); + xoffs -= (pl->slope->o.x + (1 << (31-nflatshiftup))) & ~((1 << (32-nflatshiftup))-1); + yoffs += (pl->slope->o.y + (1 << (31-nflatshiftup))) & ~((1 << (32-nflatshiftup))-1); } -#undef incorporateorigin xoffs = (fixed_t)(xoffs*fudge); yoffs = (fixed_t)(yoffs/fudge); @@ -1039,6 +1008,8 @@ yoffs += (originy + (1 << (31-nflatshiftup))) & ~((1 << (32-nflatshiftup))-1) temp = P_GetZAt(pl->slope, pl->viewx, pl->viewy); zeroheight = FIXED_TO_FLOAT(temp); +#define ANG2RAD(angle) ((float)((angle)*M_PI)/ANGLE_180) + // p is the texture origin in view space // Don't add in the offsets at this stage, because doing so can result in // errors if the flat is rotated. From e333dd62f021d2311735ee1d53d02f6f4050bb5a Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Mon, 10 Apr 2017 11:34:56 +0100 Subject: [PATCH 10/12] I did it!!!!!!!!!!!!!!!!!!!!!! --- src/r_plane.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/r_plane.c b/src/r_plane.c index ae4e5369c..209d29495 100644 --- a/src/r_plane.c +++ b/src/r_plane.c @@ -963,32 +963,32 @@ void R_DrawSinglePlane(visplane_t *pl) yoffs *= 1; - if (hack != 0) + if (hack) { const fixed_t cosinecomponent = FINECOSINE(hack>>ANGLETOFINESHIFT); const fixed_t sinecomponent = FINESINE(hack>>ANGLETOFINESHIFT); - const fixed_t mod = ((1 << (32-nflatshiftup)) - 1); + const fixed_t modmask = ((1 << (32-nflatshiftup)) - 1); - fixed_t ox = (FixedMul(pl->slope->o.x,cosinecomponent) & mod) + (FixedMul(pl->slope->o.y,sinecomponent) & mod) + (1 << (31-nflatshiftup)); - fixed_t oy = (-FixedMul(pl->slope->o.x,sinecomponent) & mod) + (FixedMul(pl->slope->o.y,cosinecomponent) & mod) + (1 << (31-nflatshiftup)); + fixed_t ox = (FixedMul(pl->slope->o.x,cosinecomponent) & modmask) - (FixedMul(pl->slope->o.y,sinecomponent) & modmask); + fixed_t oy = (-FixedMul(pl->slope->o.x,sinecomponent) & modmask) - (FixedMul(pl->slope->o.y,cosinecomponent) & modmask); - temp = ox & mod; - oy &= mod; + temp = ox & modmask; + oy &= modmask; ox = FixedMul(temp,cosinecomponent)+FixedMul(oy,-sinecomponent); // negative sine for opposite direction oy = -FixedMul(temp,-sinecomponent)+FixedMul(oy,cosinecomponent); temp = xoffs; - xoffs = (FixedMul(xoffs,cosinecomponent) & mod) + (FixedMul(yoffs,sinecomponent) & mod); - yoffs = (-FixedMul(temp,sinecomponent) & mod) + (FixedMul(yoffs,cosinecomponent) & mod); + xoffs = (FixedMul(temp,cosinecomponent) & modmask) + (FixedMul(yoffs,sinecomponent) & modmask); + yoffs = (-FixedMul(temp,sinecomponent) & modmask) + (FixedMul(yoffs,cosinecomponent) & modmask); - temp = xoffs & mod; - yoffs &= mod; + temp = xoffs & modmask; + yoffs &= modmask; xoffs = FixedMul(temp,cosinecomponent)+FixedMul(yoffs,-sinecomponent); // ditto yoffs = -FixedMul(temp,-sinecomponent)+FixedMul(yoffs,cosinecomponent); xoffs -= (pl->slope->o.x - ox); - yoffs += (pl->slope->o.y - oy); + yoffs += (pl->slope->o.y + oy); } else { From 48ed7835d733044917a73e3bd2c6d90ca9ea067b Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Mon, 10 Apr 2017 11:41:26 +0100 Subject: [PATCH 11/12] Add a helpful comment in order to make people who look at this in future suffer less. --- src/r_plane.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/r_plane.c b/src/r_plane.c index 209d29495..cf7b679bb 100644 --- a/src/r_plane.c +++ b/src/r_plane.c @@ -965,6 +965,13 @@ void R_DrawSinglePlane(visplane_t *pl) if (hack) { + /* + Essentially: We can't & the components along the regular axes when the plane is rotated. + This is because the distance on each regular axis in order to loop is different. + We rotate them, & the components, add them together, & them again, and then rotate them back. + These three seperate & operations are done per axis in order to prevent overflows. + toast 10/04/17 + */ const fixed_t cosinecomponent = FINECOSINE(hack>>ANGLETOFINESHIFT); const fixed_t sinecomponent = FINESINE(hack>>ANGLETOFINESHIFT); From db4002cd7f255fdca6467f2cfb2f816a81d36bed Mon Sep 17 00:00:00 2001 From: toasterbabe Date: Mon, 10 Apr 2017 11:49:14 +0100 Subject: [PATCH 12/12] Remove now-unused code. --- src/hardware/hw_main.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 25d1a93b1..58c60af70 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -669,12 +669,6 @@ static void HWR_RenderPlane(sector_t *sector, extrasubsector_t *xsub, boolean is if (angle) // Only needs to be done if there's an altered angle { angle = InvAngle(angle)>>ANGLETOFINESHIFT; - // This needs to be done so that it scrolls in a different direction after rotation like software - /*tempxsow = FLOAT_TO_FIXED(scrollx); - tempytow = FLOAT_TO_FIXED(scrolly); - scrollx = (FIXED_TO_FLOAT(FixedMul(tempxsow, FINECOSINE(angle)) - FixedMul(tempytow, FINESINE(angle)))); - scrolly = (FIXED_TO_FLOAT(FixedMul(tempxsow, FINESINE(angle)) + FixedMul(tempytow, FINECOSINE(angle))));*/ - // This needs to be done so everything aligns after rotation // It would be done so that rotation is done, THEN the translation, but I couldn't get it to rotate AND scroll like software does tempxsow = FLOAT_TO_FIXED(flatxref);