Skip to content

Commit

Permalink
Fix free cam bug on lon lon crates (and possibly other dynamic collis…
Browse files Browse the repository at this point in the history
…ion) (#682)

* Fix free cam bug on lon lon crates (and likely other dynamic collision)

* Run automatic format script as code does not match clang format rules.

Developers please rebase to avoid merge conflicts!

---------

Co-authored-by: Roberto-Nessy <[email protected]>
  • Loading branch information
Roberto-Nessy and Roberto-Nessy committed Jun 8, 2023
1 parent fe22ab0 commit 0e25215
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 15 deletions.
17 changes: 17 additions & 0 deletions code/include/z3D/z3D.h
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,19 @@ typedef struct {
/* 0x04 */ char unk_04[0x4C];
} StaticCollisionContext; // size = 0x50

typedef struct {
/* 0x00 */ Actor* actor;
/* 0x04 */ CollisionHeader* colHeader;
/* 0x08 */ char unk_04[0x0C];
/* 0x14 */ Vec3f scale1;
/* 0x20 */ Vec3s rot1;
/* 0x28 */ Vec3f pos1;
/* 0x34 */ Vec3f scale2;
/* 0x40 */ Vec3s rot2;
/* 0x48 */ Vec3f pos2;
/* 0x54 */ char unk_54[0x18];
} ActorMesh; // size = 0x6C

typedef struct {
/* 0x0000 */ char unk_00[0x04];
/* 0x0004 */ ActorMesh actorMeshArr[50];
Expand Down Expand Up @@ -816,6 +829,10 @@ typedef u32 (*PauseContext_GetState_proc)(void);
typedef s32 (*Camera_CheckWater_proc)(Camera* camera);
#define Camera_CheckWater ((Camera_CheckWater_proc)0x2D06A0)

typedef f32 (*BgCheck_EntityRaycastFloor5_proc)(GlobalContext* globalCtx, CollisionContext* colCtx,
CollisionPoly** floorPoly, s16* bgId, Player* player, Vec3f* playerPos);
#define BgCheck_EntityRaycastFloor5 ((BgCheck_EntityRaycastFloor5_proc)0x316C18)

typedef void (*Camera_UpdateInterface_proc)(u32 flags);
#define Camera_UpdateInterface ((Camera_UpdateInterface_proc)0x330D84)

Expand Down
12 changes: 0 additions & 12 deletions code/include/z3D/z3Dactor.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,18 +248,6 @@ typedef struct DynaPolyActor {
/* 0x1BA */ s16 unk_1BA;
} DynaPolyActor; // size = 0x1BC

typedef struct {
/* 0x00 */ Actor* actor;
/* 0x04 */ char unk_04[0x10];
/* 0x14 */ Vec3f scale1;
/* 0x20 */ Vec3s rot1;
/* 0x28 */ Vec3f pos1;
/* 0x34 */ Vec3f scale2;
/* 0x40 */ Vec3s rot2;
/* 0x48 */ Vec3f pos2;
/* 0x54 */ char unk_54[0x18];
} ActorMesh; // size = 0x6C

typedef struct {
/* 0x0000 */ Actor actor;
/* 0x01A4 */ char unk_148[0x0005];
Expand Down
21 changes: 18 additions & 3 deletions code/src/camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,24 @@ void Camera_FreeCamUpdate(Vec3s* out, Camera* camera) {
out->y = camera->inputDir.y = camera->camDir.y = yaw;
out->z = camera->inputDir.z = camera->camDir.z = 0;

// Pretty much entirely to let the alcoves in SpT reclaim control of the camera
s16 newCamDataIdx = Camera_GetCamDataId(&camera->globalCtx->colCtx, camera->player->actor.floorPoly, 0x32);
s16 newSetting = camera->globalCtx->colCtx.stat.colHeader->camDataList[newCamDataIdx].setting;
// Update camera setting
CollisionPoly* floorPoly;
s16 newSetting;
Vec3f headPos;
headPos.x = camera->player->actor.world.pos.x;
headPos.y = camera->player->actor.world.pos.y + (gSaveContext.linkAge ? 44 : 68);
headPos.z = camera->player->actor.world.pos.z;

camera->playerGroundY = BgCheck_EntityRaycastFloor5(camera->globalCtx, &camera->globalCtx->colCtx, &floorPoly,
&camera->bgCheckId, camera->player, &headPos);
s16 newCamDataIdx = Camera_GetCamDataId(&camera->globalCtx->colCtx, floorPoly, camera->bgCheckId);
if (camera->bgCheckId == 0x32)
newSetting = camera->globalCtx->colCtx.stat.colHeader->camDataList[newCamDataIdx].setting;
else
newSetting = camera->globalCtx->colCtx.dyna.actorMeshArr[camera->bgCheckId]
.colHeader->camDataList[newCamDataIdx]
.setting;

if (newCamDataIdx != -1 && newSetting && (newSetting != 0x35 || gSaveContext.linkAge)) {
camera->camDataIdx = newCamDataIdx;
if (newSetting != camera->setting) {
Expand Down

0 comments on commit 0e25215

Please sign in to comment.