mirror of
https://git.do.srb2.org/STJr/SRB2.git
synced 2025-02-16 09:02:06 +00:00
Interpolate radius/height when scaling mobjs
This commit is contained in:
parent
6c416c61b1
commit
f42c2403f9
5 changed files with 58 additions and 52 deletions
|
@ -3595,7 +3595,7 @@ static void HWR_DrawDropShadow(mobj_t *thing, fixed_t scale)
|
|||
return;
|
||||
}
|
||||
|
||||
floordiff = abs((flip < 0 ? thing->height : 0) + interp.z - groundz);
|
||||
floordiff = abs((flip < 0 ? interp.height : 0) + interp.z - groundz);
|
||||
|
||||
alpha = floordiff / (4*FRACUNIT) + 75;
|
||||
if (alpha >= 255) return;
|
||||
|
@ -3606,9 +3606,7 @@ static void HWR_DrawDropShadow(mobj_t *thing, fixed_t scale)
|
|||
HWR_GetPatch(gpatch);
|
||||
|
||||
scalemul = FixedMul(FRACUNIT - floordiff/640, scale);
|
||||
scalemul = FixedMul(scalemul, (thing->radius*2) / gpatch->height);
|
||||
if ((thing->scale != thing->old_scale) && (thing->scale >= FRACUNIT/1024)) // Interpolate shadows when scaling mobjs
|
||||
scalemul = FixedMul(scalemul, FixedDiv(interp.scale, thing->scale));
|
||||
scalemul = FixedMul(scalemul, (interp.radius*2) / gpatch->height);
|
||||
|
||||
fscale = FIXED_TO_FLOAT(scalemul);
|
||||
fx = FIXED_TO_FLOAT(interp.x);
|
||||
|
@ -3720,7 +3718,7 @@ static void HWR_RotateSpritePolyToAim(gl_vissprite_t *spr, FOutVector *wallVerts
|
|||
|
||||
if (P_MobjFlip(spr->mobj) == -1)
|
||||
{
|
||||
basey = FIXED_TO_FLOAT(interp.z + spr->mobj->height);
|
||||
basey = FIXED_TO_FLOAT(interp.z + interp.height);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -5326,7 +5324,7 @@ static void HWR_ProjectSprite(mobj_t *thing)
|
|||
}
|
||||
|
||||
groundz = R_GetShadowZ(thing, NULL);
|
||||
floordiff = abs(((thing->eflags & MFE_VERTICALFLIP) ? caster->height : 0) + casterinterp.z - groundz);
|
||||
floordiff = abs(((thing->eflags & MFE_VERTICALFLIP) ? casterinterp.height : 0) + casterinterp.z - groundz);
|
||||
|
||||
shadowheight = FIXED_TO_FLOAT(floordiff);
|
||||
shadowscale = FIXED_TO_FLOAT(FixedMul(FRACUNIT - floordiff/640, casterinterp.scale));
|
||||
|
@ -5378,10 +5376,7 @@ static void HWR_ProjectSprite(mobj_t *thing)
|
|||
|
||||
if (vflip)
|
||||
{
|
||||
if (thing->scale != thing->old_scale) // Interpolate heights in reverse gravity when scaling mobjs
|
||||
gz = FIXED_TO_FLOAT(interp.z + FixedMul(thing->height, FixedDiv(interp.scale, thing->scale))) - (FIXED_TO_FLOAT(spr_topoffset) * this_yscale);
|
||||
else
|
||||
gz = FIXED_TO_FLOAT(interp.z + thing->height) - (FIXED_TO_FLOAT(spr_topoffset) * this_yscale);
|
||||
gz = FIXED_TO_FLOAT(interp.z + interp.height) - (FIXED_TO_FLOAT(spr_topoffset) * this_yscale);
|
||||
gzt = gz + (FIXED_TO_FLOAT(spr_height) * this_yscale);
|
||||
}
|
||||
else
|
||||
|
@ -5687,7 +5682,6 @@ static void HWR_ProjectBoundingBox(mobj_t *thing)
|
|||
gl_vissprite_t *vis;
|
||||
float tr_x, tr_y;
|
||||
float tz;
|
||||
float rad;
|
||||
|
||||
if (!thing)
|
||||
return;
|
||||
|
@ -5722,15 +5716,13 @@ static void HWR_ProjectBoundingBox(mobj_t *thing)
|
|||
tr_x += gl_viewx;
|
||||
tr_y += gl_viewy;
|
||||
|
||||
rad = FIXED_TO_FLOAT(thing->radius);
|
||||
|
||||
vis = HWR_NewVisSprite();
|
||||
vis->x1 = tr_x - rad;
|
||||
vis->x2 = tr_x + rad;
|
||||
vis->z1 = tr_y - rad;
|
||||
vis->z2 = tr_y + rad;
|
||||
vis->x1 = tr_x - FIXED_TO_FLOAT(interp.radius);
|
||||
vis->x2 = tr_x + FIXED_TO_FLOAT(interp.radius);
|
||||
vis->z1 = tr_y - FIXED_TO_FLOAT(interp.radius);
|
||||
vis->z2 = tr_y + FIXED_TO_FLOAT(interp.radius);
|
||||
vis->gz = FIXED_TO_FLOAT(interp.z);
|
||||
vis->gzt = vis->gz + FIXED_TO_FLOAT(thing->height);
|
||||
vis->gzt = vis->gz + FIXED_TO_FLOAT(interp.height);
|
||||
vis->mobj = thing;
|
||||
|
||||
vis->precip = false;
|
||||
|
|
|
@ -1585,12 +1585,7 @@ boolean HWR_DrawModel(gl_vissprite_t *spr)
|
|||
p.y = FIXED_TO_FLOAT(interp.y)+md2->offset;
|
||||
|
||||
if (flip)
|
||||
{
|
||||
if (spr->mobj->scale != spr->mobj->old_scale) // Interpolate heights in reverse gravity when scaling mobjs
|
||||
p.z = FIXED_TO_FLOAT(interp.z + FixedMul(spr->mobj->height, FixedDiv(interp.scale, spr->mobj->scale)));
|
||||
else
|
||||
p.z = FIXED_TO_FLOAT(interp.z + spr->mobj->height);
|
||||
}
|
||||
p.z = FIXED_TO_FLOAT(interp.z + interp.height);
|
||||
else
|
||||
p.z = FIXED_TO_FLOAT(interp.z);
|
||||
|
||||
|
@ -1626,8 +1621,8 @@ boolean HWR_DrawModel(gl_vissprite_t *spr)
|
|||
p.roll = true;
|
||||
|
||||
// rotation pivot
|
||||
p.centerx = FIXED_TO_FLOAT(spr->mobj->radius / 2);
|
||||
p.centery = FIXED_TO_FLOAT(spr->mobj->height / 2);
|
||||
p.centerx = FIXED_TO_FLOAT(interp.radius / 2);
|
||||
p.centery = FIXED_TO_FLOAT(interp.height / 2);
|
||||
|
||||
// rotation axes relative to camera
|
||||
p.rollx = FIXED_TO_FLOAT(FINECOSINE(FixedAngle(camAngleDiff) >> ANGLETOFINESHIFT));
|
||||
|
|
20
src/r_fps.c
20
src/r_fps.c
|
@ -292,6 +292,8 @@ void R_InterpolateMobjState(mobj_t *mobj, fixed_t frac, interpmobjstate_t *out)
|
|||
out->y = mobj->y;
|
||||
out->z = mobj->z;
|
||||
out->scale = mobj->scale;
|
||||
out->radius = mobj->radius;
|
||||
out->height = mobj->height;
|
||||
out->subsector = mobj->subsector;
|
||||
out->angle = mobj->player ? mobj->player->drawangle : mobj->angle;
|
||||
out->pitch = mobj->pitch;
|
||||
|
@ -307,10 +309,22 @@ void R_InterpolateMobjState(mobj_t *mobj, fixed_t frac, interpmobjstate_t *out)
|
|||
out->x = R_LerpFixed(mobj->old_x, mobj->x, frac);
|
||||
out->y = R_LerpFixed(mobj->old_y, mobj->y, frac);
|
||||
out->z = R_LerpFixed(mobj->old_z, mobj->z, frac);
|
||||
out->scale = mobj->resetinterp ? mobj->scale : R_LerpFixed(mobj->old_scale, mobj->scale, frac);
|
||||
out->spritexscale = mobj->resetinterp ? mobj->spritexscale : R_LerpFixed(mobj->old_spritexscale, mobj->spritexscale, frac);
|
||||
out->spriteyscale = mobj->resetinterp ? mobj->spriteyscale : R_LerpFixed(mobj->old_spriteyscale, mobj->spriteyscale, frac);
|
||||
|
||||
if (mobj->scale == mobj->old_scale) // Tiny optimisation - scale is usually unchanging, so let's skip a lerp, two FixedMuls, and two FixedDivs
|
||||
{
|
||||
out->scale = mobj->scale;
|
||||
out->radius = mobj->radius;
|
||||
out->height = mobj->height;
|
||||
}
|
||||
else
|
||||
{
|
||||
out->scale = R_LerpFixed(mobj->old_scale, mobj->scale, frac);
|
||||
out->radius = FixedMul(mobj->radius, FixedDiv(out->scale, mobj->scale));
|
||||
out->height = FixedMul(mobj->height, FixedDiv(out->scale, mobj->scale));
|
||||
}
|
||||
|
||||
// Sprite offsets are not interpolated until we have a way to interpolate them explicitly in Lua.
|
||||
// It seems existing mods visually break more often than not if it is interpolated.
|
||||
out->spritexoffset = mobj->spritexoffset;
|
||||
|
@ -340,6 +354,8 @@ void R_InterpolatePrecipMobjState(precipmobj_t *mobj, fixed_t frac, interpmobjst
|
|||
out->y = mobj->y;
|
||||
out->z = mobj->z;
|
||||
out->scale = FRACUNIT;
|
||||
out->radius = mobj->radius;
|
||||
out->height = mobj->height;
|
||||
out->subsector = mobj->subsector;
|
||||
out->angle = mobj->angle;
|
||||
out->pitch = mobj->angle;
|
||||
|
@ -356,6 +372,8 @@ void R_InterpolatePrecipMobjState(precipmobj_t *mobj, fixed_t frac, interpmobjst
|
|||
out->y = R_LerpFixed(mobj->old_y, mobj->y, frac);
|
||||
out->z = R_LerpFixed(mobj->old_z, mobj->z, frac);
|
||||
out->scale = FRACUNIT;
|
||||
out->radius = mobj->radius;
|
||||
out->height = mobj->height;
|
||||
out->spritexscale = R_LerpFixed(mobj->old_spritexscale, mobj->spritexscale, frac);
|
||||
out->spriteyscale = R_LerpFixed(mobj->old_spriteyscale, mobj->spriteyscale, frac);
|
||||
out->spritexoffset = R_LerpFixed(mobj->old_spritexoffset, mobj->spritexoffset, frac);
|
||||
|
|
|
@ -63,6 +63,8 @@ typedef struct {
|
|||
angle_t roll;
|
||||
angle_t spriteroll;
|
||||
fixed_t scale;
|
||||
fixed_t radius;
|
||||
fixed_t height;
|
||||
fixed_t spritexscale;
|
||||
fixed_t spriteyscale;
|
||||
fixed_t spritexoffset;
|
||||
|
|
|
@ -1184,7 +1184,7 @@ fixed_t R_GetShadowZ(mobj_t *thing, pslope_t **shadowslope)
|
|||
R_InterpolateMobjState(thing, FRACUNIT, &interp);
|
||||
}
|
||||
|
||||
halfHeight = interp.z + (thing->height >> 1);
|
||||
halfHeight = interp.z + (interp.height >> 1);
|
||||
floorz = P_GetFloorZ(thing, interp.subsector->sector, interp.x, interp.y, NULL);
|
||||
ceilingz = P_GetCeilingZ(thing, interp.subsector->sector, interp.x, interp.y, NULL);
|
||||
|
||||
|
@ -1248,8 +1248,8 @@ fixed_t R_GetShadowZ(mobj_t *thing, pslope_t **shadowslope)
|
|||
}
|
||||
}
|
||||
|
||||
if (isflipped ? (ceilingz < groundz - (!groundslope ? 0 : FixedMul(abs(groundslope->zdelta), thing->radius*3/2)))
|
||||
: (floorz > groundz + (!groundslope ? 0 : FixedMul(abs(groundslope->zdelta), thing->radius*3/2))))
|
||||
if (isflipped ? (ceilingz < groundz - (!groundslope ? 0 : FixedMul(abs(groundslope->zdelta), interp.radius*3/2)))
|
||||
: (floorz > groundz + (!groundslope ? 0 : FixedMul(abs(groundslope->zdelta), interp.radius*3/2))))
|
||||
{
|
||||
groundz = isflipped ? ceilingz : floorz;
|
||||
groundslope = NULL;
|
||||
|
@ -1292,9 +1292,9 @@ static void R_SkewShadowSprite(
|
|||
//CONS_Printf("Shadow is sloped by %d %d\n", xslope, zslope);
|
||||
|
||||
if (viewz < groundz)
|
||||
*shadowyscale += FixedMul(FixedMul(thing->radius*2 / spriteheight, scalemul), zslope);
|
||||
*shadowyscale += FixedMul(FixedMul(interp.radius*2 / spriteheight, scalemul), zslope);
|
||||
else
|
||||
*shadowyscale -= FixedMul(FixedMul(thing->radius*2 / spriteheight, scalemul), zslope);
|
||||
*shadowyscale -= FixedMul(FixedMul(interp.radius*2 / spriteheight, scalemul), zslope);
|
||||
|
||||
*shadowyscale = abs((*shadowyscale));
|
||||
*shadowskew = xslope;
|
||||
|
@ -1345,20 +1345,18 @@ static void R_ProjectDropShadow(mobj_t *thing, vissprite_t *vis, fixed_t scale,
|
|||
return;
|
||||
}
|
||||
|
||||
floordiff = abs((isflipped ? thing->height : 0) + interp.z - groundz);
|
||||
floordiff = abs((isflipped ? interp.height : 0) + interp.z - groundz);
|
||||
|
||||
trans = floordiff / (100*FRACUNIT) + 3;
|
||||
if (trans >= 9) return;
|
||||
|
||||
scalemul = FixedMul(FRACUNIT - floordiff/640, scale);
|
||||
if ((thing->scale != thing->old_scale) && (thing->scale >= FRACUNIT/1024)) // Interpolate shadows when scaling mobjs
|
||||
scalemul = FixedMul(scalemul, FixedDiv(interp.scale, thing->scale));
|
||||
|
||||
patch = W_CachePatchName("DSHADOW", PU_SPRITE);
|
||||
xscale = FixedDiv(projection, tz);
|
||||
yscale = FixedDiv(projectiony, tz);
|
||||
shadowxscale = FixedMul(thing->radius*2, scalemul);
|
||||
shadowyscale = FixedMul(FixedMul(thing->radius*2, scalemul), FixedDiv(abs(groundz - viewz), tz));
|
||||
shadowxscale = FixedMul(interp.radius*2, scalemul);
|
||||
shadowyscale = FixedMul(FixedMul(interp.radius*2, scalemul), FixedDiv(abs(groundz - viewz), tz));
|
||||
shadowyscale = min(shadowyscale, shadowxscale) / patch->height;
|
||||
shadowxscale /= patch->width;
|
||||
shadowskew = 0;
|
||||
|
@ -1484,8 +1482,8 @@ static void R_ProjectBoundingBox(mobj_t *thing, vissprite_t *vis)
|
|||
// 0--2
|
||||
|
||||
// start in the (0) corner
|
||||
gx = interp.x - thing->radius - viewx;
|
||||
gy = interp.y - thing->radius - viewy;
|
||||
gx = interp.x - interp.radius - viewx;
|
||||
gy = interp.y - interp.radius - viewy;
|
||||
|
||||
tz = FixedMul(gx, viewcos) + FixedMul(gy, viewsin);
|
||||
|
||||
|
@ -1507,14 +1505,14 @@ static void R_ProjectBoundingBox(mobj_t *thing, vissprite_t *vis)
|
|||
box = R_NewVisSprite();
|
||||
box->mobj = thing;
|
||||
box->mobjflags = thing->flags;
|
||||
box->thingheight = thing->height;
|
||||
box->thingheight = interp.height;
|
||||
box->cut = SC_BBOX;
|
||||
|
||||
box->gx = tx;
|
||||
box->gy = tz;
|
||||
|
||||
box->scale = 2 * FixedMul(thing->radius, viewsin);
|
||||
box->xscale = 2 * FixedMul(thing->radius, viewcos);
|
||||
box->scale = 2 * FixedMul(interp.radius, viewsin);
|
||||
box->xscale = 2 * FixedMul(interp.radius, viewcos);
|
||||
|
||||
box->pz = interp.z;
|
||||
box->pzt = box->pz + box->thingheight;
|
||||
|
@ -1563,6 +1561,7 @@ static void R_ProjectSprite(mobj_t *thing)
|
|||
fixed_t tr_x, tr_y;
|
||||
fixed_t tx, tz;
|
||||
fixed_t xscale, yscale; //added : 02-02-98 : aaargll..if I were a math-guy!!!
|
||||
fixed_t radius, height; // For drop shadows
|
||||
fixed_t sortscale, sortsplat = 0;
|
||||
fixed_t linkscale = 0;
|
||||
fixed_t sort_x = 0, sort_y = 0, sort_z;
|
||||
|
@ -1638,6 +1637,8 @@ static void R_ProjectSprite(mobj_t *thing)
|
|||
}
|
||||
|
||||
this_scale = interp.scale;
|
||||
radius = interp.radius; // For drop shadows
|
||||
height = interp.height; // Ditto
|
||||
|
||||
// transform the origin point
|
||||
tr_x = interp.x - viewx;
|
||||
|
@ -1977,6 +1978,8 @@ static void R_ProjectSprite(mobj_t *thing)
|
|||
{
|
||||
R_InterpolateMobjState(thing, FRACUNIT, &tracer_interp);
|
||||
}
|
||||
radius = tracer_interp.radius; // For drop shadows
|
||||
height = tracer_interp.height; // Ditto
|
||||
|
||||
tr_x = (tracer_interp.x + sort_x) - viewx;
|
||||
tr_y = (tracer_interp.y + sort_y) - viewy;
|
||||
|
@ -2068,7 +2071,7 @@ static void R_ProjectSprite(mobj_t *thing)
|
|||
if (abs(groundz-viewz)/tz > 4)
|
||||
return; // Prevent stretchy shadows and possible crashes
|
||||
|
||||
floordiff = abs((isflipped ? caster->height : 0) + casterinterp.z - groundz);
|
||||
floordiff = abs((isflipped ? casterinterp.height : 0) + casterinterp.z - groundz);
|
||||
trans += ((floordiff / (100*FRACUNIT)) + 3);
|
||||
shadowscale = FixedMul(FRACUNIT - floordiff/640, casterinterp.scale);
|
||||
}
|
||||
|
@ -2083,8 +2086,8 @@ static void R_ProjectSprite(mobj_t *thing)
|
|||
|
||||
if (shadowdraw)
|
||||
{
|
||||
spritexscale = FixedMul(thing->radius * 2, FixedMul(shadowscale, spritexscale));
|
||||
spriteyscale = FixedMul(thing->radius * 2, FixedMul(shadowscale, spriteyscale));
|
||||
spritexscale = FixedMul(radius * 2, FixedMul(shadowscale, spritexscale));
|
||||
spriteyscale = FixedMul(radius * 2, FixedMul(shadowscale, spriteyscale));
|
||||
spriteyscale = FixedMul(spriteyscale, FixedDiv(abs(groundz - viewz), tz));
|
||||
spriteyscale = min(spriteyscale, spritexscale) / patch->height;
|
||||
spritexscale /= patch->width;
|
||||
|
@ -2099,7 +2102,7 @@ static void R_ProjectSprite(mobj_t *thing)
|
|||
{
|
||||
R_SkewShadowSprite(thing, thing->standingslope, groundz, patch->height, shadowscale, &spriteyscale, &sheartan);
|
||||
|
||||
gzt = (isflipped ? (interp.z + thing->height) : interp.z) + patch->height * spriteyscale / 2;
|
||||
gzt = (isflipped ? (interp.z + height) : interp.z) + patch->height * spriteyscale / 2;
|
||||
gz = gzt - patch->height * spriteyscale;
|
||||
|
||||
cut |= SC_SHEAR;
|
||||
|
@ -2114,11 +2117,7 @@ static void R_ProjectSprite(mobj_t *thing)
|
|||
// When vertical flipped, draw sprites from the top down, at least as far as offsets are concerned.
|
||||
// sprite height - sprite topoffset is the proper inverse of the vertical offset, of course.
|
||||
// remember gz and gzt should be seperated by sprite height, not thing height - thing height can be shorter than the sprite itself sometimes!
|
||||
|
||||
if (oldthing->scale != oldthing->old_scale) // Interpolate heights in reverse gravity when scaling mobjs
|
||||
gz = interp.z + FixedMul(oldthing->height, FixedDiv(interp.scale, oldthing->scale)) - FixedMul(spr_topoffset, FixedMul(spriteyscale, this_scale));
|
||||
else
|
||||
gz = interp.z + oldthing->height - FixedMul(spr_topoffset, FixedMul(spriteyscale, this_scale));
|
||||
gz = interp.z + interp.height - FixedMul(spr_topoffset, FixedMul(spriteyscale, this_scale));
|
||||
gzt = gz + FixedMul(spr_height, FixedMul(spriteyscale, this_scale));
|
||||
}
|
||||
else
|
||||
|
@ -2197,7 +2196,7 @@ static void R_ProjectSprite(mobj_t *thing)
|
|||
vis->gy = interp.y;
|
||||
vis->gz = gz;
|
||||
vis->gzt = gzt;
|
||||
vis->thingheight = thing->height;
|
||||
vis->thingheight = height;
|
||||
vis->pz = interp.z;
|
||||
vis->pzt = vis->pz + vis->thingheight;
|
||||
vis->texturemid = FixedDiv(gzt - viewz, spriteyscale);
|
||||
|
|
Loading…
Reference in a new issue