From 313f5a08b45c922a02ef0a3f2bfefcaa586f54a4 Mon Sep 17 00:00:00 2001 From: Garrett Cox Date: Fri, 27 Oct 2023 17:17:37 -0500 Subject: [PATCH] Implement gMoveWhileFirstPerson. Works but not super happy with how player is moved --- .../controls/GameControlEditor.cpp | 6 +- .../actors/ovl_player_actor/z_player.c | 102 ++++++++++++------ 2 files changed, 73 insertions(+), 35 deletions(-) diff --git a/soh/soh/Enhancements/controls/GameControlEditor.cpp b/soh/soh/Enhancements/controls/GameControlEditor.cpp index 3bd65063773..bf3ab676502 100644 --- a/soh/soh/Enhancements/controls/GameControlEditor.cpp +++ b/soh/soh/Enhancements/controls/GameControlEditor.cpp @@ -233,6 +233,9 @@ namespace GameControlEditor { window->BeginGroupPanelPublic("Aiming/First-Person Camera", ImGui::GetContentRegionAvail()); UIWidgets::PaddedEnhancementCheckbox("Right Stick Aiming", "gRightStickAiming"); DrawHelpIcon("Allows for aiming with the right stick in:\n-First-Person/C-Up view\n-Weapon Aiming"); + if (CVarGetInteger("gRightStickAiming", 0)) { + UIWidgets::PaddedEnhancementCheckbox("Allow moving while in first person mode", "gMoveWhileFirstPerson"); + } UIWidgets::PaddedEnhancementCheckbox("Invert Aiming X Axis", "gInvertAimingXAxis"); DrawHelpIcon("Inverts the Camera X Axis in:\n-First-Person/C-Up view\n-Weapon Aiming"); UIWidgets::PaddedEnhancementCheckbox("Invert Aiming Y Axis", "gInvertAimingYAxis", true, true, false, "", UIWidgets::CheckboxGraphics::Cross, true); @@ -245,7 +248,8 @@ namespace GameControlEditor { DrawHelpIcon("Prevents the C-Up view from auto-centering, allowing for Gyro Aiming"); if (UIWidgets::PaddedEnhancementCheckbox("Enable Custom Aiming/First-Person sensitivity", "gEnableFirstPersonSensitivity", true, false)) { if (!CVarGetInteger("gEnableFirstPersonSensitivity", 0)) { - CVarClear("gFirstPersonCameraSensitivity"); + CVarClear("gFirstPersonCameraSensitivityX"); + CVarClear("gFirstPersonCameraSensitivityY"); } } if (CVarGetInteger("gEnableFirstPersonSensitivity", 0)) { diff --git a/soh/src/overlays/actors/ovl_player_actor/z_player.c b/soh/src/overlays/actors/ovl_player_actor/z_player.c index b575a0084b5..e4eae95a0e7 100644 --- a/soh/src/overlays/actors/ovl_player_actor/z_player.c +++ b/soh/src/overlays/actors/ovl_player_actor/z_player.c @@ -11384,58 +11384,92 @@ void Player_Destroy(Actor* thisx, PlayState* play) { //first person manipulate player actor s16 func_8084ABD8(PlayState* play, Player* this, s32 arg2, s16 arg3) { - s32 temp1; - s16 temp2; - s16 temp3; - bool gInvertAimingXAxis = (CVarGetInteger("gInvertAimingXAxis", 0) && !CVarGetInteger("gMirroredWorld", 0)) || (!CVarGetInteger("gInvertAimingXAxis", 0) && CVarGetInteger("gMirroredWorld", 0)); - - if (!func_8002DD78(this) && !func_808334B4(this) && (arg2 == 0) && !CVarGetInteger("gDisableAutoCenterViewFirstPerson", 0)) { - temp2 = sControlInput->rel.stick_y * 240.0f * (CVarGetInteger("gInvertAimingYAxis", 1) ? 1 : -1); // Sensitivity not applied here because higher than default sensitivies will allow the camera to escape the autocentering, and glitch out massively + s32 temp1 = 0; + s16 temp2 = 0; + s16 temp3 = 0; + s8 invertXAxisMulti = ((CVarGetInteger("gInvertAimingXAxis", 0) && !CVarGetInteger("gMirroredWorld", 0)) || (!CVarGetInteger("gInvertAimingXAxis", 0) && CVarGetInteger("gMirroredWorld", 0))) ? -1 : 1; + s8 invertYAxisMulti = CVarGetInteger("gInvertAimingYAxis", 1) ? 1 : -1; + f32 xAxisMulti = CVarGetFloat("gFirstPersonCameraSensitivityX", 1.0f); + f32 yAxisMulti = CVarGetFloat("gFirstPersonCameraSensitivityY", 1.0f); + + if (!func_8002DD78(this) && !func_808334B4(this) && (arg2 == 0)) { // First person without weapon + // Y Axis + if (!CVarGetInteger("gMoveWhileFirstPerson", 0)) { + temp2 += sControlInput->rel.stick_y * 240.0f * invertYAxisMulti * yAxisMulti; + } + if (CVarGetInteger("gRightStickAiming", 0) && fabsf(sControlInput->cur.right_stick_y) > 15.0f) { + temp2 += sControlInput->cur.right_stick_y * 240.0f * invertYAxisMulti * yAxisMulti; + } + if (fabsf(sControlInput->cur.gyro_y) > 0.01f) { + temp2 += (sControlInput->cur.gyro_y) * 750.0f; + } Math_SmoothStepToS(&this->actor.focus.rot.x, temp2, 14, 4000, 30); - temp2 = sControlInput->rel.stick_x * -16.0f * (gInvertAimingXAxis ? -1 : 1) * (CVarGetFloat("gFirstPersonCameraSensitivityX", 1.0f)); + temp2 = 0; + + // X Axis + if (!CVarGetInteger("gMoveWhileFirstPerson", 0)) { + temp2 += sControlInput->rel.stick_x * -16.0f * invertXAxisMulti * xAxisMulti; + } + if (CVarGetInteger("gRightStickAiming", 0) && fabsf(sControlInput->cur.right_stick_x) > 15.0f) { + temp2 += sControlInput->cur.right_stick_x * -16.0f * invertXAxisMulti * xAxisMulti; + } + if (fabsf(sControlInput->cur.gyro_x) > 0.01f) { + temp2 += (sControlInput->cur.gyro_x) * 750.0f; + } temp2 = CLAMP(temp2, -3000, 3000); this->actor.focus.rot.y += temp2; - } else { + } else { // First person with weapon + // Y Axis temp1 = (this->stateFlags1 & PLAYER_STATE1_ON_HORSE) ? 3500 : 14000; - temp3 = ((sControlInput->rel.stick_y >= 0) ? 1 : -1) * - (s32)((1.0f - Math_CosS(sControlInput->rel.stick_y * 200)) * 1500.0f * - (CVarGetInteger("gInvertAimingYAxis", 1) ? 1 : -1)) * (CVarGetFloat("gFirstPersonCameraSensitivityY", 1.0f)); - this->actor.focus.rot.x += temp3; - - if (fabsf(sControlInput->cur.gyro_x) > 0.01f) { - this->actor.focus.rot.x -= (sControlInput->cur.gyro_x) * 750.0f; + + if (!CVarGetInteger("gMoveWhileFirstPerson", 0)) { + temp3 += ((sControlInput->rel.stick_y >= 0) ? 1 : -1) * + (s32)((1.0f - Math_CosS(sControlInput->rel.stick_y * 200)) * 1500.0f) * invertYAxisMulti * yAxisMulti; } - - if (fabsf(sControlInput->cur.right_stick_y) > 15.0f && CVarGetInteger("gRightStickAiming", 0) != 0) { - this->actor.focus.rot.x -= - (sControlInput->cur.right_stick_y) * 10.0f * (CVarGetInteger("gInvertAimingYAxis", 1) ? -1 : 1) * (CVarGetFloat("gFirstPersonCameraSensitivityY", 1.0f)); + if (CVarGetInteger("gRightStickAiming", 0) && fabsf(sControlInput->cur.right_stick_y) > 15.0f) { + temp3 += ((sControlInput->cur.right_stick_y >= 0) ? 1 : -1) * + (s32)((1.0f - Math_CosS(sControlInput->cur.right_stick_y * 200)) * 1500.0f) * invertYAxisMulti * yAxisMulti; } - + if (fabsf(sControlInput->cur.gyro_y) > 0.01f) { + temp3 += (sControlInput->cur.gyro_y) * 750.0f; + } + this->actor.focus.rot.x += temp3; this->actor.focus.rot.x = CLAMP(this->actor.focus.rot.x, -temp1, temp1); + // X Axis temp1 = 19114; temp2 = this->actor.focus.rot.y - this->actor.shape.rot.y; - temp3 = ((sControlInput->rel.stick_x >= 0) ? 1 : -1) * - (s32)((1.0f - Math_CosS(sControlInput->rel.stick_x * 200)) * -1500.0f * - (gInvertAimingXAxis ? -1 : 1)) * (CVarGetFloat("gFirstPersonCameraSensitivityX", 1.0f)); + if (!CVarGetInteger("gMoveWhileFirstPerson", 0)) { + temp3 = ((sControlInput->rel.stick_x >= 0) ? 1 : -1) * + (s32)((1.0f - Math_CosS(sControlInput->rel.stick_x * 200)) * -1500.0f) * invertXAxisMulti * xAxisMulti; + } + if (CVarGetInteger("gRightStickAiming", 0) && fabsf(sControlInput->cur.right_stick_x) > 15.0f) { + temp3 += ((sControlInput->cur.right_stick_x >= 0) ? 1 : -1) * + (s32)((1.0f - Math_CosS(sControlInput->cur.right_stick_x * 200)) * -1500.0f) * invertXAxisMulti * xAxisMulti; + } + if (fabsf(sControlInput->cur.gyro_x) > 0.01f) { + temp3 += (sControlInput->cur.gyro_x) * 750.0f; + } temp2 += temp3; - this->actor.focus.rot.y = CLAMP(temp2, -temp1, temp1) + this->actor.shape.rot.y; + } - if (fabsf(sControlInput->cur.gyro_y) > 0.01f) { - this->actor.focus.rot.y += (sControlInput->cur.gyro_y) * 750.0f * (CVarGetInteger("gMirroredWorld", 0) ? -1 : 1); - } + if (CVarGetInteger("gMoveWhileFirstPerson", 0)) { + f32 relX = sControlInput->cur.stick_x / 10.0f * -invertXAxisMulti; + f32 relY = sControlInput->cur.stick_y / 10.0f; - if (fabsf(sControlInput->cur.right_stick_x) > 15.0f && CVarGetInteger("gRightStickAiming", 0) != 0) { - this->actor.focus.rot.y += - (sControlInput->cur.right_stick_x) * 10.0f * (gInvertAimingXAxis ? 1 : -1) * (CVarGetFloat("gFirstPersonCameraSensitivityX", 1.0f)); - } + // Determine what left and right mean based on camera angle + f32 relX2 = relX * Math_CosS(this->actor.focus.rot.y) + relY * Math_SinS(this->actor.focus.rot.y); + f32 relY2 = relY * Math_CosS(this->actor.focus.rot.y) - relX * Math_SinS(this->actor.focus.rot.y); + + // Apply the movement + this->actor.world.pos.x += relX2; + this->actor.world.pos.z += relY2; } this->unk_6AE |= 2; - return func_80836AB8(this, (play->shootingGalleryStatus != 0) || func_8002DD78(this) || func_808334B4(this)) - - arg3; + return func_80836AB8(this, (play->shootingGalleryStatus != 0) || func_8002DD78(this) || func_808334B4(this)) - arg3; } void func_8084AEEC(Player* this, f32* arg1, f32 arg2, s16 arg3) {