From 60b9e43604dd59b3af876155669e0e9dd0ae16c5 Mon Sep 17 00:00:00 2001 From: Agent X <44549182+AgentXLP@users.noreply.github.com> Date: Thu, 11 Jul 2024 23:10:51 -0400 Subject: [PATCH] Fix first person a little and add pitch forcing --- autogen/lua_definitions/structs.lua | 1 + docs/lua/structs.md | 1 + src/game/first_person_cam.c | 7 +++++-- src/game/first_person_cam.h | 1 + src/pc/lua/smlua_cobject_autogen.c | 19 ++++++++++--------- src/pc/network/network.c | 5 +++++ 6 files changed, 23 insertions(+), 11 deletions(-) diff --git a/autogen/lua_definitions/structs.lua b/autogen/lua_definitions/structs.lua index c63b42a6..050cef42 100644 --- a/autogen/lua_definitions/structs.lua +++ b/autogen/lua_definitions/structs.lua @@ -593,6 +593,7 @@ --- @field public centerL boolean --- @field public crouch number --- @field public enabled boolean +--- @field public forcePitch boolean --- @field public forceRoll boolean --- @field public fov number --- @field public offset Vec3f diff --git a/docs/lua/structs.md b/docs/lua/structs.md index 9baf2b7e..d5e10146 100644 --- a/docs/lua/structs.md +++ b/docs/lua/structs.md @@ -850,6 +850,7 @@ | centerL | `boolean` | | | crouch | `number` | | | enabled | `boolean` | read-only | +| forcePitch | `boolean` | | | forceRoll | `boolean` | | | fov | `number` | | | offset | [Vec3f](structs.md#Vec3f) | read-only | diff --git a/src/game/first_person_cam.c b/src/game/first_person_cam.c index 07fb90da..f6f20894 100644 --- a/src/game/first_person_cam.c +++ b/src/game/first_person_cam.c @@ -23,6 +23,7 @@ struct FirstPersonCamera gFirstPersonCamera = { .enabled = false, .forceRoll = true, + .forcePitch = false, .centerL = true, .pitch = 0, .yaw = 0, @@ -68,8 +69,10 @@ static void first_person_camera_update(void) { if (mouse_relative_enabled) { // update pitch - gFirstPersonCamera.pitch -= sensY * (invY * m->controller->extStickY - 1.5f * mouse_y); - gFirstPersonCamera.pitch = CLAMP(gFirstPersonCamera.pitch, -0x3F00, 0x3F00); + if (!gFirstPersonCamera.forcePitch) { + gFirstPersonCamera.pitch -= sensY * (invY * m->controller->extStickY - 1.5f * mouse_y); + gFirstPersonCamera.pitch = CLAMP(gFirstPersonCamera.pitch, -0x3F00, 0x3F00); + } // update yaw if (m->controller->buttonPressed & L_TRIG && gFirstPersonCamera.centerL) { diff --git a/src/game/first_person_cam.h b/src/game/first_person_cam.h index 64a858d7..285b6a34 100644 --- a/src/game/first_person_cam.h +++ b/src/game/first_person_cam.h @@ -11,6 +11,7 @@ struct FirstPersonCamera { bool enabled; bool forceRoll; + bool forcePitch; bool centerL; s16 pitch; s16 yaw; diff --git a/src/pc/lua/smlua_cobject_autogen.c b/src/pc/lua/smlua_cobject_autogen.c index a81a09b8..d8ac4073 100644 --- a/src/pc/lua/smlua_cobject_autogen.c +++ b/src/pc/lua/smlua_cobject_autogen.c @@ -676,16 +676,17 @@ static struct LuaObjectField sDjuiColorFields[LUA_DJUI_COLOR_FIELD_COUNT] = { { "r", LVT_U8, offsetof(struct DjuiColor, r), false, LOT_NONE }, }; -#define LUA_FIRST_PERSON_CAMERA_FIELD_COUNT 8 +#define LUA_FIRST_PERSON_CAMERA_FIELD_COUNT 9 static struct LuaObjectField sFirstPersonCameraFields[LUA_FIRST_PERSON_CAMERA_FIELD_COUNT] = { - { "centerL", LVT_BOOL, offsetof(struct FirstPersonCamera, centerL), false, LOT_NONE }, - { "crouch", LVT_F32, offsetof(struct FirstPersonCamera, crouch), false, LOT_NONE }, - { "enabled", LVT_BOOL, offsetof(struct FirstPersonCamera, enabled), true, LOT_NONE }, - { "forceRoll", LVT_BOOL, offsetof(struct FirstPersonCamera, forceRoll), false, LOT_NONE }, - { "fov", LVT_F32, offsetof(struct FirstPersonCamera, fov), false, LOT_NONE }, - { "offset", LVT_COBJECT, offsetof(struct FirstPersonCamera, offset), true, LOT_VEC3F }, - { "pitch", LVT_S16, offsetof(struct FirstPersonCamera, pitch), false, LOT_NONE }, - { "yaw", LVT_S16, offsetof(struct FirstPersonCamera, yaw), false, LOT_NONE }, + { "centerL", LVT_BOOL, offsetof(struct FirstPersonCamera, centerL), false, LOT_NONE }, + { "crouch", LVT_F32, offsetof(struct FirstPersonCamera, crouch), false, LOT_NONE }, + { "enabled", LVT_BOOL, offsetof(struct FirstPersonCamera, enabled), true, LOT_NONE }, + { "forcePitch", LVT_BOOL, offsetof(struct FirstPersonCamera, forcePitch), false, LOT_NONE }, + { "forceRoll", LVT_BOOL, offsetof(struct FirstPersonCamera, forceRoll), false, LOT_NONE }, + { "fov", LVT_F32, offsetof(struct FirstPersonCamera, fov), false, LOT_NONE }, + { "offset", LVT_COBJECT, offsetof(struct FirstPersonCamera, offset), true, LOT_VEC3F }, + { "pitch", LVT_S16, offsetof(struct FirstPersonCamera, pitch), false, LOT_NONE }, + { "yaw", LVT_S16, offsetof(struct FirstPersonCamera, yaw), false, LOT_NONE }, }; #define LUA_FLOOR_GEOMETRY_FIELD_COUNT 4 diff --git a/src/pc/network/network.c b/src/pc/network/network.c index ab43fcd9..8749ee55 100644 --- a/src/pc/network/network.c +++ b/src/pc/network/network.c @@ -33,6 +33,7 @@ #include "game/ingame_menu.h" #include "game/first_person_cam.h" #include "game/envfx_snow.h" +#include "engine/math_util.h" #ifdef DISCORD_SDK #include "pc/discord/discord.h" @@ -721,7 +722,11 @@ void network_shutdown(bool sendLeaving, bool exiting, bool popup, bool reconnect cnt->extStickY = 0; gFirstPersonCamera.enabled = false; + gFirstPersonCamera.forceRoll = false; + gFirstPersonCamera.forcePitch = false; + gFirstPersonCamera.centerL = true; gFirstPersonCamera.fov = FIRST_PERSON_DEFAULT_FOV; + vec3f_set(gFirstPersonCamera.offset, 0, 0, 0); first_person_reset(); extern void save_file_load_all(UNUSED u8 reload);