redo kart tilt offsetting code

also caught some more issues with sprite offsets, should be perfect now(?)
This commit is contained in:
minenice55 2026-04-23 12:59:06 -04:00
parent 532826f61d
commit b9553e4c9e
3 changed files with 44 additions and 19 deletions

View file

@ -1855,7 +1855,10 @@ static void HWR_ProjectSprite(mobj_t *thing)
}
else
{
use_xoffset += (FixedDiv(interp.spritexoffset,highresscale) * (flip ? -1 : 1));
SINT8 flipoffset = 1;
if ((thing->renderflags & RF_FLIPOFFSETS) && flip)
flipoffset = -1;
use_xoffset += (FixedDiv(interp.spritexoffset,highresscale) * flipoffset);
}
affine_pivotoffsetdiff.x = FIXED_TO_FLOAT(affine_pivot.x - use_xoffset);
@ -1870,8 +1873,9 @@ static void HWR_ProjectSprite(mobj_t *thing)
angle = R_ConvToRollAngle(spriterotangle) * flipsign;
const fixed_t rolloffs_x = FixedDiv(interptarg->rollingxoffset * FRACUNIT, highresscale) * (((thing->renderflags & RF_FLIPOFFSETS) && flip) ? -1 : 1);
const fixed_t rolloffs_y = FixedDiv(interptarg->rollingyoffset * FRACUNIT, highresscale);
const boolean renderflip = ((thing->renderflags & RF_FLIPOFFSETS) == RF_FLIPOFFSETS);
const fixed_t rolloffs_x = FixedDiv(interptarg->rollingxoffset * FRACUNIT, highresscale) * (((!renderflip) && flip) ? -1 : 1);
const fixed_t rolloffs_y = FixedDiv(interptarg->rollingyoffset * FRACUNIT, highresscale) * (((!renderflip) && vflip) ? -1 : 1);
fixed_t y_piv = affine_pivot.y;
if (vflip)

View file

@ -7873,8 +7873,15 @@ void K_KartPlayerThink(player_t *player, ticcmd_t *cmd)
if (player->karttilt)
{
//todo: a way for skins(?) to define the tyre offset
player->mo->spriteyoffset += abs(FixedMul(player->mo->info->radius, FINESINE(FixedAngle(abs(player->karttilt))>>ANGLETOFINESHIFT))) * P_MobjFlip(player->mo);
player->mo->spritexoffset -= FixedMul(4*player->mo->info->radius, FINESINE(FixedAngle(player->karttilt)>>ANGLETOFINESHIFT));
vector2_t tyreoffs = {player->mo->info->radius * intsign(player->karttilt), 0};
FV2_Rotate(&tyreoffs, -player->karttilt);
player->mo->spritexoffset -= FixedMul(5 * player->mo->info->radius / 2, FSIN(FixedAngle(-player->karttilt))) - ((player->mo->info->radius * intsign(player->karttilt)) - tyreoffs.x);
player->mo->spriteyoffset += (-tyreoffs.y/2) * P_MobjFlip(player->mo);
CONS_Debug(DBG_PLAYER, "kart tilt : %4.3f\n", FIXED_TO_FLOAT(player->karttilt));
CONS_Debug(DBG_PLAYER, "tyreoffs x: %4.3f, y: %4.3f\n", FIXED_TO_FLOAT(tyreoffs.x), FIXED_TO_FLOAT(tyreoffs.y));
CONS_Debug(DBG_PLAYER, "radius fac: %4.3f\n", FIXED_TO_FLOAT(player->mo->info->radius * intsign(player->karttilt)));
CONS_Debug(DBG_PLAYER, "spritexoff: %4.3f, y: %4.3f\n", FIXED_TO_FLOAT(player->mo->spritexoffset), FIXED_TO_FLOAT(player->mo->spriteyoffset));
}
}
@ -9491,7 +9498,7 @@ static void K_HandleKartTilt(player_t *player)
return;
}
angulargravity = abs(lineargravity) * (P_IsObjectOnGround(player->mo) ? 11 : 5);
angulargravity = abs(lineargravity) * (P_IsObjectOnGround(player->mo) ? 12 : 5);
// O = (linear velocity) / (distance from CoM)
angaccelgravity = FixedDiv(angulargravity, abs(FixedMul(player->mo->radius, FRACUNIT + abs(FINESINE(FixedAngle(player->karttilt)>>ANGLETOFINESHIFT)))));
@ -9501,12 +9508,12 @@ static void K_HandleKartTilt(player_t *player)
player->karttiltmomentum = PLAYERTILTMOMENTUMCAP * intsign(player->karttiltmomentum);
}
player->karttilt += FixedMul(player->karttiltmomentum, FIXEDRADTODEG)/TICRATE;
player->karttilt = CLAMP(player->karttilt + FixedMul(player->karttiltmomentum, FIXEDRADTODEG)/TICRATE, -PLAYERTILTCAP + 1, PLAYERTILTCAP - 1);
// angular drag
if (player->mo->eflags & MFE_UNDERWATER)
{
player->karttiltmomentum = FixedMul(player->karttiltmomentum, 75*FRACUNIT/100);
player->karttiltmomentum = FixedMul(player->karttiltmomentum, 80*FRACUNIT/100);
}
else
{
@ -9521,19 +9528,14 @@ static void K_HandleKartTilt(player_t *player)
if ((player->karttilt < 0 && startsign > 0) ||
(player->karttilt > 0 && startsign < 0))
{
player->karttiltmomentum = abs(player->karttiltmomentum) * intsign(player->karttilt);
player->karttiltmomentum = abs(90*player->karttiltmomentum/100) * intsign(player->karttilt);
player->karttiltmomentum /= 2;
if (abs(player->karttiltmomentum) < FRACUNIT/3)
if (abs(player->karttiltmomentum) < FRACUNIT/2)
{
player->karttiltmomentum = 0;
}
player->karttilt = 0;
}
else if (abs(player->karttilt) >= PLAYERTILTCAP)
{
player->karttiltmomentum = 0;
player->karttilt = CLAMP(player->karttilt, -PLAYERTILTCAP + 1, PLAYERTILTCAP - 1);
}
}
#undef FIXEDRADTODEG

