From 1e03f0228990289ab84fddbdaed475e318cdeb76 Mon Sep 17 00:00:00 2001 From: Phillip Stephens Date: Mon, 9 Jan 2023 22:51:58 -0800 Subject: [PATCH] Start CCollidableAABox, add CPlayerCameraBob Former-commit-id: 749dec6b1ef67f852f0d26d3773ad8986d2cb8c4 --- asm/Collision/CCollidableAABox.s | 1 - asm/MetroidPrime/CStateManager.s | 2 +- asm/MetroidPrime/Player/CPlayer.s | 4 +- asm/MetroidPrime/Player/CPlayerCameraBob.s | 150 +++++++++--------- configure.py | 4 +- include/Collision/CCollidableAABox.hpp | 27 +++- .../Collision/CInternalCollisionStructure.hpp | 38 +++++ .../Collision/CInternalRayCastStructure.hpp | 29 ++++ include/Collision/CMRay.hpp | 5 + include/Collision/CRayCastResult.hpp | 25 ++- include/Collision/CollisionUtil.hpp | 19 +-- include/Collision/NormalTable.hpp | 15 ++ include/Kyoto/Math/CUnitVector3f.hpp | 2 +- .../MetroidPrime/Player/CPlayerCameraBob.hpp | 17 +- src/Collision/CCollidableAABox.cpp | 88 ++++++++++ src/Collision/CollisionUtil.cpp | 2 + src/MetroidPrime/Player/CPlayerCameraBob.cpp | 76 +++++++++ 17 files changed, 392 insertions(+), 112 deletions(-) create mode 100644 include/Collision/CInternalCollisionStructure.hpp create mode 100644 include/Collision/CInternalRayCastStructure.hpp create mode 100644 include/Collision/NormalTable.hpp create mode 100644 src/MetroidPrime/Player/CPlayerCameraBob.cpp diff --git a/asm/Collision/CCollidableAABox.s b/asm/Collision/CCollidableAABox.s index 0c57417b..4697d425 100644 --- a/asm/Collision/CCollidableAABox.s +++ b/asm/Collision/CCollidableAABox.s @@ -28,7 +28,6 @@ __vt__16CCollidableAABox: sTableIndex__16CCollidableAABox: # ROM: 0x3F6088 .4byte 0xFFFFFFFF - .4byte 0 .section .bss .balign 8 diff --git a/asm/MetroidPrime/CStateManager.s b/asm/MetroidPrime/CStateManager.s index d8403eb2..ce861b2c 100644 --- a/asm/MetroidPrime/CStateManager.s +++ b/asm/MetroidPrime/CStateManager.s @@ -8305,7 +8305,7 @@ PreThinkObjects__13CStateManagerFf: /* 8004AC1C 00047B7C FC 02 00 40 */ fcmpo cr0, f2, f0 /* 8004AC20 00047B80 40 81 00 10 */ ble lbl_8004AC30 /* 8004AC24 00047B84 7F 64 DB 78 */ mr r4, r27 -/* 8004AC28 00047B88 4B FC 6D 59 */ bl DoPreThink__7CPlayerfRC13CStateManager +/* 8004AC28 00047B88 4B FC 6D 59 */ bl DoPreThink__7CPlayerFfRC13CStateManager /* 8004AC2C 00047B8C 48 00 01 00 */ b lbl_8004AD2C lbl_8004AC30: /* 8004AC30 00047B90 80 1B 09 04 */ lwz r0, 0x904(r27) diff --git a/asm/MetroidPrime/Player/CPlayer.s b/asm/MetroidPrime/Player/CPlayer.s index 6acaffb9..bf0630da 100644 --- a/asm/MetroidPrime/Player/CPlayer.s +++ b/asm/MetroidPrime/Player/CPlayer.s @@ -2650,8 +2650,8 @@ lbl_80011970: /* 80011978 0000E8D8 90 03 0A 10 */ stw r0, 0xa10(r3) /* 8001197C 0000E8DC 4E 80 00 20 */ blr -.global DoPreThink__7CPlayerfRC13CStateManager -DoPreThink__7CPlayerfRC13CStateManager: +.global DoPreThink__7CPlayerFfRC13CStateManager +DoPreThink__7CPlayerFfRC13CStateManager: /* 80011980 0000E8E0 94 21 FF E0 */ stwu r1, -0x20(r1) /* 80011984 0000E8E4 7C 08 02 A6 */ mflr r0 /* 80011988 0000E8E8 90 01 00 24 */ stw r0, 0x24(r1) diff --git a/asm/MetroidPrime/Player/CPlayerCameraBob.s b/asm/MetroidPrime/Player/CPlayerCameraBob.s index a4f8705e..1d24eeb6 100644 --- a/asm/MetroidPrime/Player/CPlayerCameraBob.s +++ b/asm/MetroidPrime/Player/CPlayerCameraBob.s @@ -10,27 +10,27 @@ lbl_ctor: .global kCameraBobExtentX__16CPlayerCameraBob kCameraBobExtentX__16CPlayerCameraBob: # ROM: 0x3F4D18 - .4byte 0x3D916873 + .float 0.071 .global kCameraBobExtentY__16CPlayerCameraBob kCameraBobExtentY__16CPlayerCameraBob: # ROM: 0x3F4D1C - .4byte 0x3E116873 + .float 0.142 .global kCameraBobPeriod__16CPlayerCameraBob kCameraBobPeriod__16CPlayerCameraBob: # ROM: 0x3F4D20 - .4byte 0x3EF0A3D7 + .float 0.47 .global kOrbitBobScale__16CPlayerCameraBob kOrbitBobScale__16CPlayerCameraBob: # ROM: 0x3F4D24 - .4byte 0x3F451EB8 + .float 0.77 .global kMaxOrbitBobScale__16CPlayerCameraBob kMaxOrbitBobScale__16CPlayerCameraBob: # ROM: 0x3F4D28 - .4byte 0x3F4CCCCD + .float 0.8 .global kSlowSpeedPeriodScale__16CPlayerCameraBob kSlowSpeedPeriodScale__16CPlayerCameraBob: @@ -47,53 +47,53 @@ kLandingBobSpringConstant__16CPlayerCameraBob: # ROM: 0x3F4D34 .float 150.0 +.global lbl_805A7398__16CPlayerCameraBob +lbl_805A7398__16CPlayerCameraBob: + # ROM: 0x3F4D38 + .float -30.0 + +.global lbl_805A739C__16CPlayerCameraBob +lbl_805A739C__16CPlayerCameraBob: + # ROM: 0x3F4D3C + .float -35.0 + +.global kLandingBobSpringConstant2__16CPlayerCameraBob +kLandingBobSpringConstant2__16CPlayerCameraBob: + # ROM: 0x3F4D40 + .float 40.0 + +.global lbl_805A73A4__16CPlayerCameraBob +lbl_805A73A4__16CPlayerCameraBob: + # ROM: 0x3F4D44 + .float 80.0 + .global kViewWanderRadius__16CPlayerCameraBob kViewWanderRadius__16CPlayerCameraBob: - # ROM: 0x3F4D38 - .4byte 0xC1F00000 - -.global kViewWanderSpeedMin__16CPlayerCameraBob -kViewWanderSpeedMin__16CPlayerCameraBob: - # ROM: 0x3F4D3C - .4byte 0xC20C0000 - -.global kViewWanderSpeedMax__16CPlayerCameraBob -kViewWanderSpeedMax__16CPlayerCameraBob: - # ROM: 0x3F4D40 - .4byte 0x42200000 - -.global kViewWanderRollVariation__16CPlayerCameraBob -kViewWanderRollVariation__16CPlayerCameraBob: - # ROM: 0x3F4D44 - .4byte 0x42A00000 - -.global kGunBobMagnitude__16CPlayerCameraBob -kGunBobMagnitude__16CPlayerCameraBob: # ROM: 0x3F4D48 .float 0.03 -.global kHelmetBobMagnitude__16CPlayerCameraBob -kHelmetBobMagnitude__16CPlayerCameraBob: +.global kViewWanderSpeedMin__16CPlayerCameraBob +kViewWanderSpeedMin__16CPlayerCameraBob: # ROM: 0x3F4D4C .float 0.1 -.global lbl_805A73B0 -lbl_805A73B0: +.global kViewWanderSpeedMax__16CPlayerCameraBob +kViewWanderSpeedMax__16CPlayerCameraBob: # ROM: 0x3F4D50 .float 0.3 -.global lbl_805A73B4 -lbl_805A73B4: +.global kViewWanderRollVariation__16CPlayerCameraBob +kViewWanderRollVariation__16CPlayerCameraBob: # ROM: 0x3F4D54 .float 0.3 -.global lbl_805A73B8 -lbl_805A73B8: +.global kGunBobMagnitude__16CPlayerCameraBob +kGunBobMagnitude__16CPlayerCameraBob: # ROM: 0x3F4D58 .float 0.3 -.global lbl_805A73BC -lbl_805A73BC: +.global kHelmetBobMagnitude__16CPlayerCameraBob +kHelmetBobMagnitude__16CPlayerCameraBob: # ROM: 0x3F4D5C .float 2.0 @@ -105,12 +105,12 @@ lbl_805A73C0: .global lbl_805A73C4 lbl_805A73C4: # ROM: 0x3F4D64 - .4byte 0 + .float 0 .global lbl_805A73C8 lbl_805A73C8: # ROM: 0x3F4D68 - .4byte 0 + .float 0 .global lbl_805A73CC lbl_805A73CC: @@ -120,7 +120,7 @@ lbl_805A73CC: .global lbl_805A73D0 lbl_805A73D0: # ROM: 0x3F4D70 - .4byte 0 + .float 0.0 .global lbl_805A73D4 lbl_805A73D4: @@ -131,15 +131,15 @@ lbl_805A73D4: .balign 8 # CPlayerCameraBob -.global lbl_805A8ED0 -lbl_805A8ED0: +.global kLandingBobDamping__16CPlayerCameraBob +kLandingBobDamping__16CPlayerCameraBob: .skip 0x4 -.global lbl_805A8ED4 -lbl_805A8ED4: +.global kLandingBobDamping2__16CPlayerCameraBob +kLandingBobDamping2__16CPlayerCameraBob: + .skip 0x4 +.global kCameraDamping__16CPlayerCameraBob +kCameraDamping__16CPlayerCameraBob: .skip 0x4 -.global lbl_805A8ED8 -lbl_805A8ED8: - .skip 0x8 .section .sdata2, "a" .balign 8 @@ -371,10 +371,10 @@ UpdateViewWander__16CPlayerCameraBobFfR13CStateManager: /* 800E9794 000E66F4 54 1F 10 3A */ slwi r31, r0, 2 /* 800E9798 000E66F8 48 00 00 85 */ bl CalculateRandomViewWanderPitch__16CPlayerCameraBobFR13CStateManager /* 800E979C 000E66FC 7C 3E FD 2E */ stfsx f1, r30, r31 -/* 800E97A0 000E6700 C3 ED 87 EC */ lfs f31, kHelmetBobMagnitude__16CPlayerCameraBob@sda21(r13) +/* 800E97A0 000E6700 C3 ED 87 EC */ lfs f31, kViewWanderSpeedMin__16CPlayerCameraBob@sda21(r13) /* 800E97A4 000E6704 80 7D 09 00 */ lwz r3, 0x900(r29) /* 800E97A8 000E6708 48 22 8D 35 */ bl Float__9CRandom16Fv -/* 800E97AC 000E670C C0 4D 87 F0 */ lfs f2, lbl_805A73B0@sda21(r13) +/* 800E97AC 000E670C C0 4D 87 F0 */ lfs f2, kViewWanderSpeedMax__16CPlayerCameraBob@sda21(r13) /* 800E97B0 000E6710 C0 02 90 7C */ lfs f0, lbl_805AAD9C@sda21(r2) /* 800E97B4 000E6714 EC 42 F8 28 */ fsubs f2, f2, f31 /* 800E97B8 000E6718 EC 22 F8 7A */ fmadds f1, f2, f1, f31 @@ -414,7 +414,7 @@ CalculateRandomViewWanderPitch__16CPlayerCameraBobFR13CStateManager: /* 800E9830 000E6790 C0 02 90 88 */ lfs f0, lbl_805AADA8@sda21(r2) /* 800E9834 000E6794 C0 42 90 84 */ lfs f2, lbl_805AADA4@sda21(r2) /* 800E9838 000E6798 EC 61 00 28 */ fsubs f3, f1, f0 -/* 800E983C 000E679C C0 2D 87 F4 */ lfs f1, lbl_805A73B4@sda21(r13) +/* 800E983C 000E679C C0 2D 87 F4 */ lfs f1, kViewWanderRollVariation__16CPlayerCameraBob@sda21(r13) /* 800E9840 000E67A0 C0 02 90 80 */ lfs f0, lbl_805AADA0@sda21(r2) /* 800E9844 000E67A4 EC 42 00 F2 */ fmuls f2, f2, f3 /* 800E9848 000E67A8 EC 21 00 B2 */ fmuls f1, f1, f2 @@ -447,7 +447,7 @@ CalculateRandomViewWanderPosition__16CPlayerCameraBobFR13CStateManager: /* 800E98A8 000E6808 80 7F 09 00 */ lwz r3, 0x900(r31) /* 800E98AC 000E680C EF C0 00 72 */ fmuls f30, f0, f1 /* 800E98B0 000E6810 48 22 8C 2D */ bl Float__9CRandom16Fv -/* 800E98B4 000E6814 C0 0D 87 E8 */ lfs f0, kGunBobMagnitude__16CPlayerCameraBob@sda21(r13) +/* 800E98B4 000E6814 C0 0D 87 E8 */ lfs f0, kViewWanderRadius__16CPlayerCameraBob@sda21(r13) /* 800E98B8 000E6818 EF A0 00 72 */ fmuls f29, f0, f1 /* 800E98BC 000E681C FC 20 F0 90 */ fmr f1, f30 /* 800E98C0 000E6820 48 22 BA 25 */ bl SlowCosineR__5CMathFf @@ -520,10 +520,10 @@ InitViewWander__16CPlayerCameraBobFR13CStateManager: /* 800E99C0 000E6920 D0 1E 00 BC */ stfs f0, 0xbc(r30) /* 800E99C4 000E6924 4B FF FE 59 */ bl CalculateRandomViewWanderPitch__16CPlayerCameraBobFR13CStateManager /* 800E99C8 000E6928 D0 3E 00 C0 */ stfs f1, 0xc0(r30) -/* 800E99CC 000E692C C3 ED 87 EC */ lfs f31, kHelmetBobMagnitude__16CPlayerCameraBob@sda21(r13) +/* 800E99CC 000E692C C3 ED 87 EC */ lfs f31, kViewWanderSpeedMin__16CPlayerCameraBob@sda21(r13) /* 800E99D0 000E6930 80 7F 09 00 */ lwz r3, 0x900(r31) /* 800E99D4 000E6934 48 22 8B 09 */ bl Float__9CRandom16Fv -/* 800E99D8 000E6938 C0 4D 87 F0 */ lfs f2, lbl_805A73B0@sda21(r13) +/* 800E99D8 000E6938 C0 4D 87 F0 */ lfs f2, kViewWanderSpeedMax__16CPlayerCameraBob@sda21(r13) /* 800E99DC 000E693C 38 00 00 00 */ li r0, 0 /* 800E99E0 000E6940 C0 02 90 78 */ lfs f0, lbl_805AAD98@sda21(r2) /* 800E99E4 000E6944 EC 42 F8 28 */ fsubs f2, f2, f31 @@ -575,10 +575,10 @@ SetState__16CPlayerCameraBobFQ216CPlayerCameraBob15ECameraBobStateR13CStateManag /* 800E9A80 000E69E0 38 00 00 01 */ li r0, 1 /* 800E9A84 000E69E4 98 03 00 28 */ stb r0, 0x28(r3) /* 800E9A88 000E69E8 C0 23 00 68 */ lfs f1, 0x68(r3) -/* 800E9A8C 000E69EC C0 0D 87 DC */ lfs f0, kViewWanderSpeedMin__16CPlayerCameraBob@sda21(r13) +/* 800E9A8C 000E69EC C0 0D 87 DC */ lfs f0, lbl_805A739C__16CPlayerCameraBob@sda21(r13) /* 800E9A90 000E69F0 FC 01 00 40 */ fcmpo cr0, f1, f0 /* 800E9A94 000E69F4 40 80 00 0C */ bge lbl_800E9AA0 -/* 800E9A98 000E69F8 38 8D 87 DC */ addi r4, r13, kViewWanderSpeedMin__16CPlayerCameraBob@sda21 +/* 800E9A98 000E69F8 38 8D 87 DC */ addi r4, r13, lbl_805A739C__16CPlayerCameraBob@sda21 /* 800E9A9C 000E69FC 48 00 00 08 */ b lbl_800E9AA4 lbl_800E9AA0: /* 800E9AA0 000E6A00 38 83 00 68 */ addi r4, r3, 0x68 @@ -586,7 +586,7 @@ lbl_800E9AA4: /* 800E9AA4 000E6A04 C0 04 00 00 */ lfs f0, 0(r4) /* 800E9AA8 000E6A08 D0 03 00 68 */ stfs f0, 0x68(r3) /* 800E9AAC 000E6A0C C0 23 00 68 */ lfs f1, 0x68(r3) -/* 800E9AB0 000E6A10 C0 0D 87 D8 */ lfs f0, kViewWanderRadius__16CPlayerCameraBob@sda21(r13) +/* 800E9AB0 000E6A10 C0 0D 87 D8 */ lfs f0, lbl_805A7398__16CPlayerCameraBob@sda21(r13) /* 800E9AB4 000E6A14 FC 01 00 40 */ fcmpo cr0, f1, f0 /* 800E9AB8 000E6A18 7C 00 00 26 */ mfcr r0 /* 800E9ABC 000E6A1C 54 00 0F FE */ srwi r0, r0, 0x1f @@ -752,7 +752,7 @@ GetHelmetBobTranslation__16CPlayerCameraBobCFv: /* 800E9CEC 000E6C4C C0 04 00 38 */ lfs f0, 0x38(r4) /* 800E9CF0 000E6C50 C0 44 00 48 */ lfs f2, 0x48(r4) /* 800E9CF4 000E6C54 EC 00 08 28 */ fsubs f0, f0, f1 -/* 800E9CF8 000E6C58 C0 8D 87 FC */ lfs f4, lbl_805A73BC@sda21(r13) +/* 800E9CF8 000E6C58 C0 8D 87 FC */ lfs f4, kHelmetBobMagnitude__16CPlayerCameraBob@sda21(r13) /* 800E9CFC 000E6C5C EC 62 08 28 */ fsubs f3, f2, f1 /* 800E9D00 000E6C60 C0 44 00 58 */ lfs f2, 0x58(r4) /* 800E9D04 000E6C64 C0 24 00 78 */ lfs f1, 0x78(r4) @@ -774,7 +774,7 @@ GetGunBobTransformation__16CPlayerCameraBobCFv: /* 800E9D38 000E6C98 93 E1 00 5C */ stw r31, 0x5c(r1) /* 800E9D3C 000E6C9C 7C 7F 1B 78 */ mr r31, r3 /* 800E9D40 000E6CA0 38 61 00 20 */ addi r3, r1, 0x20 -/* 800E9D44 000E6CA4 C0 0D 87 F8 */ lfs f0, lbl_805A73B8@sda21(r13) +/* 800E9D44 000E6CA4 C0 0D 87 F8 */ lfs f0, kGunBobMagnitude__16CPlayerCameraBob@sda21(r13) /* 800E9D48 000E6CA8 C0 84 00 58 */ lfs f4, 0x58(r4) /* 800E9D4C 000E6CAC EC 61 00 2A */ fadds f3, f1, f0 /* 800E9D50 000E6CB0 C0 24 00 48 */ lfs f1, 0x48(r4) @@ -922,12 +922,12 @@ Update__16CPlayerCameraBobFfR13CStateManager: /* 800E9F28 000E6E88 28 00 00 00 */ cmplwi r0, 0 /* 800E9F2C 000E6E8C 41 82 00 E8 */ beq lbl_800EA014 /* 800E9F30 000E6E90 88 1E 00 29 */ lbz r0, 0x29(r30) -/* 800E9F34 000E6E94 C0 0D A3 10 */ lfs f0, lbl_805A8ED0@sda21(r13) +/* 800E9F34 000E6E94 C0 0D A3 10 */ lfs f0, kLandingBobDamping__16CPlayerCameraBob@sda21(r13) /* 800E9F38 000E6E98 28 00 00 00 */ cmplwi r0, 0 /* 800E9F3C 000E6E9C C0 8D 87 D4 */ lfs f4, kLandingBobSpringConstant__16CPlayerCameraBob@sda21(r13) /* 800E9F40 000E6EA0 41 82 00 0C */ beq lbl_800E9F4C -/* 800E9F44 000E6EA4 C0 0D A3 14 */ lfs f0, lbl_805A8ED4@sda21(r13) -/* 800E9F48 000E6EA8 C0 8D 87 E0 */ lfs f4, kViewWanderSpeedMax__16CPlayerCameraBob@sda21(r13) +/* 800E9F44 000E6EA4 C0 0D A3 14 */ lfs f0, kLandingBobDamping2__16CPlayerCameraBob@sda21(r13) +/* 800E9F48 000E6EA8 C0 8D 87 E0 */ lfs f4, kLandingBobSpringConstant2__16CPlayerCameraBob@sda21(r13) lbl_800E9F4C: /* 800E9F4C 000E6EAC C0 5E 00 6C */ lfs f2, 0x6c(r30) /* 800E9F50 000E6EB0 C0 7E 00 70 */ lfs f3, 0x70(r30) @@ -941,9 +941,9 @@ lbl_800E9F4C: /* 800E9F70 000E6ED0 C0 1E 00 70 */ lfs f0, 0x70(r30) /* 800E9F74 000E6ED4 EC 02 07 FA */ fmadds f0, f2, f31, f0 /* 800E9F78 000E6ED8 D0 1E 00 70 */ stfs f0, 0x70(r30) -/* 800E9F7C 000E6EDC C0 0D A3 18 */ lfs f0, lbl_805A8ED8@sda21(r13) +/* 800E9F7C 000E6EDC C0 0D A3 18 */ lfs f0, kCameraDamping__16CPlayerCameraBob@sda21(r13) /* 800E9F80 000E6EE0 C0 5E 00 74 */ lfs f2, 0x74(r30) -/* 800E9F84 000E6EE4 C0 8D 87 E4 */ lfs f4, kViewWanderRollVariation__16CPlayerCameraBob@sda21(r13) +/* 800E9F84 000E6EE4 C0 8D 87 E4 */ lfs f4, lbl_805A73A4__16CPlayerCameraBob@sda21(r13) /* 800E9F88 000E6EE8 EC 00 00 B2 */ fmuls f0, f0, f2 /* 800E9F8C 000E6EEC C0 7E 00 78 */ lfs f3, 0x78(r30) /* 800E9F90 000E6EF0 FC 00 00 50 */ fneg f0, f0 @@ -1109,22 +1109,22 @@ ReadTweaks__16CPlayerCameraBobFR12CInputStream: /* 800EA1F0 000E7150 D0 2D 87 D4 */ stfs f1, kLandingBobSpringConstant__16CPlayerCameraBob@sda21(r13) /* 800EA1F4 000E7154 7F E3 FB 78 */ mr r3, r31 /* 800EA1F8 000E7158 48 25 4A 31 */ bl ReadFloat__12CInputStreamFv -/* 800EA1FC 000E715C D0 2D 87 E8 */ stfs f1, kGunBobMagnitude__16CPlayerCameraBob@sda21(r13) +/* 800EA1FC 000E715C D0 2D 87 E8 */ stfs f1, kViewWanderRadius__16CPlayerCameraBob@sda21(r13) /* 800EA200 000E7160 7F E3 FB 78 */ mr r3, r31 /* 800EA204 000E7164 48 25 4A 25 */ bl ReadFloat__12CInputStreamFv -/* 800EA208 000E7168 D0 2D 87 EC */ stfs f1, kHelmetBobMagnitude__16CPlayerCameraBob@sda21(r13) +/* 800EA208 000E7168 D0 2D 87 EC */ stfs f1, kViewWanderSpeedMin__16CPlayerCameraBob@sda21(r13) /* 800EA20C 000E716C 7F E3 FB 78 */ mr r3, r31 /* 800EA210 000E7170 48 25 4A 19 */ bl ReadFloat__12CInputStreamFv -/* 800EA214 000E7174 D0 2D 87 F0 */ stfs f1, lbl_805A73B0@sda21(r13) +/* 800EA214 000E7174 D0 2D 87 F0 */ stfs f1, kViewWanderSpeedMax__16CPlayerCameraBob@sda21(r13) /* 800EA218 000E7178 7F E3 FB 78 */ mr r3, r31 /* 800EA21C 000E717C 48 25 4A 0D */ bl ReadFloat__12CInputStreamFv -/* 800EA220 000E7180 D0 2D 87 F4 */ stfs f1, lbl_805A73B4@sda21(r13) +/* 800EA220 000E7180 D0 2D 87 F4 */ stfs f1, kViewWanderRollVariation__16CPlayerCameraBob@sda21(r13) /* 800EA224 000E7184 7F E3 FB 78 */ mr r3, r31 /* 800EA228 000E7188 48 25 4A 01 */ bl ReadFloat__12CInputStreamFv -/* 800EA22C 000E718C D0 2D 87 F8 */ stfs f1, lbl_805A73B8@sda21(r13) +/* 800EA22C 000E718C D0 2D 87 F8 */ stfs f1, kGunBobMagnitude__16CPlayerCameraBob@sda21(r13) /* 800EA230 000E7190 7F E3 FB 78 */ mr r3, r31 /* 800EA234 000E7194 48 25 49 F5 */ bl ReadFloat__12CInputStreamFv -/* 800EA238 000E7198 D0 2D 87 FC */ stfs f1, lbl_805A73BC@sda21(r13) +/* 800EA238 000E7198 D0 2D 87 FC */ stfs f1, kHelmetBobMagnitude__16CPlayerCameraBob@sda21(r13) /* 800EA23C 000E719C 80 01 00 14 */ lwz r0, 0x14(r1) /* 800EA240 000E71A0 83 E1 00 0C */ lwz r31, 0xc(r1) /* 800EA244 000E71A4 7C 08 03 A6 */ mtlr r0 @@ -1175,7 +1175,7 @@ __ct__16CPlayerCameraBobFQ216CPlayerCameraBob14ECameraBobTypeRC9CVector2ff: /* 800EA2EC 000E724C 90 1F 00 7C */ stw r0, 0x7c(r31) /* 800EA2F0 000E7250 90 1F 00 B0 */ stw r0, 0xb0(r31) /* 800EA2F4 000E7254 D0 1F 00 C4 */ stfs f0, 0xc4(r31) -/* 800EA2F8 000E7258 C0 0D 87 EC */ lfs f0, kHelmetBobMagnitude__16CPlayerCameraBob@sda21(r13) +/* 800EA2F8 000E7258 C0 0D 87 EC */ lfs f0, kViewWanderSpeedMin__16CPlayerCameraBob@sda21(r13) /* 800EA2FC 000E725C D0 1F 00 C8 */ stfs f0, 0xc8(r31) /* 800EA300 000E7260 90 1F 00 CC */ stw r0, 0xcc(r31) /* 800EA304 000E7264 48 22 88 71 */ bl __ct__12CTransform4fFRC12CTransform4f @@ -1285,8 +1285,7 @@ lbl_800EA468: /* 800EA484 000E73E4 38 21 00 10 */ addi r1, r1, 0x10 /* 800EA488 000E73E8 4E 80 00 20 */ blr -.global __sinit_CPlayerCameraBob_cpp -__sinit_CPlayerCameraBob_cpp: +.fn __sinit_CPlayerCameraBob_cpp, local /* 800EA48C 000E73EC 94 21 FF F0 */ stwu r1, -0x10(r1) /* 800EA490 000E73F0 7C 08 02 A6 */ mflr r0 /* 800EA494 000E73F4 90 01 00 14 */ stw r0, 0x14(r1) @@ -1294,18 +1293,19 @@ __sinit_CPlayerCameraBob_cpp: /* 800EA49C 000E73FC 48 22 B0 65 */ bl SqrtF__5CMathFf /* 800EA4A0 000E7400 C0 02 90 84 */ lfs f0, lbl_805AADA4@sda21(r2) /* 800EA4A4 000E7404 EC 00 00 72 */ fmuls f0, f0, f1 -/* 800EA4A8 000E7408 C0 2D 87 E0 */ lfs f1, kViewWanderSpeedMax__16CPlayerCameraBob@sda21(r13) -/* 800EA4AC 000E740C D0 0D A3 10 */ stfs f0, lbl_805A8ED0@sda21(r13) +/* 800EA4A8 000E7408 C0 2D 87 E0 */ lfs f1, kLandingBobSpringConstant2__16CPlayerCameraBob@sda21(r13) +/* 800EA4AC 000E740C D0 0D A3 10 */ stfs f0, kLandingBobDamping__16CPlayerCameraBob@sda21(r13) /* 800EA4B0 000E7410 48 22 B0 51 */ bl SqrtF__5CMathFf /* 800EA4B4 000E7414 C0 02 90 BC */ lfs f0, lbl_805AADDC@sda21(r2) /* 800EA4B8 000E7418 EC 00 00 72 */ fmuls f0, f0, f1 -/* 800EA4BC 000E741C C0 2D 87 E4 */ lfs f1, kViewWanderRollVariation__16CPlayerCameraBob@sda21(r13) -/* 800EA4C0 000E7420 D0 0D A3 14 */ stfs f0, lbl_805A8ED4@sda21(r13) +/* 800EA4BC 000E741C C0 2D 87 E4 */ lfs f1, lbl_805A73A4__16CPlayerCameraBob@sda21(r13) +/* 800EA4C0 000E7420 D0 0D A3 14 */ stfs f0, kLandingBobDamping2__16CPlayerCameraBob@sda21(r13) /* 800EA4C4 000E7424 48 22 B0 3D */ bl SqrtF__5CMathFf /* 800EA4C8 000E7428 C0 02 90 C0 */ lfs f0, lbl_805AADE0@sda21(r2) /* 800EA4CC 000E742C EC 00 00 72 */ fmuls f0, f0, f1 -/* 800EA4D0 000E7430 D0 0D A3 18 */ stfs f0, lbl_805A8ED8@sda21(r13) +/* 800EA4D0 000E7430 D0 0D A3 18 */ stfs f0, kCameraDamping__16CPlayerCameraBob@sda21(r13) /* 800EA4D4 000E7434 80 01 00 14 */ lwz r0, 0x14(r1) /* 800EA4D8 000E7438 7C 08 03 A6 */ mtlr r0 /* 800EA4DC 000E743C 38 21 00 10 */ addi r1, r1, 0x10 /* 800EA4E0 000E7440 4E 80 00 20 */ blr +.endfn __sinit_CPlayerCameraBob_cpp diff --git a/configure.py b/configure.py index b40b44d8..20071109 100755 --- a/configure.py +++ b/configure.py @@ -119,7 +119,7 @@ LIBS = [ ["MetroidPrime/HUD/CHUDMemoParms", True], ["MetroidPrime/ScriptObjects/CScriptHUDMemo", True], ["MetroidPrime/CMappableObject", False], - "MetroidPrime/Player/CPlayerCameraBob", + ["MetroidPrime/Player/CPlayerCameraBob", False], ["MetroidPrime/ScriptObjects/CScriptCameraFilterKeyframe", True], ["MetroidPrime/ScriptObjects/CScriptCameraBlurKeyframe", True], ["MetroidPrime/Cameras/CCameraFilter", False], @@ -316,7 +316,7 @@ LIBS = [ "MetroidPrime/Enemies/CMagdolite", "MetroidPrime/Enemies/CTeamAiMgr", "MetroidPrime/Enemies/CSnakeWeedSwarm", - "MetroidPrime/Cameras/CBallCameraFailsafeState", + ["MetroidPrime/Cameras/CBallCameraFailsafeState", False], "MetroidPrime/Enemies/CActorContraption", "MetroidPrime/ScriptObjects/CScriptSpindleCamera", ["MetroidPrime/ScriptObjects/CScriptMemoryRelay", True], diff --git a/include/Collision/CCollidableAABox.hpp b/include/Collision/CCollidableAABox.hpp index 8d743846..4f6bbb3b 100644 --- a/include/Collision/CCollidableAABox.hpp +++ b/include/Collision/CCollidableAABox.hpp @@ -10,18 +10,31 @@ public: CCollidableAABox(); CCollidableAABox(const CAABox& box, const CMaterialList& matList) : CCollisionPrimitive(matList), x10_aabb(box) {} - // TODO - uint GetTableIndex() const override; - CAABox CalculateAABox(const CTransform4f&) const override; - CAABox CalculateLocalAABox() const override; - FourCC GetPrimType() const override; - ~CCollidableAABox() override{}; - CRayCastResult CastRayInternal(const CInternalRayCastStructure&) const override; + bool CollideMovingAABox(const CInternalCollisionStructure& collision, const CVector3f& dir, + double& dOut, CCollisionInfo& infoOut); + bool CollideMovingSphere(const CInternalCollisionStructure& collision, const CVector3f& dir, + double& dOut, CCollisionInfo& infoOut); + + uint GetTableIndex() const; + CAABox CalculateAABox(const CTransform4f&) const; + CAABox CalculateLocalAABox() const; + CAABox Transform(const CTransform4f& xf) const; + FourCC GetPrimType() const; + CRayCastResult CastRayInternal(const CInternalRayCastStructure&) const; + + static void SetStaticTableIndex(uint idx); + static CCollisionPrimitive::Type GetType(); private: + static uint sTableIndex; + CAABox x10_aabb; }; CHECK_SIZEOF(CCollidableAABox, 0x28) +namespace Collide { +bool AABox_AABox_Bool(const CInternalCollisionStructure&); +bool AABox_AABox(const CInternalCollisionStructure& collision, CCollisionInfoList& list); +} // namespace Collide #endif // _CCOLLIDABLEAABOX diff --git a/include/Collision/CInternalCollisionStructure.hpp b/include/Collision/CInternalCollisionStructure.hpp new file mode 100644 index 00000000..7bfc3d03 --- /dev/null +++ b/include/Collision/CInternalCollisionStructure.hpp @@ -0,0 +1,38 @@ +#ifndef _CINTERNALCOLLISIONSTRUCTURE +#define _CINTERNALCOLLISIONSTRUCTURE + +#include "Kyoto/Math/CTransform4f.hpp" + +class CMaterialFilter; +class CCollisionPrimitive; +class CInternalCollisionStructure { +public: + class CPrimDesc { + public: + CPrimDesc(const CCollisionPrimitive& prim, const CMaterialFilter& filter, + const CTransform4f& xf) + : x0_prim(prim), x4_filter(filter), x8_xf(xf) {} + + const CCollisionPrimitive& GetPrim() const { return x0_prim; } + const CMaterialFilter& GetFilter() const { return x4_filter; } + const CTransform4f& GetTransform() const { return x8_xf; } + + private: + const CCollisionPrimitive& x0_prim; + const CMaterialFilter& x4_filter; + CTransform4f x8_xf; + }; + + CInternalCollisionStructure(const CPrimDesc& left, const CPrimDesc& right) + : x0_left(left), x38_right(right) {} + + const CPrimDesc& GetLeft() const { return x0_left; } + const CPrimDesc& GetRight() const { return x38_right; } + CInternalCollisionStructure + GetSwapped() const; // TODO: Find where this is used and investigate proper behavior +private: + CPrimDesc x0_left; + CPrimDesc x38_right; +}; + +#endif // _CINTERNALCOLLISIONSTRUCTURE diff --git a/include/Collision/CInternalRayCastStructure.hpp b/include/Collision/CInternalRayCastStructure.hpp new file mode 100644 index 00000000..06a92c7e --- /dev/null +++ b/include/Collision/CInternalRayCastStructure.hpp @@ -0,0 +1,29 @@ +#ifndef _CINTERNALRAYCASTSTRUCTURE +#define _CINTERNALRAYCASTSTRUCTURE + +#include "Collision/CMRay.hpp" + +#include "Kyoto/Math/CTransform4f.hpp" + +class CMaterialFilter; +class CInternalRayCastStructure { +public: + CInternalRayCastStructure(const CVector3f& start, const CVector3f& dir, float length, + const CTransform4f& xf, const CMaterialFilter& filter) + : x0_ray(start, dir, length), x38_maxTime(length), x3c_xf(xf), x6c_filter(filter) {} + + const CMRay& GetRay() const { return x0_ray; } + const CVector3f& GetStart() const { return x0_ray.GetStart(); } + const CVector3f& GetNormal() const { return x0_ray.GetNormal(); } + float GetMaxTime() const { return x38_maxTime; } + const CTransform4f& GetTransform() const { return x3c_xf; } + const CMaterialFilter& GetFilter() const { return x6c_filter; } + +private: + CMRay x0_ray; + float x38_maxTime; + CTransform4f x3c_xf; + const CMaterialFilter& x6c_filter; +}; + +#endif // _CINTERNALRAYCASTSTRUCTURE diff --git a/include/Collision/CMRay.hpp b/include/Collision/CMRay.hpp index f16de1f6..36eed586 100644 --- a/include/Collision/CMRay.hpp +++ b/include/Collision/CMRay.hpp @@ -10,6 +10,11 @@ public: CMRay(const CVector3f& start, const CVector3f& end, float); CMRay GetInvUnscaledTransformRay(const CTransform4f&) const; + const CVector3f& GetStart() const { return mStart; } + const CVector3f& GetNormal() const { return mEnd; } + const CVector3f& GetDelta() const { return mDelta; } + const CVector3f& GetDirection() const { return mDir; } + private: CVector3f mStart; CVector3f mEnd; diff --git a/include/Collision/CRayCastResult.hpp b/include/Collision/CRayCastResult.hpp index 87657ff6..20112dd7 100644 --- a/include/Collision/CRayCastResult.hpp +++ b/include/Collision/CRayCastResult.hpp @@ -14,26 +14,35 @@ public: kI_Invalid, kI_Valid, }; + CRayCastResult(float time, const CVector3f& point, const CPlane& plane, const CMaterialList& list) + : x0_time(time), x4_point(point), x10_plane(plane), x20_valid(kI_Valid), x28_material(list) {} + CRayCastResult(EInvalid invalid) + : x0_time(0) + , x4_point(CVector3f(0.f, 0.f, 0.f)) + , x10_plane(CPlane(0.f, CUnitVector3f(1.f, 0.f, 0.f, CUnitVector3f::kN_Yes))) + , x20_valid(invalid) {} - float GetTime() const { return x0_t; } + float GetTime() const { return x0_time; } + const CVector3f& GetPoint() const { return x4_point; } + const CPlane& GetPlane() const { return x10_plane; } bool IsValid() const { return x20_valid != kI_Invalid; } // TODO: figure out what's going on here bool IsInvalid() const { return x20_valid == kI_Invalid; } - // GetPlane__14CRayCastResultCFv - const CPlane& GetPlane() const { return x10_plane; } - const CVector3f& GetPoint() const { return x4_point; } - // GetMaterial__14CRayCastResultCFv - // Transform__14CRayCastResultFRC12CTransform4f + const CMaterialList& GetMaterial() const { return x28_material; } + void Transform(const CTransform4f& xf); - // MakeInvalid__14CRayCastResultFv + static CRayCastResult MakeInvalid() { + return CRayCastResult(kI_Invalid); + } private: - float x0_t; + float x0_time; CVector3f x4_point; CPlane x10_plane; bool x20_valid; CMaterialList x28_material; }; + CHECK_SIZEOF(CRayCastResult, 0x30) #endif // _CRAYCASTRESULT diff --git a/include/Collision/CollisionUtil.hpp b/include/Collision/CollisionUtil.hpp index 7eef4500..606e8eac 100644 --- a/include/Collision/CollisionUtil.hpp +++ b/include/Collision/CollisionUtil.hpp @@ -3,25 +3,22 @@ #include "Kyoto/Math/CVector3f.hpp" +class CAABox; +class CMaterialList; class CCollisionInfoList; class CVector3f; -/* TODO: Figure out a better place for this, borks CBallFilter here, but is needed for CCollidableAABox/Sphere - (Best solution would be to find a Tardis and go back and slap the dev responsible for this) -static const CVector3f normalTable[6] = { - CVector3f(-1.f, 0.f, 0.f), - CVector3f(1.f, 0.f, 0.f), - CVector3f(0.f, -1.f, 0.f), - CVector3f(0.f, 1.f, 0.f), - CVector3f(0.f, 0.f, -1.f), - CVector3f(0.f, 0.f, 1.f), -}; -*/ namespace CollisionUtil { void AddAverageToFront(const CCollisionInfoList& in, CCollisionInfoList& out); bool TriBoxOverlap(const CVector3f& boxcenter, const CVector3f& boxhalfsize, const CVector3f& trivert0, const CVector3f& trivert1, const CVector3f& trivert2); +bool BoxLineTest(const CAABox&, const CVector3f&, const CVector3f&, float&, float&, int&, bool&); + +bool AABoxAABoxIntersection(const CAABox& left, const CAABox& right); +bool AABoxAABoxIntersection(const CAABox& left, const CMaterialList& leftFilter, + const CAABox& right, const CMaterialList& rightFilter, + CCollisionInfoList& list); } // namespace CollisionUtil diff --git a/include/Collision/NormalTable.hpp b/include/Collision/NormalTable.hpp new file mode 100644 index 00000000..cb9850a1 --- /dev/null +++ b/include/Collision/NormalTable.hpp @@ -0,0 +1,15 @@ +#ifndef _NORMALTABLE +#define _NORMALTABLE + +#include "Kyoto/Math/CVector3f.hpp" + +static const CVector3f normalTable[6] = { + CVector3f(-1.f, 0.f, 0.f), + CVector3f(1.f, 0.f, 0.f), + CVector3f(0.f, -1.f, 0.f), + CVector3f(0.f, 1.f, 0.f), + CVector3f(0.f, 0.f, -1.f), + CVector3f(0.f, 0.f, 1.f), +}; + +#endif // _NORMALTABLE diff --git a/include/Kyoto/Math/CUnitVector3f.hpp b/include/Kyoto/Math/CUnitVector3f.hpp index 0538e982..fe80527e 100644 --- a/include/Kyoto/Math/CUnitVector3f.hpp +++ b/include/Kyoto/Math/CUnitVector3f.hpp @@ -17,7 +17,7 @@ public: } } CUnitVector3f( - const CVector3f& vec); // : CVector3f(vec.IsNonZero() ? vec.AsNormalized() : Zero()) {} + const CVector3f& vec);//: CVector3f(vec.IsNonZero() ? vec.AsNormalized() : Zero()) {} // TODO static CUnitVector3f Forward() { diff --git a/include/MetroidPrime/Player/CPlayerCameraBob.hpp b/include/MetroidPrime/Player/CPlayerCameraBob.hpp index 4ff35bab..afe552c7 100644 --- a/include/MetroidPrime/Player/CPlayerCameraBob.hpp +++ b/include/MetroidPrime/Player/CPlayerCameraBob.hpp @@ -29,7 +29,7 @@ public: kCBS_Unspecified, }; - CPlayerCameraBob(ECameraBobType type, float bobPeriod, const CVector2f& vec); + CPlayerCameraBob(ECameraBobType type, const CVector2f& vec, float bobPeriod); CTransform4f GetViewWanderTransform() const; CVector3f GetHelmetBobTranslation() const; @@ -95,16 +95,25 @@ public: static float kSlowSpeedPeriodScale; static float kTargetMagnitudeTrackingRate; static float kLandingBobSpringConstant; + static float lbl_805A7398; + static float lbl_805A739C; static float kLandingBobSpringConstant2; + static float lbl_805A73A4; static float kViewWanderRadius; static float kViewWanderSpeedMin; static float kViewWanderSpeedMax; static float kViewWanderRollVariation; static float kGunBobMagnitude; static float kHelmetBobMagnitude; - static const float kLandingBobDamping; - static const float kLandingBobDamping2; - static const float kCameraDamping; + static float kLandingBobDamping; + static float kLandingBobDamping2; + static float kCameraDamping; + static float lbl_805A73C0; + static float lbl_805A73C4; + static float lbl_805A73C8; + static float lbl_805A73CC; + static float lbl_805A73D0; + static float lbl_805A73D4; }; CHECK_SIZEOF(CPlayerCameraBob, 0x108) diff --git a/src/Collision/CCollidableAABox.cpp b/src/Collision/CCollidableAABox.cpp index 57605789..0697163a 100644 --- a/src/Collision/CCollidableAABox.cpp +++ b/src/Collision/CCollidableAABox.cpp @@ -1,3 +1,91 @@ #include "Collision/CCollidableAABox.hpp" +#include "Collision/CCollisionInfoList.hpp" +#include "Collision/CInternalCollisionStructure.hpp" +#include "Collision/CInternalRayCastStructure.hpp" +#include "Collision/CMaterialFilter.hpp" +#include "Collision/CRayCastResult.hpp" #include "Collision/CollisionUtil.hpp" +#include "Collision/NormalTable.hpp" + +uint CCollidableAABox::sTableIndex = -1; + +void CCollidableAABox::SetStaticTableIndex(uint idx) { sTableIndex = idx; } + +CCollisionPrimitive::Type CCollidableAABox::GetType() { + return Type(SetStaticTableIndex, "CCollidableAABox"); +} + +namespace Collide { +bool AABox_AABox_Bool(const CInternalCollisionStructure& collision) { + const CCollidableAABox& box0 = + static_cast< const CCollidableAABox& >(collision.GetLeft().GetPrim()); + const CCollidableAABox& box1 = + static_cast< const CCollidableAABox& >(collision.GetRight().GetPrim()); + const CAABox aabb0 = box0.Transform(collision.GetLeft().GetTransform()); + const CAABox aabb1 = box1.Transform(collision.GetRight().GetTransform()); + + return CollisionUtil::AABoxAABoxIntersection(aabb0, aabb1); +} +bool AABox_AABox(const CInternalCollisionStructure& collision, CCollisionInfoList& list) { + const CCollidableAABox& box0 = + static_cast< const CCollidableAABox& >(collision.GetLeft().GetPrim()); + const CCollidableAABox& box1 = + static_cast< const CCollidableAABox& >(collision.GetRight().GetPrim()); + + CAABox aabb0 = box0.Transform(collision.GetLeft().GetTransform()); + CAABox aabb1 = box1.Transform(collision.GetRight().GetTransform()); + + return CollisionUtil::AABoxAABoxIntersection(aabb0, box0.GetMaterial(), aabb1, box1.GetMaterial(), + list); +} +} // namespace Collide + +bool CCollidableAABox::CollideMovingAABox(const CInternalCollisionStructure& collision, + const CVector3f& dir, double& dOut, + CCollisionInfo& infoOut) {} + +bool CCollidableAABox::CollideMovingSphere(const CInternalCollisionStructure& collision, + const CVector3f& dir, double& dOut, + CCollisionInfo& infoOut) {} + +CRayCastResult CCollidableAABox::CastRayInternal(const CInternalRayCastStructure& rayCast) const { + if (!rayCast.GetFilter().Passes(GetMaterial())) { + return CRayCastResult::MakeInvalid(); + } + + CTransform4f rayCastXf = rayCast.GetTransform(); + CTransform4f rayCastXfInv = rayCastXfInv.GetQuickInverse(); + CVector3f localRayStart = rayCastXfInv * rayCast.GetStart(); + CVector3f localRayDir = rayCastXfInv.Rotate(rayCast.GetRay().GetDirection()); + + float tMin; + float tMax; + int axis; + bool sign; + if (!CollisionUtil::BoxLineTest(x10_aabb, localRayStart, localRayDir, tMin, tMax, axis, sign) || + tMin < 0.f || (rayCast.GetMaxTime() > 0.f && tMin > rayCast.GetMaxTime())) { + return CRayCastResult::MakeInvalid(); + } + + CVector3f planeNormal = CVector3f::Zero(); + planeNormal[axis] = sign ? 1.f : -1.f; + float planeD = axis ? x10_aabb.GetMinPoint()[axis] : x10_aabb.GetMaxPoint()[axis]; + CRayCastResult result(tMin, localRayStart + tMin * localRayDir, CPlane(planeD, planeNormal), + GetMaterial()); + + result.Transform(rayCast.GetTransform()); + return result; +} + +CAABox CCollidableAABox::CalculateLocalAABox() const { return x10_aabb; } + +CAABox CCollidableAABox::CalculateAABox(const CTransform4f& xf) const { return Transform(xf); } + +CAABox CCollidableAABox::Transform(const CTransform4f& xf) const { + const CVector3f xfPos = xf.GetTranslation(); + return CAABox(x10_aabb.GetMinPoint() + xfPos, x10_aabb.GetMaxPoint() + xfPos); +} + +FourCC CCollidableAABox::GetPrimType() const { return 'AABX'; } +uint CCollidableAABox::GetTableIndex() const { return sTableIndex; } diff --git a/src/Collision/CollisionUtil.cpp b/src/Collision/CollisionUtil.cpp index 3ed91c1d..b9c86743 100644 --- a/src/Collision/CollisionUtil.cpp +++ b/src/Collision/CollisionUtil.cpp @@ -1,5 +1,7 @@ #include "Collision/CollisionUtil.hpp" +#include "Collision/NormalTable.hpp" + #include "Kyoto/Math/CMath.hpp" #include "Kyoto/Math/CPlane.hpp" #include "Kyoto/Math/CSphere.hpp" diff --git a/src/MetroidPrime/Player/CPlayerCameraBob.cpp b/src/MetroidPrime/Player/CPlayerCameraBob.cpp new file mode 100644 index 00000000..a71a4387 --- /dev/null +++ b/src/MetroidPrime/Player/CPlayerCameraBob.cpp @@ -0,0 +1,76 @@ +#include "MetroidPrime/Player/CPlayerCameraBob.hpp" + +#include "Kyoto/Math/CMath.hpp" +#include "Kyoto/Streams/CInputStream.hpp" + +float CPlayerCameraBob::kCameraBobExtentX = 0.071f; +float CPlayerCameraBob::kCameraBobExtentY = 0.142f; +float CPlayerCameraBob::kCameraBobPeriod = 0.47f; +float CPlayerCameraBob::kOrbitBobScale = 0.769f; +float CPlayerCameraBob::kMaxOrbitBobScale = 0.8f; +float CPlayerCameraBob::kSlowSpeedPeriodScale = 0.3f; +float CPlayerCameraBob::kTargetMagnitudeTrackingRate = 0.1f; +float CPlayerCameraBob::kLandingBobSpringConstant = 150.f; +float CPlayerCameraBob::lbl_805A7398 = -30.f; +float CPlayerCameraBob::lbl_805A739C = -35.f; +float CPlayerCameraBob::kLandingBobSpringConstant2 = 40.f; +float CPlayerCameraBob::lbl_805A73A4 = 80.f; +float CPlayerCameraBob::kViewWanderRadius = 0.03f; +float CPlayerCameraBob::kViewWanderSpeedMin = 0.1f; +float CPlayerCameraBob::kViewWanderSpeedMax = 0.3f; +float CPlayerCameraBob::kViewWanderRollVariation = 0.3f; +float CPlayerCameraBob::kGunBobMagnitude = 0.3f; +float CPlayerCameraBob::kHelmetBobMagnitude = 2.f; +float CPlayerCameraBob::kLandingBobDamping = CMath::SqrtF(kLandingBobSpringConstant) * 2.f; +float CPlayerCameraBob::kLandingBobDamping2 = CMath::SqrtF(kLandingBobSpringConstant2) * 4.f; +float CPlayerCameraBob::kCameraDamping = CMath::SqrtF(lbl_805A73A4) * 6.f; + +CPlayerCameraBob::CPlayerCameraBob(ECameraBobType type, const CVector2f& vec, float bobPeriod) +: x0_type(type) +, x4_vec(vec) +, xc_bobPeriod(bobPeriod) +, x10_targetBobMagnitude(0.f) +, x14_bobMagnitude(0.f) +, x18_bobTimeScale(0.f) +, x1c_bobTime(0.f) +, x20_oldState(kCBS_Unspecified) +, x24_curState(kCBS_Unspecified) +, x28_applyLandingTrans(false) +, x29_hardLand(false) +, x2c_cameraBobTransform(CTransform4f::Identity()) +, x5c_playerVelocity(CVector3f(0.f, 0.f, 0.f)) +, x68_playerPeakFallVel(0.f) +, x6c_landingVelocity(0.f) +, x70_landingTranslation(0.f) +, x74_camVelocity(0.f) +, x78_camTranslation(0.f) +, xc4_wanderTime(0.f) +, xc8_viewWanderSpeed(kViewWanderSpeedMin) +, xcc_wanderIndex(0) +, xd0_viewWanderXf(CTransform4f::Identity()) +, x100_wanderMagnitude(FLT_EPSILON) +, x104_targetWanderMagnitude(0.f) { + for (int i = 0; i < 4; ++i) { + x7c_wanderPoints.push_back(CVector3f(0.f, 1.f, 0.f)); + } + for (int i = 0; i < 4; ++i) { + xb0_wanderPitches.push_back(0.f); + } +} + +void CPlayerCameraBob::ReadTweaks(CInputStream& in) { + kCameraBobExtentX = in.ReadFloat(); + kCameraBobExtentY = in.ReadFloat(); + kCameraBobPeriod = in.ReadFloat(); + kOrbitBobScale = in.ReadFloat(); + kMaxOrbitBobScale = in.ReadFloat(); + kSlowSpeedPeriodScale = in.ReadFloat(); + kTargetMagnitudeTrackingRate = in.ReadFloat(); + kLandingBobSpringConstant = in.ReadFloat(); + kViewWanderRadius = in.ReadFloat(); + kViewWanderSpeedMin = in.ReadFloat(); + kViewWanderSpeedMax = in.ReadFloat(); + kViewWanderRollVariation = in.ReadFloat(); + kGunBobMagnitude = in.ReadFloat(); + kHelmetBobMagnitude = in.ReadFloat(); +}