From 3b2bd0e9d4ad46035d1c3ab5852cc558596ba9ec Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Tue, 5 Mar 2024 13:35:28 -0500 Subject: [PATCH] Implement/match LegoEntity::SetROI (#628) --- LEGO1/lego/legoomni/include/legoentity.h | 1 + LEGO1/lego/legoomni/src/entity/legoentity.cpp | 30 +++++++++++++++++-- LEGO1/lego/legoomni/src/entity/legoworld.cpp | 2 +- LEGO1/lego/sources/roi/legoroi.cpp | 4 +-- LEGO1/lego/sources/roi/legoroi.h | 6 ++-- 5 files changed, 34 insertions(+), 9 deletions(-) diff --git a/LEGO1/lego/legoomni/include/legoentity.h b/LEGO1/lego/legoomni/include/legoentity.h index b18799e1..5d290472 100644 --- a/LEGO1/lego/legoomni/include/legoentity.h +++ b/LEGO1/lego/legoomni/include/legoentity.h @@ -63,6 +63,7 @@ class LegoEntity : public MxEntity { inline MxU8 GetFlags() { return m_flags; } inline void SetFlags(MxU8 p_flags) { m_flags = p_flags; } + inline void SetFlag(MxU8 p_flag) { m_flags |= p_flag; } inline void ClearFlag(MxU8 p_flag) { m_flags &= ~p_flag; } protected: diff --git a/LEGO1/lego/legoomni/src/entity/legoentity.cpp b/LEGO1/lego/legoomni/src/entity/legoentity.cpp index c7060136..ddc98266 100644 --- a/LEGO1/lego/legoomni/src/entity/legoentity.cpp +++ b/LEGO1/lego/legoomni/src/entity/legoentity.cpp @@ -52,7 +52,7 @@ void LegoEntity::Destroy(MxBool p_fromDestructor) if (m_roi) { if (m_flags & c_bit1) { if (m_roi->GetUnknown0x104() == this) { - m_roi->SetUnknown0x104(NULL); + m_roi->SetEntity(NULL); } UnkSaveDataWriter()->FUN_10083db0(m_roi); @@ -76,10 +76,34 @@ void LegoEntity::SetWorld() } } -// STUB: LEGO1 0x100108a0 +// FUNCTION: LEGO1 0x100108a0 void LegoEntity::SetROI(LegoROI* p_roi, MxBool p_bool1, MxBool p_bool2) { - // TODO + m_roi = p_roi; + + if (m_roi != NULL) { + if (p_bool2) { + MxMatrix mat; + CalcLocalTransform( + Mx3DPointFloat(m_worldLocation.GetX(), m_worldLocation.GetY(), m_worldLocation.GetZ()), + Mx3DPointFloat(m_worldDirection.GetX(), m_worldDirection.GetY(), m_worldDirection.GetZ()), + Mx3DPointFloat(m_worldUp.GetX(), m_worldUp.GetY(), m_worldUp.GetZ()), + mat + ); + + m_roi->FUN_100a46b0(mat); + } + + m_roi->SetEntity(this); + VideoManager()->Get3DManager()->GetLego3DView()->Moved(*m_roi); + + if (p_bool1) { + ClearFlag(c_bit1); + } + else { + SetFlag(c_bit1); + } + } } // STUB: LEGO1 0x100109b0 diff --git a/LEGO1/lego/legoomni/src/entity/legoworld.cpp b/LEGO1/lego/legoomni/src/entity/legoworld.cpp index bdaece9b..d7aab174 100644 --- a/LEGO1/lego/legoomni/src/entity/legoworld.cpp +++ b/LEGO1/lego/legoomni/src/entity/legoworld.cpp @@ -546,7 +546,7 @@ void LegoWorld::Enable(MxBool p_enable) while (cursor.Next(entity)) { if (entity->GetROI()) { - entity->GetROI()->SetUnknown0x104(entity); + entity->GetROI()->SetEntity(entity); GetViewManager()->Add(entity->GetROI()); } } diff --git a/LEGO1/lego/sources/roi/legoroi.cpp b/LEGO1/lego/sources/roi/legoroi.cpp index e6f7aa33..0c8c31cd 100644 --- a/LEGO1/lego/sources/roi/legoroi.cpp +++ b/LEGO1/lego/sources/roi/legoroi.cpp @@ -73,7 +73,7 @@ LegoROI::LegoROI(Tgl::Renderer* p_renderer) : ViewROI(p_renderer, NULL) { m_unk0xd4 = NULL; m_name = NULL; - m_unk0x104 = NULL; + m_entity = NULL; } // FUNCTION: LEGO1 0x100a82d0 @@ -81,7 +81,7 @@ LegoROI::LegoROI(Tgl::Renderer* p_renderer, ViewLODList* p_lodList) : ViewROI(p_ { m_unk0xd4 = NULL; m_name = NULL; - m_unk0x104 = NULL; + m_entity = NULL; } // FUNCTION: LEGO1 0x100a83c0 diff --git a/LEGO1/lego/sources/roi/legoroi.h b/LEGO1/lego/sources/roi/legoroi.h index 5d589608..9c5028c3 100644 --- a/LEGO1/lego/sources/roi/legoroi.h +++ b/LEGO1/lego/sources/roi/legoroi.h @@ -76,9 +76,9 @@ class LegoROI : public ViewROI { ); inline const LegoChar* GetName() const { return m_name; } - inline LegoEntity* GetUnknown0x104() { return m_unk0x104; } + inline LegoEntity* GetUnknown0x104() { return m_entity; } - inline void SetUnknown0x104(LegoEntity* p_unk0x104) { m_unk0x104 = p_unk0x104; } + inline void SetEntity(LegoEntity* p_entity) { m_entity = p_entity; } // SYNTHETIC: LEGO1 0x100a82b0 // LegoROI::`scalar deleting destructor' @@ -87,7 +87,7 @@ class LegoROI : public ViewROI { LegoChar* m_name; // 0xe4 BoundingSphere m_sphere; // 0xe8 undefined m_unk0x100; // 0x100 - LegoEntity* m_unk0x104; // 0x104 + LegoEntity* m_entity; // 0x104 }; // VTABLE: LEGO1 0x100dbea8