Rework First Person FOV
This commit is contained in:
parent
6419e53297
commit
2a0af8e216
|
@ -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" ]
|
||||
"src/game/first_person_cam.h": [ "first_person_update", "get_dest_fov", "get_dest_near" ]
|
||||
}
|
||||
|
||||
override_hide_functions = {
|
||||
|
|
|
@ -113,8 +113,7 @@ override_field_immutable = {
|
|||
"ObjectWarpNode": [ "next "],
|
||||
"Animation": [ "length" ],
|
||||
"AnimationTable": [ "count" ],
|
||||
"Controller": [ "controllerData", "statusData" ],
|
||||
"FirstPersonCamera": [ "enabled" ],
|
||||
"Controller": [ "controllerData", "statusData" ]
|
||||
}
|
||||
|
||||
override_field_version_excludes = {
|
||||
|
|
|
@ -4016,12 +4016,6 @@ 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()
|
||||
-- ...
|
||||
|
|
|
@ -595,7 +595,6 @@
|
|||
--- @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
|
||||
|
|
|
@ -3322,26 +3322,6 @@
|
|||
|
||||
<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
|
||||
|
||||
|
|
|
@ -803,7 +803,6 @@
|
|||
- [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 />
|
||||
|
||||
|
|
|
@ -848,9 +848,8 @@
|
|||
| ----- | ---- | ------ |
|
||||
| centerL | `boolean` | |
|
||||
| crouch | `number` | |
|
||||
| enabled | `boolean` | read-only |
|
||||
| enabled | `boolean` | |
|
||||
| forceRoll | `boolean` | |
|
||||
| fov | `number` | |
|
||||
| offset | [Vec3f](structs.md#Vec3f) | read-only |
|
||||
| pitch | `integer` | |
|
||||
| yaw | `integer` | |
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "mario.h"
|
||||
#include "hardcoded.h"
|
||||
#include "save_file.h"
|
||||
#include "rendering_graph_node.h"
|
||||
|
||||
#include "engine/math_util.h"
|
||||
|
||||
|
@ -27,7 +28,6 @@ struct FirstPersonCamera gFirstPersonCamera = {
|
|||
.pitch = 0,
|
||||
.yaw = 0,
|
||||
.crouch = 0,
|
||||
.fov = FIRST_PERSON_DEFAULT_FOV,
|
||||
.offset = { 0, 0, 0 }
|
||||
};
|
||||
|
||||
|
@ -54,9 +54,12 @@ bool get_first_person_enabled(void) {
|
|||
return gFirstPersonCamera.enabled && !first_person_check_cancels(&gMarioStates[0]);
|
||||
}
|
||||
|
||||
void set_first_person_enabled(bool enable) {
|
||||
if (gFirstPersonCamera.enabled && !enable) { gFOVState.fov = 45.0f; }
|
||||
gFirstPersonCamera.enabled = enable;
|
||||
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 first_person_camera_update(void) {
|
||||
|
@ -143,8 +146,6 @@ 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) {
|
||||
|
@ -192,7 +193,6 @@ 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;
|
||||
|
|
|
@ -15,7 +15,6 @@ struct FirstPersonCamera {
|
|||
s16 pitch;
|
||||
s16 yaw;
|
||||
f32 crouch;
|
||||
f32 fov;
|
||||
Vec3f offset;
|
||||
};
|
||||
|
||||
|
@ -24,7 +23,9 @@ extern struct FirstPersonCamera gFirstPersonCamera;
|
|||
bool first_person_check_cancels(struct MarioState *m);
|
||||
|
||||
bool get_first_person_enabled(void);
|
||||
void set_first_person_enabled(bool enable);
|
||||
|
||||
f32 get_dest_fov(f32 fov);
|
||||
f32 get_dest_near(f32 near);
|
||||
|
||||
void first_person_update(void);
|
||||
void first_person_reset(void);
|
||||
|
|
|
@ -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_dest_fov(fovInterpolated), sPerspectiveAspect, get_dest_near(near), 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, not_zero(node->prevFov, gOverrideFOV), aspect, get_first_person_enabled() ? 1 : not_zero(near, gOverrideNear), not_zero(node->far, gOverrideFar), 1.0f);
|
||||
guPerspective(mtx, &perspNorm, get_dest_fov(node->prevFov), aspect, get_dest_near(near), 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 = (not_zero(gCurGraphNodeCamFrustum->fov, gOverrideFOV) / 2.0f + 1.0f) * 32768.0f / 180.0f + 0.5f;
|
||||
s16 halfFov = (get_dest_fov(gCurGraphNodeCamFrustum->fov) / 2.0f + 1.0f) * 32768.0f / 180.0f + 0.5f;
|
||||
|
||||
f32 divisor = coss(halfFov);
|
||||
if (divisor == 0) { divisor = 1; }
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#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"
|
||||
|
||||
|
@ -578,7 +579,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(not_zero(45.0f, gOverrideFOV) * ((f32)M_PI / 360.0f));
|
||||
f32 fovDefault = tanf(get_dest_fov(45.0f) * ((f32)M_PI / 360.0f));
|
||||
f32 fovCurrent = tanf((gFOVState.fov + gFOVState.fovOffset) * ((f32)M_PI / 360.0f));
|
||||
|
||||
f32 fovDifference = (fovDefault / fovCurrent) * 1.13f;
|
||||
|
|
|
@ -674,13 +674,12 @@ 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 7
|
||||
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 },
|
||||
{ "enabled", LVT_BOOL, offsetof(struct FirstPersonCamera, enabled), 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 },
|
||||
|
|
|
@ -13231,23 +13231,6 @@ 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 //
|
||||
///////////////////
|
||||
|
@ -32076,7 +32059,6 @@ 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);
|
||||
|
|
|
@ -708,7 +708,6 @@ 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);
|
||||
|
|
Loading…
Reference in New Issue