Revert "Rework First Person FOV"

This reverts commit 2a0af8e216.
This commit is contained in:
Agent X 2023-12-18 14:27:48 -05:00
parent f959ffaeb6
commit 4e96b49182
14 changed files with 68 additions and 20 deletions

View File

@ -115,7 +115,7 @@ override_disallowed_functions = {
"src/pc/lua/utils/smlua_text_utils.h": [ "smlua_text_utils_reset_all" ],
"src/pc/lua/utils/smlua_anim_utils.h": [ "smlua_anim_util_reset", "smlua_anim_util_register_animation" ],
"src/pc/network/lag_compensation.h": [ "lag_compensation_clear", "lag_compensation_store" ],
"src/game/first_person_cam.h": [ "first_person_update", "get_dest_fov", "get_dest_near" ]
"src/game/first_person_cam.h": [ "first_person_update" ]
}
override_hide_functions = {

View File

@ -113,7 +113,8 @@ override_field_immutable = {
"ObjectWarpNode": [ "next "],
"Animation": [ "length" ],
"AnimationTable": [ "count" ],
"Controller": [ "controllerData", "statusData" ]
"Controller": [ "controllerData", "statusData" ],
"FirstPersonCamera": [ "enabled" ],
}
override_field_version_excludes = {

View File

@ -4016,6 +4016,12 @@ function get_first_person_enabled()
-- ...
end
--- @param enable boolean
--- @return nil
function set_first_person_enabled(enable)
-- ...
end
--- @return nil
function reset_dialog_override_color()
-- ...

View File

@ -595,6 +595,7 @@
--- @field public crouch number
--- @field public enabled boolean
--- @field public forceRoll boolean
--- @field public fov number
--- @field public offset Vec3f
--- @field public pitch integer
--- @field public yaw integer

View File

@ -3322,6 +3322,26 @@
<br />
## [set_first_person_enabled](#set_first_person_enabled)
### Lua Example
`set_first_person_enabled(enable)`
### Parameters
| Field | Type |
| ----- | ---- |
| enable | `boolean` |
### Returns
- None
### C Prototype
`void set_first_person_enabled(bool enable);`
[:arrow_up_small:](#)
<br />
---
# functions from ingame_menu.h

View File

@ -803,6 +803,7 @@
- [first_person_check_cancels](functions-3.md#first_person_check_cancels)
- [first_person_reset](functions-3.md#first_person_reset)
- [get_first_person_enabled](functions-3.md#get_first_person_enabled)
- [set_first_person_enabled](functions-3.md#set_first_person_enabled)
<br />

View File

@ -848,8 +848,9 @@
| ----- | ---- | ------ |
| centerL | `boolean` | |
| crouch | `number` | |
| enabled | `boolean` | |
| enabled | `boolean` | read-only |
| forceRoll | `boolean` | |
| fov | `number` | |
| offset | [Vec3f](structs.md#Vec3f) | read-only |
| pitch | `integer` | |
| yaw | `integer` | |

View File

@ -9,7 +9,6 @@
#include "mario.h"
#include "hardcoded.h"
#include "save_file.h"
#include "rendering_graph_node.h"
#include "engine/math_util.h"
@ -28,6 +27,7 @@ struct FirstPersonCamera gFirstPersonCamera = {
.pitch = 0,
.yaw = 0,
.crouch = 0,
.fov = FIRST_PERSON_DEFAULT_FOV,
.offset = { 0, 0, 0 }
};
@ -54,12 +54,9 @@ bool get_first_person_enabled(void) {
return gFirstPersonCamera.enabled && !first_person_check_cancels(&gMarioStates[0]);
}
f32 get_dest_fov(f32 fov) {
return get_first_person_enabled() ? FIRST_PERSON_DEFAULT_FOV : not_zero(fov, gOverrideFOV);
}
f32 get_dest_near(f32 near) {
return get_first_person_enabled() ? 1 : not_zero(near, gOverrideNear);
void set_first_person_enabled(bool enable) {
if (gFirstPersonCamera.enabled && !enable) { gFOVState.fov = 45.0f; }
gFirstPersonCamera.enabled = enable;
}
void first_person_camera_update(void) {
@ -146,6 +143,8 @@ 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) {
@ -193,6 +192,7 @@ void first_person_reset(void) {
gFirstPersonCamera.pitch = 0;
gFirstPersonCamera.yaw = 0;
gFirstPersonCamera.crouch = 0;
gFirstPersonCamera.fov = FIRST_PERSON_DEFAULT_FOV;
gFirstPersonCamera.offset[0] = 0;
gFirstPersonCamera.offset[1] = 0;
gFirstPersonCamera.offset[2] = 0;

View File

@ -15,6 +15,7 @@ struct FirstPersonCamera {
s16 pitch;
s16 yaw;
f32 crouch;
f32 fov;
Vec3f offset;
};
@ -23,9 +24,7 @@ extern struct FirstPersonCamera gFirstPersonCamera;
bool first_person_check_cancels(struct MarioState *m);
bool get_first_person_enabled(void);
f32 get_dest_fov(f32 fov);
f32 get_dest_near(f32 near);
void set_first_person_enabled(bool enable);
void first_person_update(void);
void first_person_reset(void);

View File

@ -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, get_dest_fov(fovInterpolated), sPerspectiveAspect, get_dest_near(near), not_zero(sPerspectiveNode->far, gOverrideFar), 1.0f);
guPerspective(sPerspectiveMtx, &perspNorm, 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);
}
@ -488,7 +488,7 @@ static void geo_process_perspective(struct GraphNodePerspective *node) {
gProjectionVanillaNearValue = node->near;
gProjectionVanillaFarValue = node->far;
f32 near = MIN(node->near, gProjectionMaxNearValue);
guPerspective(mtx, &perspNorm, get_dest_fov(node->prevFov), aspect, get_dest_near(near), not_zero(node->far, gOverrideFar), 1.0f);
guPerspective(mtx, &perspNorm, not_zero(node->prevFov, gOverrideFOV), aspect, get_first_person_enabled() ? 1 : not_zero(near, gOverrideNear), not_zero(node->far, gOverrideFar), 1.0f);
sPerspectiveNode = node;
sPerspectiveMtx = mtx;
@ -1156,7 +1156,7 @@ static s32 obj_is_in_view(struct GraphNodeObject *node, Mat4 matrix) {
// visibly pop in or out at the edge of the screen.
//
// Half of the fov in in-game angle units instead of degrees.
s16 halfFov = (get_dest_fov(gCurGraphNodeCamFrustum->fov) / 2.0f + 1.0f) * 32768.0f / 180.0f + 0.5f;
s16 halfFov = (not_zero(gCurGraphNodeCamFrustum->fov, gOverrideFOV) / 2.0f + 1.0f) * 32768.0f / 180.0f + 0.5f;
f32 divisor = coss(halfFov);
if (divisor == 0) { divisor = 1; }

View File

@ -20,7 +20,6 @@
#include "game/camera.h"
#include "game/hud.h"
#include "game/rendering_graph_node.h"
#include "game/first_person_cam.h"
#include "engine/math_util.h"
@ -579,7 +578,7 @@ 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(get_dest_fov(45.0f) * ((f32)M_PI / 360.0f));
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 fovDifference = (fovDefault / fovCurrent) * 1.13f;

View File

@ -674,12 +674,13 @@ 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 7
#define LUA_FIRST_PERSON_CAMERA_FIELD_COUNT 8
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), 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 },

View File

@ -13231,6 +13231,23 @@ int smlua_func_get_first_person_enabled(UNUSED lua_State* L) {
return 1;
}
int smlua_func_set_first_person_enabled(lua_State* L) {
if (L == NULL) { return 0; }
int top = lua_gettop(L);
if (top != 1) {
LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "set_first_person_enabled", 1, top);
return 0;
}
bool enable = smlua_to_boolean(L, 1);
if (!gSmLuaConvertSuccess) { LOG_LUA("Failed to convert parameter %u for function '%s'", 1, "set_first_person_enabled"); return 0; }
set_first_person_enabled(enable);
return 1;
}
///////////////////
// ingame_menu.h //
///////////////////
@ -32059,6 +32076,7 @@ void smlua_bind_functions_autogen(void) {
smlua_bind_function(L, "first_person_check_cancels", smlua_func_first_person_check_cancels);
smlua_bind_function(L, "first_person_reset", smlua_func_first_person_reset);
smlua_bind_function(L, "get_first_person_enabled", smlua_func_get_first_person_enabled);
smlua_bind_function(L, "set_first_person_enabled", smlua_func_set_first_person_enabled);
// ingame_menu.h
smlua_bind_function(L, "reset_dialog_override_color", smlua_func_reset_dialog_override_color);

View File

@ -708,6 +708,7 @@ void network_shutdown(bool sendLeaving, bool exiting, bool popup, bool reconnect
cnt->extStickY = 0;
gFirstPersonCamera.enabled = false;
gFirstPersonCamera.fov = FIRST_PERSON_DEFAULT_FOV;
first_person_reset();
extern void save_file_load_all(UNUSED u8 reload);