- added weapon bobbing interpolation.

This was so ridiculously simple that I really fail to understand why the previous attempt was so overcomplicated that it just failed for that.
This commit is contained in:
Christoph Oelckers 2016-04-07 11:48:23 +02:00
parent 7f23a91488
commit 7ebb961917
3 changed files with 64 additions and 58 deletions

View file

@ -367,9 +367,10 @@ void P_DropWeapon (player_t *player)
//
//============================================================================
void P_BobWeapon (player_t *player, pspdef_t *psp, float *x, float *y)
void P_BobWeapon (player_t *player, pspdef_t *psp, float *x, float *y, double ticfrac)
{
static float curbob;
double xx[2], yy[2];
AWeapon *weapon;
float bobtarget;
@ -388,74 +389,79 @@ void P_BobWeapon (player_t *player, pspdef_t *psp, float *x, float *y)
float Rangex = weapon->BobRangeX;
float Rangey = weapon->BobRangeY;
// Bob the weapon based on movement speed.
FAngle angle = (BobSpeed * 35 / TICRATE*level.time) * (360.f / 8192.f);
// [RH] Smooth transitions between bobbing and not-bobbing frames.
// This also fixes the bug where you can "stick" a weapon off-center by
// shooting it when it's at the peak of its swing.
bobtarget = float((player->WeaponState & WF_WEAPONBOBBING) ? player->bob : 0.);
if (curbob != bobtarget)
for (int i = 0; i < 2; i++)
{
if (fabsf (bobtarget - curbob) <= 1)
// Bob the weapon based on movement speed.
FAngle angle = (BobSpeed * 35 / TICRATE*(level.time - 1 + i)) * (360.f / 8192.f);
// [RH] Smooth transitions between bobbing and not-bobbing frames.
// This also fixes the bug where you can "stick" a weapon off-center by
// shooting it when it's at the peak of its swing.
bobtarget = float((player->WeaponState & WF_WEAPONBOBBING) ? player->bob : 0.);
if (curbob != bobtarget)
{
curbob = bobtarget;
}
else
{
float zoom = MAX (1.f, fabsf (curbob - bobtarget) / 40);
if (curbob > bobtarget)
if (fabsf(bobtarget - curbob) <= 1)
{
curbob -= zoom;
curbob = bobtarget;
}
else
{
curbob += zoom;
float zoom = MAX(1.f, fabsf(curbob - bobtarget) / 40);
if (curbob > bobtarget)
{
curbob -= zoom;
}
else
{
curbob += zoom;
}
}
}
}
if (curbob != 0)
{
float bobx = float(player->bob * Rangex);
float boby = float(player->bob * Rangey);
switch (bobstyle)
if (curbob != 0)
{
case AWeapon::BobNormal:
*x = bobx * angle.Cos();
*y = boby * fabsf(angle.Sin());
break;
case AWeapon::BobInverse:
*x = bobx*angle.Cos();
*y = boby * (1.f - fabsf(angle.Sin()));
break;
case AWeapon::BobAlpha:
*x = bobx * angle.Sin();
*y = boby * fabsf(angle.Sin());
break;
case AWeapon::BobInverseAlpha:
*x = bobx * angle.Sin();
*y = boby * (1.f - fabsf(angle.Sin()));
break;
case AWeapon::BobSmooth:
*x = bobx*angle.Cos();
*y = 0.5f * (boby * (1.f - ((angle * 2).Cos())));
break;
float bobx = float(player->bob * Rangex);
float boby = float(player->bob * Rangey);
switch (bobstyle)
{
case AWeapon::BobNormal:
xx[i] = bobx * angle.Cos();
yy[i] = boby * fabsf(angle.Sin());
break;
case AWeapon::BobInverseSmooth:
*x = bobx*angle.Cos();
*y = 0.5f * (boby * (1.f + ((angle * 2).Cos())));
case AWeapon::BobInverse:
xx[i] = bobx*angle.Cos();
yy[i] = boby * (1.f - fabsf(angle.Sin()));
break;
case AWeapon::BobAlpha:
xx[i] = bobx * angle.Sin();
yy[i] = boby * fabsf(angle.Sin());
break;
case AWeapon::BobInverseAlpha:
xx[i] = bobx * angle.Sin();
yy[i] = boby * (1.f - fabsf(angle.Sin()));
break;
case AWeapon::BobSmooth:
xx[i] = bobx*angle.Cos();
yy[i] = 0.5f * (boby * (1.f - ((angle * 2).Cos())));
break;
case AWeapon::BobInverseSmooth:
xx[i] = bobx*angle.Cos();
yy[i] = 0.5f * (boby * (1.f + ((angle * 2).Cos())));
}
}
else
{
xx[i] = 0;
yy[i] = 0;
}
}
else
{
*x = 0;
*y = 0;
}
*x = (float)(xx[0] * (1. - ticfrac) + xx[1] * ticfrac);
*y = (float)(yy[0] * (1. - ticfrac) + yy[1] * ticfrac);
}
//============================================================================

View file

@ -87,7 +87,7 @@ void P_CalcSwing (player_t *player);
void P_BringUpWeapon (player_t *player);
void P_FireWeapon (player_t *player);
void P_DropWeapon (player_t *player);
void P_BobWeapon (player_t *player, pspdef_t *psp, float *x, float *y);
void P_BobWeapon (player_t *player, pspdef_t *psp, float *x, float *y, double ticfrac);
DAngle P_BulletSlope (AActor *mo, FTranslatedLineTarget *pLineTarget = NULL, int aimflags = 0);
void P_GunShot (AActor *mo, bool accurate, PClassActor *pufftype, DAngle pitch);

View file

@ -1579,7 +1579,7 @@ void R_DrawPlayerSprites ()
centery = viewheight >> 1;
centeryfrac = centery << FRACBITS;
P_BobWeapon (camera->player, &camera->player->psprites[ps_weapon], &ofsx, &ofsy);
P_BobWeapon (camera->player, &camera->player->psprites[ps_weapon], &ofsx, &ofsy, r_TicFracF);
// add all active psprites
for (i = 0, psp = camera->player->psprites;