From e1a97cab2de70db00d4c0fc9991242e137336ee6 Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Thu, 13 Jun 2024 17:53:45 -0400 Subject: [PATCH] Implement LegoAnimScene::FUN_1009f490 (#1032) * Implement LegoAnimScene::FUN_1009f490 * Update legoanim.cpp * Update legoanim.cpp * Update legoanim.cpp --- LEGO1/lego/sources/anim/legoanim.cpp | 89 ++++++++++++++++++++++++++-- LEGO1/lego/sources/anim/legoanim.h | 20 +++++-- 2 files changed, 98 insertions(+), 11 deletions(-) diff --git a/LEGO1/lego/sources/anim/legoanim.cpp b/LEGO1/lego/sources/anim/legoanim.cpp index 4be46ae4..45844ca9 100644 --- a/LEGO1/lego/sources/anim/legoanim.cpp +++ b/LEGO1/lego/sources/anim/legoanim.cpp @@ -18,7 +18,7 @@ DECOMP_SIZE_ASSERT(LegoAnim, 0x18) // FUNCTION: LEGO1 0x1009f000 LegoUnknownKey::LegoUnknownKey() { - m_unk0x08 = 0; + m_z = 0.0f; } // FUNCTION: LEGO1 0x1009f020 @@ -30,7 +30,7 @@ LegoResult LegoUnknownKey::Read(LegoStorage* p_storage) return result; } - result = p_storage->Read(&m_unk0x08, sizeof(m_unk0x08)); + result = p_storage->Read(&m_z, sizeof(m_z)); return result == SUCCESS ? SUCCESS : result; } @@ -136,11 +136,88 @@ LegoResult LegoAnimScene::Read(LegoStorage* p_storage) return result; } -// STUB: LEGO1 0x1009f490 -undefined4 LegoAnimScene::FUN_1009f490(LegoFloat p_time, Matrix4& p_matrix) +// FUNCTION: LEGO1 0x1009f490 +// FUNCTION: BETA10 0x10181a83 +LegoResult LegoAnimScene::FUN_1009f490(LegoFloat p_time, Matrix4& p_matrix) { - // TODO - return 0; + MxMatrix localb0; + MxMatrix local4c; + + Vector3 local5c(localb0[0]); + Vector3 local68(localb0[1]); + Vector3 local54(localb0[2]); + Vector3 localb8(localb0[3]); + + Mx3DPointFloat localcc; + + localb0.SetIdentity(); + + LegoU32 local60; + if (m_unk0x08 != 0) { + local60 = GetUnknown0x18(); + LegoAnimNodeData::GetTranslation(m_unk0x08, m_unk0x0c, p_time, localb0, local60); + SetUnknown0x18(local60); + localcc = localb8; + localb8.Clear(); + } + + if (m_unk0x00 != 0) { + local60 = GetUnknown0x1c(); + LegoAnimNodeData::GetTranslation(m_unk0x00, m_unk0x04, p_time, localb0, local60); + SetUnknown0x1c(local60); + } + + local54 = localcc; + ((Vector3&) local54).Sub(localb8); + + if (local54.Unitize() == 0) { + local5c.EqualsCross(&local68, &local54); + + if (local5c.Unitize() == 0) { + local68.EqualsCross(&local54, &local5c); + + localcc = p_matrix[3]; + ((Vector3&) localcc).Add(localb0[3]); + + p_matrix[3][0] = p_matrix[3][1] = p_matrix[3][2] = localb0[3][0] = localb0[3][1] = localb0[3][2] = 0; + + if (m_unk0x10 != 0) { + LegoU32 locald0 = -1; + LegoU32 locald8; + locald0 = GetUnknown0x20(); + + LegoU32 localdc = + LegoAnimNodeData::FindKeys(p_time, m_unk0x10, m_unk0x14, sizeof(*m_unk0x14), locald8, locald0); + + SetUnknown0x20(locald0); + + switch (localdc) { + case 1: + p_matrix.RotateZ(m_unk0x14[locald8].GetZ()); + break; + case 2: + // Seems to be unused + LegoFloat z = LegoAnimNodeData::Interpolate( + p_time, + m_unk0x14[locald8], + m_unk0x14[locald8].GetZ(), + m_unk0x14[locald8 + 1], + m_unk0x14[locald8 + 1].GetZ() + ); + p_matrix.RotateZ(m_unk0x14[locald8].GetZ()); + break; + } + } + + local4c = p_matrix; + p_matrix.Product(local4c.GetData(), localb0.GetData()); + p_matrix[3][0] = localcc[0]; + p_matrix[3][1] = localcc[1]; + p_matrix[3][2] = localcc[2]; + } + } + + return SUCCESS; } // FUNCTION: LEGO1 0x1009f900 diff --git a/LEGO1/lego/sources/anim/legoanim.h b/LEGO1/lego/sources/anim/legoanim.h index ae6f3bb6..8126c61b 100644 --- a/LEGO1/lego/sources/anim/legoanim.h +++ b/LEGO1/lego/sources/anim/legoanim.h @@ -103,8 +103,10 @@ class LegoUnknownKey : public LegoAnimKey { LegoUnknownKey(); LegoResult Read(LegoStorage* p_storage); + inline LegoFloat GetZ() { return m_z; } + protected: - undefined4 m_unk0x08; // 0x08 + LegoFloat m_z; // 0x08 }; // VTABLE: LEGO1 0x100db8c8 @@ -212,7 +214,15 @@ class LegoAnimScene { LegoAnimScene(); ~LegoAnimScene(); LegoResult Read(LegoStorage* p_storage); - undefined4 FUN_1009f490(LegoFloat p_time, Matrix4& p_matrix); + LegoResult FUN_1009f490(LegoFloat p_time, Matrix4& p_matrix); + + inline LegoU32 GetUnknown0x18() { return m_unk0x18; } + inline LegoU32 GetUnknown0x1c() { return m_unk0x1c; } + inline LegoU32 GetUnknown0x20() { return m_unk0x20; } + + inline void SetUnknown0x18(LegoU32 p_unk0x18) { m_unk0x18 = p_unk0x18; } + inline void SetUnknown0x1c(LegoU32 p_unk0x1c) { m_unk0x1c = p_unk0x1c; } + inline void SetUnknown0x20(LegoU32 p_unk0x20) { m_unk0x20 = p_unk0x20; } private: LegoU16 m_unk0x00; // 0x00 @@ -221,9 +231,9 @@ class LegoAnimScene { LegoTranslationKey* m_unk0x0c; // 0x0c LegoU16 m_unk0x10; // 0x10 LegoUnknownKey* m_unk0x14; // 0x14 - undefined4 m_unk0x18; // 0x18 - undefined4 m_unk0x1c; // 0x1c - undefined4 m_unk0x20; // 0x20 + LegoU32 m_unk0x18; // 0x18 + LegoU32 m_unk0x1c; // 0x1c + LegoU32 m_unk0x20; // 0x20 }; // VTABLE: LEGO1 0x100db8d8