Merge branch 'fix-sw-polyobject-interpolation' into 'next'

Interpolate polyobjects properly for the software renderer (resolves #950)

Closes #950

See merge request STJr/SRB2!2284
This commit is contained in:
Lactozilla 2024-02-02 00:08:06 +00:00
commit 235bf724f0
2 changed files with 18 additions and 0 deletions

View file

@ -482,6 +482,7 @@ void R_CreateInterpolator_Polyobj(thinker_t *thinker, polyobj_t *polyobj)
interp->polyobj.oldcx = interp->polyobj.bakcx = polyobj->centerPt.x; interp->polyobj.oldcx = interp->polyobj.bakcx = polyobj->centerPt.x;
interp->polyobj.oldcy = interp->polyobj.bakcy = polyobj->centerPt.y; interp->polyobj.oldcy = interp->polyobj.bakcy = polyobj->centerPt.y;
interp->polyobj.oldangle = interp->polyobj.bakangle = polyobj->angle;
} }
void R_CreateInterpolator_DynSlope(thinker_t *thinker, pslope_t *slope) void R_CreateInterpolator_DynSlope(thinker_t *thinker, pslope_t *slope)
@ -505,6 +506,15 @@ void R_InitializeLevelInterpolators(void)
levelinterpolators = NULL; levelinterpolators = NULL;
} }
static void RecalculatePolyobjectSegAngles(polyobj_t *polyobj)
{
for (size_t i = 0; i < polyobj->segCount; i++)
{
seg_t *seg = polyobj->segs[i];
seg->angle = R_PointToAngle2(seg->v1->x, seg->v1->y, seg->v2->x, seg->v2->y);
}
}
static void UpdateLevelInterpolatorState(levelinterpolator_t *interp) static void UpdateLevelInterpolatorState(levelinterpolator_t *interp)
{ {
size_t i; size_t i;
@ -535,10 +545,13 @@ static void UpdateLevelInterpolatorState(levelinterpolator_t *interp)
interp->polyobj.bakvertices[i * 2 ] = interp->polyobj.polyobj->vertices[i]->x; interp->polyobj.bakvertices[i * 2 ] = interp->polyobj.polyobj->vertices[i]->x;
interp->polyobj.bakvertices[i * 2 + 1] = interp->polyobj.polyobj->vertices[i]->y; interp->polyobj.bakvertices[i * 2 + 1] = interp->polyobj.polyobj->vertices[i]->y;
} }
RecalculatePolyobjectSegAngles(interp->polyobj.polyobj);
interp->polyobj.oldcx = interp->polyobj.bakcx; interp->polyobj.oldcx = interp->polyobj.bakcx;
interp->polyobj.oldcy = interp->polyobj.bakcy; interp->polyobj.oldcy = interp->polyobj.bakcy;
interp->polyobj.oldangle = interp->polyobj.bakangle;
interp->polyobj.bakcx = interp->polyobj.polyobj->centerPt.x; interp->polyobj.bakcx = interp->polyobj.polyobj->centerPt.x;
interp->polyobj.bakcy = interp->polyobj.polyobj->centerPt.y; interp->polyobj.bakcy = interp->polyobj.polyobj->centerPt.y;
interp->polyobj.bakangle = interp->polyobj.polyobj->angle;
break; break;
case LVLINTERP_DynSlope: case LVLINTERP_DynSlope:
FV3_Copy(&interp->dynslope.oldo, &interp->dynslope.bako); FV3_Copy(&interp->dynslope.oldo, &interp->dynslope.bako);
@ -624,8 +637,10 @@ void R_ApplyLevelInterpolators(fixed_t frac)
interp->polyobj.polyobj->vertices[ii]->x = R_LerpFixed(interp->polyobj.oldvertices[ii * 2 ], interp->polyobj.bakvertices[ii * 2 ], frac); interp->polyobj.polyobj->vertices[ii]->x = R_LerpFixed(interp->polyobj.oldvertices[ii * 2 ], interp->polyobj.bakvertices[ii * 2 ], frac);
interp->polyobj.polyobj->vertices[ii]->y = R_LerpFixed(interp->polyobj.oldvertices[ii * 2 + 1], interp->polyobj.bakvertices[ii * 2 + 1], frac); interp->polyobj.polyobj->vertices[ii]->y = R_LerpFixed(interp->polyobj.oldvertices[ii * 2 + 1], interp->polyobj.bakvertices[ii * 2 + 1], frac);
} }
RecalculatePolyobjectSegAngles(interp->polyobj.polyobj);
interp->polyobj.polyobj->centerPt.x = R_LerpFixed(interp->polyobj.oldcx, interp->polyobj.bakcx, frac); interp->polyobj.polyobj->centerPt.x = R_LerpFixed(interp->polyobj.oldcx, interp->polyobj.bakcx, frac);
interp->polyobj.polyobj->centerPt.y = R_LerpFixed(interp->polyobj.oldcy, interp->polyobj.bakcy, frac); interp->polyobj.polyobj->centerPt.y = R_LerpFixed(interp->polyobj.oldcy, interp->polyobj.bakcy, frac);
interp->polyobj.polyobj->angle = R_LerpAngle(interp->polyobj.oldangle, interp->polyobj.bakangle, frac);
break; break;
case LVLINTERP_DynSlope: case LVLINTERP_DynSlope:
R_LerpVector3(&interp->dynslope.oldo, &interp->dynslope.bako, frac, &interp->dynslope.slope->o); R_LerpVector3(&interp->dynslope.oldo, &interp->dynslope.bako, frac, &interp->dynslope.slope->o);
@ -679,8 +694,10 @@ void R_RestoreLevelInterpolators(void)
interp->polyobj.polyobj->vertices[ii]->x = interp->polyobj.bakvertices[ii * 2 ]; interp->polyobj.polyobj->vertices[ii]->x = interp->polyobj.bakvertices[ii * 2 ];
interp->polyobj.polyobj->vertices[ii]->y = interp->polyobj.bakvertices[ii * 2 + 1]; interp->polyobj.polyobj->vertices[ii]->y = interp->polyobj.bakvertices[ii * 2 + 1];
} }
RecalculatePolyobjectSegAngles(interp->polyobj.polyobj);
interp->polyobj.polyobj->centerPt.x = interp->polyobj.bakcx; interp->polyobj.polyobj->centerPt.x = interp->polyobj.bakcx;
interp->polyobj.polyobj->centerPt.y = interp->polyobj.bakcy; interp->polyobj.polyobj->centerPt.y = interp->polyobj.bakcy;
interp->polyobj.polyobj->angle = interp->polyobj.bakangle;
break; break;
case LVLINTERP_DynSlope: case LVLINTERP_DynSlope:
FV3_Copy(&interp->dynslope.slope->o, &interp->dynslope.bako); FV3_Copy(&interp->dynslope.slope->o, &interp->dynslope.bako);

View file

@ -108,6 +108,7 @@ typedef struct levelinterpolator_s {
fixed_t *bakvertices; fixed_t *bakvertices;
size_t vertices_size; size_t vertices_size;
fixed_t oldcx, oldcy, bakcx, bakcy; fixed_t oldcx, oldcy, bakcx, bakcy;
angle_t oldangle, bakangle;
} polyobj; } polyobj;
struct { struct {
pslope_t *slope; pslope_t *slope;