From 2a20939617faaef1878d64f19bd8c7b98a6760b2 Mon Sep 17 00:00:00 2001 From: TehRealSalt Date: Tue, 4 Sep 2018 16:08:37 -0400 Subject: [PATCH] Camera panning for drifts --- src/p_local.h | 3 +++ src/p_user.c | 43 +++++++++++++++++++++++++++++-------------- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/p_local.h b/src/p_local.h index 7d7342bc..51676a2c 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -107,6 +107,9 @@ typedef struct camera_s // Momentums, used to update position. fixed_t momx, momy, momz; + + // SRB2Kart: camera pans while drifting + fixed_t pan; } camera_t; extern camera_t camera, camera2, camera3, camera4; diff --git a/src/p_user.c b/src/p_user.c index 1f0d2092..524d5f5c 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -8162,7 +8162,8 @@ void P_ResetCamera(player_t *player, camera_t *thiscam) boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcalled) { angle_t angle = 0, focusangle = 0, focusaiming = 0; - fixed_t x, y, z, dist, height, checkdist, viewpointx, viewpointy, camspeed, camdist, camheight, pviewheight; + fixed_t x, y, z, dist, height, viewpointx, viewpointy, camspeed, camdist, camheight, pviewheight; + fixed_t pan, xpan, ypan; INT32 camrotate; boolean camstill, cameranoclip, lookback; mobj_t *mo; @@ -8379,9 +8380,6 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall // sets ideal cam pos dist = camdist; - if (player->speed > K_GetKartSpeed(player, false)) - dist += 3*(player->speed - K_GetKartSpeed(player, false)); - // in splitscreen modes, mess with the camera distances to make it feel proportional to how it feels normally if (splitscreen == 1) // widescreen splits should get x1.5 distance { @@ -8389,18 +8387,36 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall height = FixedMul(height, 3*FRACUNIT/2); } + if (player->kartstuff[k_drift] != 0) + { + fixed_t panmax = (dist/5); + pan = min(player->kartstuff[k_driftcharge], K_GetKartDriftSparkValue(player)) * panmax / K_GetKartDriftSparkValue(player); + if (pan > panmax) + pan = panmax; + if (player->kartstuff[k_drift] < 0) + pan *= -1; + } + else + pan = 0; + + if (player->speed > K_GetKartSpeed(player, false)) + dist += 3*(player->speed - K_GetKartSpeed(player, false)); + if (player->climbing || player->playerstate == PST_DEAD || (player->pflags & (PF_MACESPIN|PF_ITEMHANG|PF_ROPEHANG))) dist <<= 1; - checkdist = dist; - - if (checkdist < 128*FRACUNIT) - checkdist = 128*FRACUNIT; - x = mo->x - FixedMul(FINECOSINE((angle>>ANGLETOFINESHIFT) & FINEMASK), dist); y = mo->y - FixedMul(FINESINE((angle>>ANGLETOFINESHIFT) & FINEMASK), dist); pviewheight = FixedMul(32<scale); + pan = thiscam->pan + FixedMul(pan - thiscam->pan, camspeed/4); + + xpan = FixedMul(FINECOSINE(((angle+ANGLE_90)>>ANGLETOFINESHIFT) & FINEMASK), pan); + ypan = FixedMul(FINESINE(((angle+ANGLE_90)>>ANGLETOFINESHIFT) & FINEMASK), pan); + + x += xpan; + y += ypan; + if (mo->eflags & MFE_VERTICALFLIP) z = mo->z + mo->height - pviewheight - camheight; @@ -8608,15 +8624,12 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall // point viewed by the camera // this point is just 64 unit forward the player dist = 64*mapheaderinfo[gamemap-1]->mobj_scale; - viewpointx = mo->x + FixedMul(FINECOSINE((angle>>ANGLETOFINESHIFT) & FINEMASK), dist); - viewpointy = mo->y + FixedMul(FINESINE((angle>>ANGLETOFINESHIFT) & FINEMASK), dist); + viewpointx = mo->x + FixedMul(FINECOSINE((angle>>ANGLETOFINESHIFT) & FINEMASK), dist) + xpan; + viewpointy = mo->y + FixedMul(FINESINE((angle>>ANGLETOFINESHIFT) & FINEMASK), dist) + ypan; if (!camstill && !resetcalled && !paused) thiscam->angle = R_PointToAngle2(thiscam->x, thiscam->y, viewpointx, viewpointy); - viewpointx = mo->x + FixedMul(FINECOSINE((angle>>ANGLETOFINESHIFT) & FINEMASK), dist); - viewpointy = mo->y + FixedMul(FINESINE((angle>>ANGLETOFINESHIFT) & FINEMASK), dist); - if (player->exiting) { thiscam->momx = 0; @@ -8636,6 +8649,8 @@ boolean P_MoveChaseCamera(player_t *player, camera_t *thiscam, boolean resetcall thiscam->momz = FixedMul(z - thiscam->z, camspeed/2); } + thiscam->pan = pan; + // compute aming to look the viewed point f1 = viewpointx-thiscam->x; f2 = viewpointy-thiscam->y;