From e6474b7fcda541b8d2b08f6e970a4ccb24c47bc7 Mon Sep 17 00:00:00 2001 From: jonschz <17198703+jonschz@users.noreply.github.com> Date: Fri, 4 Oct 2024 17:19:42 +0200 Subject: [PATCH] Implement `LegoCarBuildAnimPresenter::FUN_10079920()` (#1108) * Implement `FUN_10079920()` * Fix formatting * Address review comment --------- Co-authored-by: jonschz --- LEGO1/lego/legoomni/include/legocarbuild.h | 2 +- .../legoomni/include/legocarbuildpresenter.h | 7 ++-- .../lego/legoomni/src/build/legocarbuild.cpp | 4 +- .../src/build/legocarbuildpresenter.cpp | 41 +++++++++++++++++-- LEGO1/lego/sources/anim/legoanim.h | 30 ++++++++++++++ LEGO1/mxgeometry/mxgeometry3d.h | 1 + LEGO1/realtime/vector.h | 2 + 7 files changed, 77 insertions(+), 10 deletions(-) diff --git a/LEGO1/lego/legoomni/include/legocarbuild.h b/LEGO1/lego/legoomni/include/legocarbuild.h index 60b5a9c3..c06d4e9e 100644 --- a/LEGO1/lego/legoomni/include/legocarbuild.h +++ b/LEGO1/lego/legoomni/include/legocarbuild.h @@ -202,7 +202,7 @@ class LegoCarBuild : public LegoWorld { static MxS16 g_unk0x100f11cc; static MxFloat g_unk0x100d65a4; - static MxFloat g_unk0x100d65a8; + static MxFloat g_rotationAngleStepYAxis; }; #endif // LEGOCARBUILD_H diff --git a/LEGO1/lego/legoomni/include/legocarbuildpresenter.h b/LEGO1/lego/legoomni/include/legocarbuildpresenter.h index 8d707eff..8084da7c 100644 --- a/LEGO1/lego/legoomni/include/legocarbuildpresenter.h +++ b/LEGO1/lego/legoomni/include/legocarbuildpresenter.h @@ -45,7 +45,8 @@ class LegoCarBuildAnimPresenter : public LegoAnimPresenter { void EndAction() override; // vtable+0x40 void PutFrame() override; // vtable+0x6c - void FUN_10079920(float p_param1); + void FUN_10079160(); + void RotateAroundYAxis(MxFloat p_angle); MxBool FUN_10079c30(const LegoChar* p_name); MxBool FUN_10079ca0(const LegoChar* p_name); MxBool FUN_10079cf0(const LegoChar* p_string); @@ -64,11 +65,11 @@ class LegoCarBuildAnimPresenter : public LegoAnimPresenter { undefined2 m_unk0xbc; // 0xbc MxS16 m_unk0xbe; // 0xbe MxS16 m_unk0xc0; // 0xc0 - undefined4 m_unk0xc4; // 0xc4 + LegoAnimNodeData* m_unk0xc4; // 0xc4 LegoAnim m_unk0xc8; // 0xc8 MxMatrix m_unk0xe0; // 0xe0 UnknownListEntry* m_unk0x128; // 0x128 - undefined4 m_unk0x12c; // 0x12c + MxFloat m_unk0x12c; // 0x12c undefined4 m_unk0x130; // 0x130 undefined4 m_unk0x134; // 0x134 undefined4 m_unk0x138; // 0x138 diff --git a/LEGO1/lego/legoomni/src/build/legocarbuild.cpp b/LEGO1/lego/legoomni/src/build/legocarbuild.cpp index 2d6501c7..b9865c1b 100644 --- a/LEGO1/lego/legoomni/src/build/legocarbuild.cpp +++ b/LEGO1/lego/legoomni/src/build/legocarbuild.cpp @@ -26,7 +26,7 @@ DECOMP_SIZE_ASSERT(LegoVehicleBuildState, 0x50) MxFloat LegoCarBuild::g_unk0x100d65a4 = -0.1f; // GLOBAL: LEGO1 0x100d65a8 -MxFloat LegoCarBuild::g_unk0x100d65a8 = 0.07; +MxFloat LegoCarBuild::g_rotationAngleStepYAxis = 0.07; // GLOBAL: LEGO1 0x100f11cc MxS16 LegoCarBuild::g_unk0x100f11cc = -1; @@ -783,7 +783,7 @@ void LegoCarBuild::FUN_10024ef0() void LegoCarBuild::FUN_10024f50() { m_unk0x2d4 = FALSE; - m_unk0x258->FUN_10079920(g_unk0x100d65a8); + m_unk0x258->RotateAroundYAxis(g_rotationAngleStepYAxis); } // FUNCTION: LEGO1 0x10024f70 diff --git a/LEGO1/lego/legoomni/src/build/legocarbuildpresenter.cpp b/LEGO1/lego/legoomni/src/build/legocarbuildpresenter.cpp index 2ed86f7b..29b35d21 100644 --- a/LEGO1/lego/legoomni/src/build/legocarbuildpresenter.cpp +++ b/LEGO1/lego/legoomni/src/build/legocarbuildpresenter.cpp @@ -14,7 +14,7 @@ LegoCarBuildAnimPresenter::LegoCarBuildAnimPresenter() m_unk0xbe = 0; m_unk0xc0 = 0; m_unk0x128 = NULL; - m_unk0xc4 = 0; + m_unk0xc4 = NULL; m_unk0x130 = 0; m_unk0x12c = 0; m_unk0x134 = 0; @@ -83,13 +83,46 @@ void LegoCarBuildAnimPresenter::EndAction() } } -// STUB: LEGO1 0x10079920 -// STUB: BETA10 0x1007225d -void LegoCarBuildAnimPresenter::FUN_10079920(float p_param1) +// STUB: LEGO1 0x10079160 +void LegoCarBuildAnimPresenter::FUN_10079160() { + // called from LegoCarBuildAnimPresenter::StreamingTickle() // TODO } +// FUNCTION: LEGO1 0x10079920 +// FUNCTION: BETA10 0x1007225d +void LegoCarBuildAnimPresenter::RotateAroundYAxis(MxFloat p_angle) +{ + if (m_unk0xc4) { + LegoRotationKey* rotationKey = m_unk0xc4->GetRotationKey(0); + + Mx4DPointFloat + currentRotation(rotationKey->GetX(), rotationKey->GetY(), rotationKey->GetZ(), rotationKey->GetAngle()); + Mx4DPointFloat additionalRotation(0.0f, 1.0f, 0.0f, -p_angle); + Mx4DPointFloat newRotation; + + additionalRotation.NormalizeQuaternion(); + newRotation.EqualsHamiltonProduct(¤tRotation, &additionalRotation); + + if (newRotation[3] < 0.9999) { + rotationKey->FUN_100739a0(TRUE); + } + else { + rotationKey->FUN_100739a0(FALSE); + } + + m_unk0xc4->GetRotationKey(0)->SetX(newRotation[0]); + m_unk0xc4->GetRotationKey(0)->SetY(newRotation[1]); + m_unk0xc4->GetRotationKey(0)->SetZ(newRotation[2]); + m_unk0xc4->GetRotationKey(0)->SetAngle(newRotation[3]); + + if (m_unk0x140->GetROI()) { + FUN_1006b9a0(&m_unk0xc8, m_unk0x12c, NULL); + } + } +} + // FUNCTION: LEGO1 0x10079b80 // FUNCTION: BETA10 0x1007258f MxBool LegoCarBuildAnimPresenter::StringEndsOnYOrN(const LegoChar* p_string) diff --git a/LEGO1/lego/sources/anim/legoanim.h b/LEGO1/lego/sources/anim/legoanim.h index 1a861eb6..0badeae9 100644 --- a/LEGO1/lego/sources/anim/legoanim.h +++ b/LEGO1/lego/sources/anim/legoanim.h @@ -24,6 +24,17 @@ class LegoAnimKey { LegoU32 TestBit2() { return m_flags & c_bit2; } LegoU32 TestBit3() { return m_flags & c_bit3; } + // FUNCTION: BETA10 0x100739a0 + void FUN_100739a0(MxS32 p_param) + { + if (p_param) { + m_flags |= c_bit1; + } + else { + m_flags &= ~c_bit1; + } + } + protected: LegoU8 m_flags; // 0x00 LegoFloat m_time; // 0x04 @@ -52,13 +63,29 @@ class LegoRotationKey : public LegoAnimKey { public: LegoRotationKey(); LegoResult Read(LegoStorage* p_storage); + + // FUNCTION: BETA10 0x10073a00 LegoFloat GetAngle() { return m_angle; } + + // FUNCTION: BETA10 0x10073a30 void SetAngle(LegoFloat p_angle) { m_angle = p_angle; } + + // FUNCTION: BETA10 0x10073a60 LegoFloat GetX() { return m_x; } + + // FUNCTION: BETA10 0x10073a90 void SetX(LegoFloat p_x) { m_x = p_x; } + + // FUNCTION: BETA10 0x10073ac0 LegoFloat GetY() { return m_y; } + + // FUNCTION: BETA10 0x10073af0 void SetY(LegoFloat p_y) { m_y = p_y; } + + // FUNCTION: BETA10 0x10073b20 LegoFloat GetZ() { return m_z; } + + // FUNCTION: BETA10 0x10073b50 void SetZ(LegoFloat p_z) { m_z = p_z; } protected: @@ -129,6 +156,9 @@ class LegoAnimNodeData : public LegoTreeNodeData { LegoU16 GetUnknown0x20() { return m_unk0x20; } LegoU16 GetUnknown0x22() { return m_unk0x22; } + // FUNCTION: BETA10 0x10073b80 + LegoRotationKey* GetRotationKey(MxS32 index) { return &m_rotationKeys[index]; } + void SetTranslationIndex(LegoU32 p_translationIndex) { m_translationIndex = p_translationIndex; } void SetRotationIndex(LegoU32 p_rotationIndex) { m_rotationIndex = p_rotationIndex; } void SetScaleIndex(LegoU32 p_scaleIndex) { m_scaleIndex = p_scaleIndex; } diff --git a/LEGO1/mxgeometry/mxgeometry3d.h b/LEGO1/mxgeometry/mxgeometry3d.h index f5e2c083..f73d5d8a 100644 --- a/LEGO1/mxgeometry/mxgeometry3d.h +++ b/LEGO1/mxgeometry/mxgeometry3d.h @@ -50,6 +50,7 @@ class Mx3DPointFloat : public Vector3 { class Mx4DPointFloat : public Vector4 { public: // FUNCTION: LEGO1 0x10048290 + // FUNCTION: BETA10 0x100484c0 Mx4DPointFloat() : Vector4(m_elements) {} // FUNCTION: BETA10 0x10073bb0 diff --git a/LEGO1/realtime/vector.h b/LEGO1/realtime/vector.h index 4c1e17c3..3faa559e 100644 --- a/LEGO1/realtime/vector.h +++ b/LEGO1/realtime/vector.h @@ -182,6 +182,7 @@ class Vector2 { class Vector3 : public Vector2 { public: // FUNCTION: LEGO1 0x1001d150 + // FUNCTION: BETA10 0x10011660 Vector3(float* p_data) : Vector2(p_data) {} // Hack: Some code initializes a Vector3 from a (most likely) const float* source. @@ -298,6 +299,7 @@ class Vector3 : public Vector2 { // SIZE 0x08 class Vector4 : public Vector3 { public: + // FUNCTION: BETA10 0x10048780 Vector4(float* p_data) : Vector3(p_data) {} // Hack: Some code initializes a Vector4 from a (most likely) const float* source.