From 140ae6cc32351007d51ab441de8ca20059033f49 Mon Sep 17 00:00:00 2001 From: Mr-Wiseguy Date: Sun, 26 May 2024 07:41:01 -0400 Subject: [PATCH] Added scaled radial deadzone to analog cam and fixed issue walking after ledge grabs with analog cam --- patches/camera_patches.c | 6 ++++++ src/game/recomp_api.cpp | 21 ++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/patches/camera_patches.c b/patches/camera_patches.c index 1a3dabe..a1d0075 100644 --- a/patches/camera_patches.c +++ b/patches/camera_patches.c @@ -1860,10 +1860,16 @@ void analog_cam_post_play_update(PlayState* play) { Camera *active_cam = play->cameraPtrs[play->activeCamId]; // recomp_printf("prev_analog_cam_active: %d can_use_analog_cam: %d\n", prev_analog_cam_active, can_use_analog_cam); // recomp_printf("setting: %d mode: %d func: %d\n", active_cam->setting, active_cam->mode, sCameraSettings[active_cam->setting].cameraModes[active_cam->mode].funcId); + // recomp_printf("active cam yaw %d\n", Camera_GetInputDirYaw(GET_ACTIVE_CAM(play))); // Update parameters for the analog cam if the game is unpaused. if (play->pauseCtx.state == PAUSE_STATE_OFF && R_PAUSE_BG_PRERENDER_STATE == PAUSE_BG_PRERENDER_OFF) { update_analog_camera_params(active_cam); can_use_analog_cam = false; } + + if (analog_cam_active) { + active_cam->inputDir.x = analog_camera_pos.pitch; + active_cam->inputDir.y = analog_camera_pos.yaw + DEG_TO_BINANG(180); + } } diff --git a/src/game/recomp_api.cpp b/src/game/recomp_api.cpp index d993971..2d90838 100644 --- a/src/game/recomp_api.cpp +++ b/src/game/recomp_api.cpp @@ -139,7 +139,26 @@ extern "C" void recomp_get_camera_inputs(uint8_t* rdram, recomp_context* ctx) { float* x_out = _arg<0, float*>(rdram, ctx); float* y_out = _arg<1, float*>(rdram, ctx); - recomp::get_right_analog(x_out, y_out); + // TODO expose this in the menu + constexpr float radial_deadzone = 0.05f; + + float x, y; + + recomp::get_right_analog(&x, &y); + + float magnitude = std::sqrtf(x * x + y * y); + + if (magnitude < radial_deadzone) { + *x_out = 0.0f; + *y_out = 0.0f; + } + else { + float x_normalized = x / magnitude; + float y_normalized = y / magnitude; + + *x_out = x_normalized * ((magnitude - radial_deadzone) / (1 - radial_deadzone)); + *y_out = y_normalized * ((magnitude - radial_deadzone) / (1 - radial_deadzone)); + } } extern "C" void recomp_set_right_analog_suppressed(uint8_t* rdram, recomp_context* ctx) {