View file

@ -2398,7 +2398,26 @@ static void R_ProjectSprite(mobj_t *thing)
sprinfo,
(thing->frame & FF_FRAMEMASK));
affine_pivotoffsetdiff.x = FIXED_TO_FLOAT(affine_pivot.x - spr_offset);
fixed_t use_xoffset = spr_offset;
if (flip)
{
use_xoffset = spr_width - spr_offset;
}
if (thing->renderflags & RF_ABSOLUTEOFFSETS)
{
use_xoffset = FixedDiv(interp.spritexoffset,highresscale);
}
else
{
SINT8 flipoffset = 1;
if ((thing->renderflags & RF_FLIPOFFSETS) && flip)
flipoffset = -1;
use_xoffset += (FixedDiv(interp.spritexoffset,highresscale) * flipoffset);
}
affine_pivotoffsetdiff.x = FIXED_TO_FLOAT(affine_pivot.x - use_xoffset);
affine_pivotoffsetdiff.y = FIXED_TO_FLOAT(affine_pivot.y - spr_topoffset);
affine_scale.x = FixedMul(affine_scale.x, FixedMul(spritexscale, this_scale));
@ -2463,7 +2482,7 @@ static void R_ProjectSprite(mobj_t *thing)
if (thing->renderflags & RF_ABSOLUTEOFFSETS)
{
spr_offset = FixedDiv(use_sprxoff, highresscale);
spr_offset = FixedDiv(interp.spritexoffset, highresscale);
#ifdef ROTSPRITE
spr_topoffset = thingyoffset;
#else
@ -2477,7 +2496,7 @@ static void R_ProjectSprite(mobj_t *thing)
if ((thing->renderflags & RF_FLIPOFFSETS) && flip)
flipoffset = -1;
spr_offset += FixedDiv(use_sprxoff, highresscale) * flipoffset;
spr_offset += FixedDiv(interp.spritexoffset, highresscale) * flipoffset;
#ifdef ROTSPRITE
thingyoffset *= flipoffset;
@ -2490,7 +2509,7 @@ static void R_ProjectSprite(mobj_t *thing)
#endif
}
if (flip)
if ((thing->renderflags & RF_FLIPOFFSETS) && flip)
offset = spr_offset - spr_width;
else
offset = -spr_offset;