Fix first person a little and add pitch forcing

This commit is contained in:
Agent X 2024-07-11 23:10:51 -04:00
parent fe0c766e76
commit 60b9e43604
6 changed files with 23 additions and 11 deletions

View File

@ -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

View File

@ -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 |

View File

@ -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) {

View File

@ -11,6 +11,7 @@
struct FirstPersonCamera {
bool enabled;
bool forceRoll;
bool forcePitch;
bool centerL;
s16 pitch;
s16 yaw;

View File

@ -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

View File

@ -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);