- 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; static float curbob;
double xx[2], yy[2];
AWeapon *weapon; AWeapon *weapon;
float bobtarget; float bobtarget;
@ -388,8 +389,10 @@ void P_BobWeapon (player_t *player, pspdef_t *psp, float *x, float *y)
float Rangex = weapon->BobRangeX; float Rangex = weapon->BobRangeX;
float Rangey = weapon->BobRangeY; float Rangey = weapon->BobRangeY;
for (int i = 0; i < 2; i++)
{
// Bob the weapon based on movement speed. // Bob the weapon based on movement speed.
FAngle angle = (BobSpeed * 35 / TICRATE*level.time) * (360.f / 8192.f); FAngle angle = (BobSpeed * 35 / TICRATE*(level.time - 1 + i)) * (360.f / 8192.f);
// [RH] Smooth transitions between bobbing and not-bobbing frames. // [RH] Smooth transitions between bobbing and not-bobbing frames.
// This also fixes the bug where you can "stick" a weapon off-center by // This also fixes the bug where you can "stick" a weapon off-center by
@ -422,41 +425,44 @@ void P_BobWeapon (player_t *player, pspdef_t *psp, float *x, float *y)
switch (bobstyle) switch (bobstyle)
{ {
case AWeapon::BobNormal: case AWeapon::BobNormal:
*x = bobx * angle.Cos(); xx[i] = bobx * angle.Cos();
*y = boby * fabsf(angle.Sin()); yy[i] = boby * fabsf(angle.Sin());
break; break;
case AWeapon::BobInverse: case AWeapon::BobInverse:
*x = bobx*angle.Cos(); xx[i] = bobx*angle.Cos();
*y = boby * (1.f - fabsf(angle.Sin())); yy[i] = boby * (1.f - fabsf(angle.Sin()));
break; break;
case AWeapon::BobAlpha: case AWeapon::BobAlpha:
*x = bobx * angle.Sin(); xx[i] = bobx * angle.Sin();
*y = boby * fabsf(angle.Sin()); yy[i] = boby * fabsf(angle.Sin());
break; break;
case AWeapon::BobInverseAlpha: case AWeapon::BobInverseAlpha:
*x = bobx * angle.Sin(); xx[i] = bobx * angle.Sin();
*y = boby * (1.f - fabsf(angle.Sin())); yy[i] = boby * (1.f - fabsf(angle.Sin()));
break; break;
case AWeapon::BobSmooth: case AWeapon::BobSmooth:
*x = bobx*angle.Cos(); xx[i] = bobx*angle.Cos();
*y = 0.5f * (boby * (1.f - ((angle * 2).Cos()))); yy[i] = 0.5f * (boby * (1.f - ((angle * 2).Cos())));
break; break;
case AWeapon::BobInverseSmooth: case AWeapon::BobInverseSmooth:
*x = bobx*angle.Cos(); xx[i] = bobx*angle.Cos();
*y = 0.5f * (boby * (1.f + ((angle * 2).Cos()))); yy[i] = 0.5f * (boby * (1.f + ((angle * 2).Cos())));
} }
} }
else else
{ {
*x = 0; xx[i] = 0;
*y = 0; yy[i] = 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_BringUpWeapon (player_t *player);
void P_FireWeapon (player_t *player); void P_FireWeapon (player_t *player);
void P_DropWeapon (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); DAngle P_BulletSlope (AActor *mo, FTranslatedLineTarget *pLineTarget = NULL, int aimflags = 0);
void P_GunShot (AActor *mo, bool accurate, PClassActor *pufftype, DAngle pitch); void P_GunShot (AActor *mo, bool accurate, PClassActor *pufftype, DAngle pitch);

View file

@ -1579,7 +1579,7 @@ void R_DrawPlayerSprites ()
centery = viewheight >> 1; centery = viewheight >> 1;
centeryfrac = centery << FRACBITS; 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 // add all active psprites
for (i = 0, psp = camera->player->psprites; for (i = 0, psp = camera->player->psprites;