From e92d7eca8e5c9ab2f62a6b40ac3ec7e7d78bd685 Mon Sep 17 00:00:00 2001 From: fickleheart Date: Sun, 8 Dec 2019 15:54:16 -0600 Subject: [PATCH] Shift camera sideways toward player angle --- src/d_netcmd.c | 2 ++ src/g_game.c | 4 ++++ src/g_game.h | 2 +- src/m_menu.c | 14 ++++++++------ src/p_user.c | 24 ++++++++++++++++++++++-- 5 files changed, 37 insertions(+), 9 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 49d3d060c..24df649fc 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -826,6 +826,8 @@ void D_RegisterClientCommands(void) // hi here's some new controls CV_RegisterVar(&cv_abilitydirection[0]); CV_RegisterVar(&cv_abilitydirection[1]); + CV_RegisterVar(&cv_cam_shiftfacing[0]); + CV_RegisterVar(&cv_cam_shiftfacing[1]); CV_RegisterVar(&cv_cam_turnfacing[0]); CV_RegisterVar(&cv_cam_turnfacing[1]); CV_RegisterVar(&cv_cam_turnfacingability[0]); diff --git a/src/g_game.c b/src/g_game.c index d300fb80d..2d44c8e00 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -400,6 +400,10 @@ consvar_t cv_abilitydirection[2] = { {"abilitydirection2", "Movement", CV_SAVE, directionchar_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}, }; static CV_PossibleValue_t zerotoone_cons_t[] = {{0, "MIN"}, {FRACUNIT, "MAX"}, {0, NULL}}; +consvar_t cv_cam_shiftfacing[2] = { + {"cam_shiftfacingchar", "0.33", CV_FLOAT|CV_SAVE, zerotoone_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}, + {"cam2_shiftfacingchar", "0.33", CV_FLOAT|CV_SAVE, zerotoone_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}, +}; consvar_t cv_cam_turnfacing[2] = { {"cam_turnfacingchar", "0.002", CV_FLOAT|CV_SAVE, zerotoone_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}, {"cam2_turnfacingchar", "0.002", CV_FLOAT|CV_SAVE, zerotoone_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}, diff --git a/src/g_game.h b/src/g_game.h index ea2098f35..ea2cd1694 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -77,7 +77,7 @@ extern consvar_t cv_sideaxis2,cv_turnaxis2,cv_moveaxis2,cv_lookaxis2,cv_jumpaxis extern consvar_t cv_ghost_bestscore, cv_ghost_besttime, cv_ghost_bestrings, cv_ghost_last, cv_ghost_guest; // hi here's some new controls -extern consvar_t cv_abilitydirection[2], cv_cam_turnfacing[2], cv_cam_turnfacingability[2], cv_cam_turnfacinginput[2]; +extern consvar_t cv_abilitydirection[2], cv_cam_shiftfacing[2], cv_cam_turnfacing[2], cv_cam_turnfacingability[2], cv_cam_turnfacinginput[2]; // mouseaiming (looking up/down with the mouse or keyboard) #define KB_LOOKSPEED (1<<25) diff --git a/src/m_menu.c b/src/m_menu.c index 71d5b1bfb..4ae2b7036 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1182,9 +1182,10 @@ static menuitem_t OP_CameraOptionsMenu[] = {IT_STRING | IT_CVAR | IT_CV_INTEGERSTEP, NULL, "Camera Height", &cv_cam_height, 70}, {IT_STRING | IT_CVAR | IT_CV_FLOATSLIDER, NULL, "Camera Speed", &cv_cam_speed, 80}, - {IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Turn to character angle", &cv_cam_turnfacing[0], 100}, - {IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Turn to ability", &cv_cam_turnfacingability[0], 110}, - {IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Turn to input", &cv_cam_turnfacinginput[0], 120}, + {IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Shift to character angle", &cv_cam_shiftfacing[0], 100}, + {IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Turn to character angle", &cv_cam_turnfacing[0], 110}, + {IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Turn to ability", &cv_cam_turnfacingability[0], 120}, + {IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Turn to input", &cv_cam_turnfacinginput[0], 130}, {IT_STRING | IT_CVAR, NULL, "Crosshair", &cv_crosshair, 140}, }; @@ -1200,9 +1201,10 @@ static menuitem_t OP_Camera2OptionsMenu[] = {IT_STRING | IT_CVAR | IT_CV_INTEGERSTEP, NULL, "Camera Height", &cv_cam2_height, 70}, {IT_STRING | IT_CVAR | IT_CV_FLOATSLIDER, NULL, "Camera Speed", &cv_cam2_speed, 80}, - {IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Turn to character angle", &cv_cam_turnfacing[1], 100}, - {IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Turn to ability", &cv_cam_turnfacingability[1], 110}, - {IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Turn to input", &cv_cam_turnfacinginput[1], 120}, + {IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Shift to character angle", &cv_cam_shiftfacing[1], 100}, + {IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Turn to character angle", &cv_cam_turnfacing[1], 110}, + {IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Turn to ability", &cv_cam_turnfacingability[1], 120}, + {IT_STRING | IT_CVAR | IT_CV_SLIDER, NULL, "Turn to input", &cv_cam_turnfacinginput[1], 130}, {IT_STRING | IT_CVAR, NULL, "Crosshair", &cv_crosshair2, 140}, }; diff --git a/src/p_user.c b/src/p_user.c index 3b8b64e04..0a3636884 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -9677,6 +9677,9 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall subsector_t *newsubsec; fixed_t f1, f2; + static fixed_t camsideshift[2] = {0, 0}; + fixed_t shiftx = 0, shifty = 0; + // We probably shouldn't move the camera if there is no player or player mobj somehow if (!player || !player->mo) return true; @@ -9882,6 +9885,20 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall } } + if (cv_abilitydirection[(thiscam == &camera) ? 0 : 1].value) + { + // Shift the camera slightly to the sides depending on the player facing direction + UINT8 forplayer = (thiscam == &camera) ? 0 : 1; + fixed_t shift = FixedMul(FINESINE((player->drawangle - angle) >> ANGLETOFINESHIFT), cv_cam_shiftfacing[forplayer].value); + + shift += FixedMul(camsideshift[forplayer] - shift, FRACUNIT-(camspeed>>3)); + camsideshift[forplayer] = shift; + + shift = FixedMul(shift, camdist); + shiftx = -FixedMul(FINESINE(angle>>ANGLETOFINESHIFT), shift); + shifty = FixedMul(FINECOSINE(angle>>ANGLETOFINESHIFT), shift); + } + // sets ideal cam pos if (twodlevel || (mo->flags2 & MF2_TWOD)) dist = 480<x + FixedMul(FINECOSINE((angle>>ANGLETOFINESHIFT) & FINEMASK), dist); - viewpointy = mo->y + FixedMul(FINESINE((angle>>ANGLETOFINESHIFT) & FINEMASK), dist); + viewpointx = mo->x + shiftx + FixedMul(FINECOSINE((angle>>ANGLETOFINESHIFT) & FINEMASK), dist); + viewpointy = mo->y + shifty + FixedMul(FINESINE((angle>>ANGLETOFINESHIFT) & FINEMASK), dist); } if (!camstill && !resetcalled && !paused) @@ -10270,6 +10287,9 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall } else thiscam->momz = FixedMul(z - thiscam->z, camspeed); + + thiscam->momx += FixedMul(shiftx, camspeed); + thiscam->momy += FixedMul(shifty, camspeed); } // compute aming to look the viewed point