diff --git a/autogen/lua_definitions/structs.lua b/autogen/lua_definitions/structs.lua index 4658382d..75020866 100644 --- a/autogen/lua_definitions/structs.lua +++ b/autogen/lua_definitions/structs.lua @@ -595,6 +595,7 @@ --- @field public enabled boolean --- @field public forceRoll boolean --- @field public fov number +--- @field public offset Vec3f --- @field public pitch integer --- @field public yaw integer diff --git a/docs/lua/structs.md b/docs/lua/structs.md index ebe2422c..ab5907ba 100644 --- a/docs/lua/structs.md +++ b/docs/lua/structs.md @@ -850,6 +850,7 @@ | enabled | `boolean` | read-only | | forceRoll | `boolean` | | | fov | `number` | | +| offset | [Vec3f](structs.md#Vec3f) | read-only | | pitch | `integer` | | | yaw | `integer` | | diff --git a/src/game/first_person_cam.c b/src/game/first_person_cam.c index 9afe47d1..a6189381 100644 --- a/src/game/first_person_cam.c +++ b/src/game/first_person_cam.c @@ -24,7 +24,8 @@ struct FirstPersonCamera gFirstPersonCamera = { .pitch = 0, .yaw = 0, .crouch = 0, - .fov = FIRST_PERSON_DEFAULT_FOV + .fov = FIRST_PERSON_DEFAULT_FOV, + .offset = { 0, 0, 0 } }; extern s16 gMenuMode; @@ -114,17 +115,17 @@ void first_person_camera_update(void) { } // update pos - gLakituState.pos[0] = m->pos[0] + coss(gFirstPersonCamera.pitch) * sins(gFirstPersonCamera.yaw); - gLakituState.pos[1] = m->pos[1] + sins(gFirstPersonCamera.pitch) + (FIRST_PERSON_MARIO_HEAD_POS - gFirstPersonCamera.crouch); - gLakituState.pos[2] = m->pos[2] + coss(gFirstPersonCamera.pitch) * coss(gFirstPersonCamera.yaw); + gLakituState.pos[0] = (m->pos[0] + gFirstPersonCamera.offset[0]) + coss(gFirstPersonCamera.pitch) * sins(gFirstPersonCamera.yaw); + gLakituState.pos[1] = (m->pos[1] + gFirstPersonCamera.offset[1]) + sins(gFirstPersonCamera.pitch) + (FIRST_PERSON_MARIO_HEAD_POS - gFirstPersonCamera.crouch); + gLakituState.pos[2] = (m->pos[2] + gFirstPersonCamera.offset[2]) + coss(gFirstPersonCamera.pitch) * coss(gFirstPersonCamera.yaw); vec3f_copy(m->area->camera->pos, gLakituState.pos); vec3f_copy(gLakituState.curPos, gLakituState.pos); vec3f_copy(gLakituState.goalPos, gLakituState.pos); // update focus - gLakituState.focus[0] = m->pos[0] - 100 * coss(gFirstPersonCamera.pitch) * sins(gFirstPersonCamera.yaw); - gLakituState.focus[1] = m->pos[1] - 100 * sins(gFirstPersonCamera.pitch) + (FIRST_PERSON_MARIO_HEAD_POS - gFirstPersonCamera.crouch); - gLakituState.focus[2] = m->pos[2] - 100 * coss(gFirstPersonCamera.pitch) * coss(gFirstPersonCamera.yaw); + gLakituState.focus[0] = (m->pos[0] + gFirstPersonCamera.offset[0]) - 100 * coss(gFirstPersonCamera.pitch) * sins(gFirstPersonCamera.yaw); + gLakituState.focus[1] = (m->pos[1] + gFirstPersonCamera.offset[1]) - 100 * sins(gFirstPersonCamera.pitch) + (FIRST_PERSON_MARIO_HEAD_POS - gFirstPersonCamera.crouch); + gLakituState.focus[2] = (m->pos[2] + gFirstPersonCamera.offset[2]) - 100 * coss(gFirstPersonCamera.pitch) * coss(gFirstPersonCamera.yaw); vec3f_copy(m->area->camera->focus, gLakituState.focus); vec3f_copy(gLakituState.curFocus, gLakituState.focus); vec3f_copy(gLakituState.goalFocus, gLakituState.focus); @@ -174,7 +175,12 @@ void first_person_update(void) { } void first_person_reset(void) { + gFirstPersonCamera.forceRoll = false; 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; } diff --git a/src/game/first_person_cam.h b/src/game/first_person_cam.h index 5c659ba3..c8429ec1 100644 --- a/src/game/first_person_cam.h +++ b/src/game/first_person_cam.h @@ -15,6 +15,7 @@ struct FirstPersonCamera { s16 yaw; f32 crouch; f32 fov; + Vec3f offset; }; extern struct FirstPersonCamera gFirstPersonCamera; diff --git a/src/pc/lua/smlua_cobject_autogen.c b/src/pc/lua/smlua_cobject_autogen.c index a24172ab..af7a23e7 100644 --- a/src/pc/lua/smlua_cobject_autogen.c +++ b/src/pc/lua/smlua_cobject_autogen.c @@ -674,14 +674,15 @@ 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 6 +#define LUA_FIRST_PERSON_CAMERA_FIELD_COUNT 7 static struct LuaObjectField sFirstPersonCameraFields[LUA_FIRST_PERSON_CAMERA_FIELD_COUNT] = { - { "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 }, - { "pitch", LVT_S16, offsetof(struct FirstPersonCamera, pitch), false, LOT_NONE }, - { "yaw", LVT_S16, offsetof(struct FirstPersonCamera, yaw), 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 }, }; #define LUA_FLOOR_GEOMETRY_FIELD_COUNT 4