From 26095da73c6f0959cddbda9091213ce55005b0f4 Mon Sep 17 00:00:00 2001 From: Colton Rushton Date: Tue, 19 May 2020 21:58:15 -0300 Subject: [PATCH 1/6] Updating Bettercamera --- src/game/bettercamera.inc.h | 55 +++++++++++++++++++++++++------------ src/game/camera.c | 6 ++++ 2 files changed, 44 insertions(+), 17 deletions(-) diff --git a/src/game/bettercamera.inc.h b/src/game/bettercamera.inc.h index db8c04f8..f83770ab 100644 --- a/src/game/bettercamera.inc.h +++ b/src/game/bettercamera.inc.h @@ -74,9 +74,9 @@ struct newcam_hardpos newcam_fixedcam[] = #endif // noaccel s16 newcam_yaw; //Z axis rotation -s8 newcam_yaw_acc; +f32 newcam_yaw_acc; s16 newcam_tilt = 1500; //Y axis rotation -s8 newcam_tilt_acc; +f32 newcam_tilt_acc; u16 newcam_distance = 750; //The distance the camera stays from the player u16 newcam_distance_target = 750; //The distance the player camera tries to reach. f32 newcam_pos_target[3]; //The position the camera is basing calculations off. *usually* Mario. @@ -189,12 +189,18 @@ void newcam_diagnostics(void) static s16 newcam_adjust_value(s16 var, s16 val) { - var += val; - if (var > 100) - var = 100; - if (var < -100) - var = -100; - + if (val > 0) + { + var += val; + if (var > max) + var = max; + } + else if (val < 0) + { + var += val; + if (var < max) + var = max; + } return var; } @@ -234,6 +240,8 @@ static int ivrt(u8 axis) static void newcam_rotate_button(void) { + f32 intendedXMag; + f32 intendedYMag; if ((newcam_modeflags & NC_FLAG_8D || newcam_modeflags & NC_FLAG_4D) && newcam_modeflags & NC_FLAG_XTURN) //8 directional camera rotation input for buttons. { if ((gPlayer1Controller->buttonPressed & L_CBUTTONS) && newcam_analogue == 0) @@ -264,27 +272,33 @@ static void newcam_rotate_button(void) if (newcam_modeflags & NC_FLAG_XTURN) { if ((gPlayer1Controller->buttonDown & L_CBUTTONS) && newcam_analogue == 0) - newcam_yaw_acc = newcam_adjust_value(newcam_yaw_acc,accel); + newcam_yaw_acc = newcam_adjust_value(newcam_yaw_acc,accel, 100); else if ((gPlayer1Controller->buttonDown & R_CBUTTONS) && newcam_analogue == 0) - newcam_yaw_acc = newcam_adjust_value(newcam_yaw_acc,-accel); + newcam_yaw_acc = newcam_adjust_value(newcam_yaw_acc,-accel, -100); else + if (!newcam_analogue) + { #ifdef noaccel newcam_yaw_acc = 0; #else newcam_yaw_acc -= (newcam_yaw_acc*newcam_degrade); #endif + } } if (gPlayer1Controller->buttonDown & U_CBUTTONS && newcam_modeflags & NC_FLAG_YTURN && newcam_analogue == 0) - newcam_tilt_acc = newcam_adjust_value(newcam_tilt_acc,accel); + newcam_tilt_acc = newcam_adjust_value(newcam_tilt_acc,accel, 100); else if (gPlayer1Controller->buttonDown & D_CBUTTONS && newcam_modeflags & NC_FLAG_YTURN && newcam_analogue == 0) - newcam_tilt_acc = newcam_adjust_value(newcam_tilt_acc,-accel); + newcam_tilt_acc = newcam_adjust_value(newcam_tilt_acc,-accel, -100); else + if (!newcam_analogue) + { #ifdef noaccel newcam_tilt_acc = 0; #else newcam_tilt_acc -= (newcam_tilt_acc*newcam_degrade); #endif + } newcam_framessincec[0] += 1; newcam_framessincec[1] += 1; @@ -316,6 +330,8 @@ static void newcam_rotate_button(void) if (newcam_analogue == 1) //There's not much point in keeping this behind a check, but it wouldn't hurt, just incase any 2player shenanigans ever happen, it makes it easy to disable. { //The joystick values cap at 80, so divide by 8 to get the same net result at maximum turn as the button + intendedXMag = gPlayer2Controller->rawStickX*1.25; + intendedYMag = gPlayer2Controller->rawStickY*1.25; if (ABS(gPlayer2Controller->stickX) > 20 && newcam_modeflags & NC_FLAG_XTURN) { if (newcam_modeflags & NC_FLAG_8D) @@ -344,18 +360,23 @@ static void newcam_rotate_button(void) } } else - newcam_yaw_acc = newcam_adjust_value(newcam_yaw_acc,(-gPlayer2Controller->stickX/4)); - } + { + newcam_yaw_acc = newcam_adjust_value(newcam_yaw_acc,gPlayer2Controller->stickX/8, intendedXMag); + } else + if (newcam_analogue) { newcam_cstick_down = 0; newcam_yaw_acc -= (newcam_yaw_acc*newcam_degrade); } if (ABS(gPlayer2Controller->stickY) > 20 && newcam_modeflags & NC_FLAG_YTURN) - newcam_tilt_acc = newcam_adjust_value(newcam_tilt_acc,(-gPlayer2Controller->stickY/4)); + newcam_tilt_acc = newcam_adjust_value(newcam_tilt_acc,(-gPlayer2Controller->stickY/8, intendedYMag)); else + if (newcam_analogue) + { newcam_tilt_acc -= (newcam_tilt_acc*newcam_degrade); + } } if (newcam_mouse == 1) @@ -417,9 +438,9 @@ static void newcam_update_values(void) {//For tilt, this just limits it so it doesn't go further than 90 degrees either way. 90 degrees is actually 16384, but can sometimes lead to issues, so I just leave it shy of 90. u8 waterflag = 0; if (newcam_modeflags & NC_FLAG_XTURN) - newcam_yaw += (ivrt(0)*(newcam_yaw_acc*(newcam_sensitivityX/10))); + newcam_yaw += ((ivrt(0)*(newcam_yaw_acc*(newcam_sensitivityX/10)))); if (((newcam_tilt < 12000 && newcam_tilt_acc*ivrt(1) > 0) || (newcam_tilt > -12000 && newcam_tilt_acc*ivrt(1) < 0)) && newcam_modeflags & NC_FLAG_YTURN) - newcam_tilt += (ivrt(1)*(newcam_tilt_acc*(newcam_sensitivityY/10))); + newcam_tilt += ((ivrt(1)*(newcam_tilt_acc*(newcam_sensitivityY/10)))); else { if (newcam_tilt > 12000) diff --git a/src/game/camera.c b/src/game/camera.c index deddc6d5..e337c815 100644 --- a/src/game/camera.c +++ b/src/game/camera.c @@ -3080,6 +3080,12 @@ void update_camera(struct Camera *c) { sCButtonsPressed = find_c_buttons_pressed(sCButtonsPressed, gPlayer1Controller->buttonPressed,gPlayer1Controller->buttonDown); #ifdef BETTERCAMERA } + + if (gMarioState->action == ACT_SHOT_FROM_CANNON && newcam_active) + { + gMarioState->area->camera->mode = CAM_MODE_NEWCAM; + gLakituState.mode = CAM_MODE_NEWCAM; + } #endif if (c->cutscene != 0) { From 68374ca330e3b8d18f636a4274b791812775d834 Mon Sep 17 00:00:00 2001 From: Colton Rushton Date: Tue, 19 May 2020 22:05:35 -0300 Subject: [PATCH 2/6] Minor fix --- src/game/bettercamera.inc.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/game/bettercamera.inc.h b/src/game/bettercamera.inc.h index f83770ab..9a365a7a 100644 --- a/src/game/bettercamera.inc.h +++ b/src/game/bettercamera.inc.h @@ -330,8 +330,8 @@ static void newcam_rotate_button(void) if (newcam_analogue == 1) //There's not much point in keeping this behind a check, but it wouldn't hurt, just incase any 2player shenanigans ever happen, it makes it easy to disable. { //The joystick values cap at 80, so divide by 8 to get the same net result at maximum turn as the button - intendedXMag = gPlayer2Controller->rawStickX*1.25; - intendedYMag = gPlayer2Controller->rawStickY*1.25; + intendedXMag = gPlayer2Controller->stickX*1.25; + intendedYMag = gPlayer2Controller->stickY*1.25; if (ABS(gPlayer2Controller->stickX) > 20 && newcam_modeflags & NC_FLAG_XTURN) { if (newcam_modeflags & NC_FLAG_8D) From f9d798c321b02fd816f0dd97f33d8ccec67c8b83 Mon Sep 17 00:00:00 2001 From: Colton Rushton Date: Tue, 19 May 2020 22:08:45 -0300 Subject: [PATCH 3/6] Another minor fix --- src/game/bettercamera.inc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/game/bettercamera.inc.h b/src/game/bettercamera.inc.h index 9a365a7a..9e92dd3e 100644 --- a/src/game/bettercamera.inc.h +++ b/src/game/bettercamera.inc.h @@ -361,7 +361,7 @@ static void newcam_rotate_button(void) } else { - newcam_yaw_acc = newcam_adjust_value(newcam_yaw_acc,gPlayer2Controller->stickX/8, intendedXMag); + newcam_yaw_acc = newcam_adjust_value(newcam_yaw_acc,(-gPlayer2Controller->stickX/8), intendedXMag); } else if (newcam_analogue) From 560800e97a6b22dd1fd729abf21c25e100a8638d Mon Sep 17 00:00:00 2001 From: Colton Rushton Date: Tue, 19 May 2020 22:10:47 -0300 Subject: [PATCH 4/6] Formatting fixes. --- src/game/bettercamera.inc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/game/bettercamera.inc.h b/src/game/bettercamera.inc.h index 9e92dd3e..6f3decbf 100644 --- a/src/game/bettercamera.inc.h +++ b/src/game/bettercamera.inc.h @@ -361,7 +361,7 @@ static void newcam_rotate_button(void) } else { - newcam_yaw_acc = newcam_adjust_value(newcam_yaw_acc,(-gPlayer2Controller->stickX/8), intendedXMag); + newcam_yaw_acc = newcam_adjust_value(newcam_yaw_acc,(-gPlayer2Controller->stickX/8, intendedXMag)); } else if (newcam_analogue) From 6e936174b0b8145087e6470ea0a71c9c5baa2d66 Mon Sep 17 00:00:00 2001 From: Colton Rushton Date: Wed, 20 May 2020 16:52:52 -0300 Subject: [PATCH 5/6] Resolve a few errors with the new additions. --- src/game/bettercamera.inc.h | 4 ++-- src/game/camera.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/game/bettercamera.inc.h b/src/game/bettercamera.inc.h index 6f3decbf..81ec9d07 100644 --- a/src/game/bettercamera.inc.h +++ b/src/game/bettercamera.inc.h @@ -187,7 +187,7 @@ void newcam_diagnostics(void) print_text_fmt_int(32,32,"DISTANCE %d",newcam_distance); } -static s16 newcam_adjust_value(s16 var, s16 val) +static s16 newcam_adjust_value(s16 var, s16 val, s8 max) { if (val > 0) { @@ -337,7 +337,7 @@ static void newcam_rotate_button(void) if (newcam_modeflags & NC_FLAG_8D) { if (newcam_cstick_down == 0) - { + { newcam_cstick_down = 1; newcam_centering = 1; #ifndef nosound diff --git a/src/game/camera.c b/src/game/camera.c index e337c815..5ae68805 100644 --- a/src/game/camera.c +++ b/src/game/camera.c @@ -3083,8 +3083,8 @@ void update_camera(struct Camera *c) { if (gMarioState->action == ACT_SHOT_FROM_CANNON && newcam_active) { - gMarioState->area->camera->mode = CAM_MODE_NEWCAM; - gLakituState.mode = CAM_MODE_NEWCAM; + gMarioState->area->camera->mode = CAMERA_MODE_NEWCAM; + gLakituState.mode = CAMERA_MODE_NEWCAM; } #endif From 9805dcab32d1de14317ad9b277fd3772e63a7bd7 Mon Sep 17 00:00:00 2001 From: Colton Rushton Date: Wed, 20 May 2020 21:10:00 -0300 Subject: [PATCH 6/6] Minor fix to updated bettercamera --- src/game/bettercamera.inc.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/game/bettercamera.inc.h b/src/game/bettercamera.inc.h index 81ec9d07..1dbe2f3b 100644 --- a/src/game/bettercamera.inc.h +++ b/src/game/bettercamera.inc.h @@ -361,8 +361,9 @@ static void newcam_rotate_button(void) } else { - newcam_yaw_acc = newcam_adjust_value(newcam_yaw_acc,(-gPlayer2Controller->stickX/8, intendedXMag)); + newcam_yaw_acc = newcam_adjust_value(newcam_yaw_acc,-gPlayer2Controller->stickX/8, intendedXMag); } + } else if (newcam_analogue) { @@ -371,7 +372,7 @@ static void newcam_rotate_button(void) } if (ABS(gPlayer2Controller->stickY) > 20 && newcam_modeflags & NC_FLAG_YTURN) - newcam_tilt_acc = newcam_adjust_value(newcam_tilt_acc,(-gPlayer2Controller->stickY/8, intendedYMag)); + newcam_tilt_acc = newcam_adjust_value(newcam_tilt_acc,-gPlayer2Controller->stickY/8, intendedYMag); else if (newcam_analogue) {