From c99e6426d7509c34d6a8ae4e948134a0fec1a2e6 Mon Sep 17 00:00:00 2001 From: Agent X <44549182+AgentXLP@users.noreply.github.com> Date: Wed, 3 Jul 2024 22:00:05 -0400 Subject: [PATCH] Improve first person camera --- src/game/camera.c | 2 +- src/game/first_person_cam.c | 5 +---- src/game/rendering_graph_node.c | 2 +- src/pc/controller/controller_mouse.c | 2 +- src/pc/controller/controller_mouse.h | 2 ++ src/pc/djui/djui_hud_utils.c | 6 ++++-- 6 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/game/camera.c b/src/game/camera.c index 7891df2f..8ec1ed9a 100644 --- a/src/game/camera.c +++ b/src/game/camera.c @@ -3648,7 +3648,7 @@ void zoom_out_if_paused_and_outside(struct GraphNodeCamera *camera) { areaMaskIndex = 0; areaBit = 0; } - if (gCameraMovementFlags & CAM_MOVE_PAUSE_SCREEN && !gDjuiInPlayerMenu) { + if (gCameraMovementFlags & CAM_MOVE_PAUSE_SCREEN && !gDjuiInPlayerMenu && !get_first_person_enabled()) { if (sFramesPaused >= 2) { if (sZoomOutAreaMasks[areaMaskIndex] & areaBit) { diff --git a/src/game/first_person_cam.c b/src/game/first_person_cam.c index 6baf0ed9..13f10a4c 100644 --- a/src/game/first_person_cam.c +++ b/src/game/first_person_cam.c @@ -55,7 +55,6 @@ bool get_first_person_enabled(void) { } void set_first_person_enabled(bool enable) { - if (gFirstPersonCamera.enabled && !enable) { gFOVState.fov = 45.0f; } gFirstPersonCamera.enabled = enable; } @@ -66,7 +65,7 @@ static void first_person_camera_update(void) { s16 invX = camera_config_is_x_inverted() ? 1 : -1; s16 invY = camera_config_is_y_inverted() ? 1 : -1; - if (gMenuMode == -1 && !gDjuiChatBoxFocus && !gDjuiConsoleFocus) { + if (mouse_relative_enabled) { // update pitch gFirstPersonCamera.pitch -= sensY * (invY * m->controller->extStickY - 1.5f * mouse_y); gFirstPersonCamera.pitch = CLAMP(gFirstPersonCamera.pitch, -0x3F00, 0x3F00); @@ -139,8 +138,6 @@ static void first_person_camera_update(void) { gLakituState.focHSpeed = 0; gLakituState.focVSpeed = 0; vec3s_set(gLakituState.shakeMagnitude, 0, 0, 0); - - gFOVState.fov = gFirstPersonCamera.fov; } void first_person_update(void) { diff --git a/src/game/rendering_graph_node.c b/src/game/rendering_graph_node.c index 89f14d6b..f29ba326 100644 --- a/src/game/rendering_graph_node.c +++ b/src/game/rendering_graph_node.c @@ -237,7 +237,7 @@ void patch_mtx_interpolated(f32 delta) { u16 perspNorm; f32 fovInterpolated = delta_interpolate_f32(sPerspectiveNode->prevFov, sPerspectiveNode->fov, delta); f32 near = MIN(sPerspectiveNode->near, gProjectionMaxNearValue); - guPerspective(sPerspectiveMtx, &perspNorm, not_zero(fovInterpolated, gOverrideFOV), sPerspectiveAspect, get_first_person_enabled() ? 1 : not_zero(near, gOverrideNear), not_zero(sPerspectiveNode->far, gOverrideFar), 1.0f); + guPerspective(sPerspectiveMtx, &perspNorm, get_first_person_enabled() ? gFirstPersonCamera.fov : not_zero(fovInterpolated, gOverrideFOV), sPerspectiveAspect, get_first_person_enabled() ? 1 : not_zero(near, gOverrideNear), not_zero(sPerspectiveNode->far, gOverrideFar), 1.0f); gSPMatrix(sPerspectivePos, VIRTUAL_TO_PHYSICAL(sPerspectiveNode), G_MTX_PROJECTION | G_MTX_LOAD | G_MTX_NOPUSH); } diff --git a/src/pc/controller/controller_mouse.c b/src/pc/controller/controller_mouse.c index 708970e0..837e9adc 100644 --- a/src/pc/controller/controller_mouse.c +++ b/src/pc/controller/controller_mouse.c @@ -21,7 +21,7 @@ u32 mouse_window_buttons; s32 mouse_window_x; s32 mouse_window_y; -static bool mouse_relative_enabled; +bool mouse_relative_enabled; void controller_mouse_read_window(void) { if (!mouse_init_ok) { return; } diff --git a/src/pc/controller/controller_mouse.h b/src/pc/controller/controller_mouse.h index 877f5d30..db98c456 100644 --- a/src/pc/controller/controller_mouse.h +++ b/src/pc/controller/controller_mouse.h @@ -14,6 +14,8 @@ extern u32 mouse_window_buttons; extern s32 mouse_window_x; extern s32 mouse_window_y; +extern bool mouse_relative_enabled; + void controller_mouse_read_window(void); void controller_mouse_read_relative(void); diff --git a/src/pc/djui/djui_hud_utils.c b/src/pc/djui/djui_hud_utils.c index bbf7e948..f43dd454 100644 --- a/src/pc/djui/djui_hud_utils.c +++ b/src/pc/djui/djui_hud_utils.c @@ -19,6 +19,7 @@ #include "game/camera.h" #include "game/hud.h" #include "game/rendering_graph_node.h" +#include "game/first_person_cam.h" #include "pc/lua/smlua.h" #include "engine/math_util.h" @@ -592,8 +593,9 @@ bool djui_hud_world_pos_to_screen_pos(Vec3f pos, Vec3f out) { out[1] *= 256.0f / out[2]; // fov of 45.0 is the default fov - f32 fovDefault = tanf(not_zero(45.0f, gOverrideFOV) * ((f32)M_PI / 360.0f)); - f32 fovCurrent = tanf((gFOVState.fov + gFOVState.fovOffset) * ((f32)M_PI / 360.0f)); + f32 fov = get_first_person_enabled() ? gFirstPersonCamera.fov : not_zero(45.0f, gOverrideFOV); + f32 fovDefault = tanf(fov * ((f32)M_PI / 360.0f)); + f32 fovCurrent = tanf((fov + gFOVState.fovOffset) * ((f32)M_PI / 360.0f)); f32 fovDifference = (fovDefault / fovCurrent) * 1.13f;