From e1a1aea32f313c440c588cbfe9cbbdccea1ad86a Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Tue, 31 Dec 2024 11:03:37 -0700 Subject: [PATCH 01/16] Order experimentation --- LEGO1/lego/legoomni/include/helicopter.h | 12 +- LEGO1/lego/legoomni/include/islepathactor.h | 37 +- .../legoomni/include/legoanimationmanager.h | 1 + LEGO1/lego/sources/anim/legoanim.cpp | 1 + LEGO1/lego/sources/geom/legowegedge.h | 1 + LEGO1/lego/sources/roi/legoroi.cpp | 1 + LEGO1/mxgeometry/mxgeometry3d.h | 195 -------- LEGO1/mxgeometry/mxgeometry4d.h | 197 ++++++++ LEGO1/mxgeometry/mxmatrix.h | 34 +- LEGO1/realtime/matrix.h | 351 -------------- LEGO1/realtime/vector.h | 433 ++++++++++++++++-- 11 files changed, 634 insertions(+), 629 deletions(-) create mode 100644 LEGO1/mxgeometry/mxgeometry4d.h diff --git a/LEGO1/lego/legoomni/include/helicopter.h b/LEGO1/lego/legoomni/include/helicopter.h index 8d887d7369..2e49c024ae 100644 --- a/LEGO1/lego/legoomni/include/helicopter.h +++ b/LEGO1/lego/legoomni/include/helicopter.h @@ -44,17 +44,16 @@ class HelicopterState : public LegoState { MxU32 m_unk0x08; // 0x08 }; +#include "mxgeometry/mxgeometry4d.h" + // VTABLE: LEGO1 0x100d40f8 // VTABLE: BETA10 0x101b9880 // SIZE 0x230 class Helicopter : public IslePathActor { public: - Helicopter(); - ~Helicopter() override; // vtable+0x00 - // FUNCTION: LEGO1 0x10003070 // FUNCTION: BETA10 0x1002b300 - const char* ClassName() const override // vtable+0x0c + virtual const char* ClassName() const override // vtable+0x0c { // STRING: LEGO1 0x100f0130 return "Helicopter"; @@ -62,11 +61,14 @@ class Helicopter : public IslePathActor { // FUNCTION: LEGO1 0x10003080 // FUNCTION: BETA10 0x1002b330 - MxBool IsA(const char* p_name) const override // vtable+0x10 + virtual MxBool IsA(const char* p_name) const override // vtable+0x10 { return !strcmp(p_name, Helicopter::ClassName()) || IslePathActor::IsA(p_name); } + Helicopter(); + ~Helicopter() override; // vtable+0x00 + MxResult Create(MxDSAction& p_dsAction) override; // vtable+0x18 void Animate(float p_time) override; // vtable+0x70 void VTable0x74(Matrix4& p_transform) override; // vtable+0x74 diff --git a/LEGO1/lego/legoomni/include/islepathactor.h b/LEGO1/lego/legoomni/include/islepathactor.h index 1aa5616a98..4a2356691a 100644 --- a/LEGO1/lego/legoomni/include/islepathactor.h +++ b/LEGO1/lego/legoomni/include/islepathactor.h @@ -86,10 +86,27 @@ class IslePathActor : public LegoPathActor { IslePathActor(); + // FUNCTION: LEGO1 0x10002df0 + virtual MxLong HandleNotification0() { return 0; } // vtable+0xd0 + + // FUNCTION: LEGO1 0x10002e00 + virtual MxLong HandlePathStruct(LegoPathStructNotificationParam&) { return 0; } // vtable+0xdc + // FUNCTION: LEGO1 0x10002e10 ~IslePathActor() override { IslePathActor::Destroy(TRUE); } - MxLong Notify(MxParam& p_param) override; // vtable+0x04 + // FUNCTION: LEGO1 0x10002e70 + virtual MxLong HandleClick() { return 0; } // vtable+0xcc + + // FUNCTION: LEGO1 0x10002e80 + virtual MxLong HandleControl(LegoControlManagerNotificationParam&) { return 0; } // vtable+0xd4 + + // FUNCTION: LEGO1 0x10002e90 + virtual MxLong HandleEndAnim(LegoEndAnimNotificationParam&) { return 0; } // vtable+0xd8 + + MxLong Notify(MxParam& p_param) override; // vtable+0x04 + MxResult Create(MxDSAction& p_dsAction) override; // vtable+0x18 + void Destroy(MxBool p_fromDestructor) override; // vtable+0x1c // FUNCTION: LEGO1 0x10002ea0 // FUNCTION: BETA10 0x10023fa0 @@ -105,24 +122,6 @@ class IslePathActor : public LegoPathActor { return !strcmp(p_name, IslePathActor::ClassName()) || LegoPathActor::IsA(p_name); } - MxResult Create(MxDSAction& p_dsAction) override; // vtable+0x18 - void Destroy(MxBool p_fromDestructor) override; // vtable+0x1c - - // FUNCTION: LEGO1 0x10002e70 - virtual MxLong HandleClick() { return 0; } // vtable+0xcc - - // FUNCTION: LEGO1 0x10002df0 - virtual MxLong HandleNotification0() { return 0; } // vtable+0xd0 - - // FUNCTION: LEGO1 0x10002e80 - virtual MxLong HandleControl(LegoControlManagerNotificationParam&) { return 0; } // vtable+0xd4 - - // FUNCTION: LEGO1 0x10002e90 - virtual MxLong HandleEndAnim(LegoEndAnimNotificationParam&) { return 0; } // vtable+0xd8 - - // FUNCTION: LEGO1 0x10002e00 - virtual MxLong HandlePathStruct(LegoPathStructNotificationParam&) { return 0; } // vtable+0xdc - virtual void Enter(); // vtable+0xe0 virtual void Exit(); // vtable+0xe4 virtual void SpawnPlayer(LegoGameState::Area p_area, MxBool p_enter, MxU8 p_flags); // vtable+0xe8 diff --git a/LEGO1/lego/legoomni/include/legoanimationmanager.h b/LEGO1/lego/legoomni/include/legoanimationmanager.h index 56f6d0a795..324307292c 100644 --- a/LEGO1/lego/legoomni/include/legoanimationmanager.h +++ b/LEGO1/lego/legoomni/include/legoanimationmanager.h @@ -8,6 +8,7 @@ #include "legotraninfolist.h" #include "mxcore.h" #include "mxgeometry/mxgeometry3d.h" +#include "mxgeometry/mxgeometry4d.h" class LegoAnimPresenter; class LegoEntity; diff --git a/LEGO1/lego/sources/anim/legoanim.cpp b/LEGO1/lego/sources/anim/legoanim.cpp index 39b8921bd3..e367b8157e 100644 --- a/LEGO1/lego/sources/anim/legoanim.cpp +++ b/LEGO1/lego/sources/anim/legoanim.cpp @@ -1,5 +1,6 @@ #include "legoanim.h" +#include "mxgeometry/mxgeometry4d.h" #include "mxgeometry/mxmatrix.h" #include diff --git a/LEGO1/lego/sources/geom/legowegedge.h b/LEGO1/lego/sources/geom/legowegedge.h index 77567bfe93..350e31b7fe 100644 --- a/LEGO1/lego/sources/geom/legowegedge.h +++ b/LEGO1/lego/sources/geom/legowegedge.h @@ -4,6 +4,7 @@ #include "decomp.h" #include "legoweedge.h" #include "mxgeometry/mxgeometry3d.h" +#include "mxgeometry/mxgeometry4d.h" class LegoPathStruct; diff --git a/LEGO1/lego/sources/roi/legoroi.cpp b/LEGO1/lego/sources/roi/legoroi.cpp index 6598af3e60..2c0bc7dee0 100644 --- a/LEGO1/lego/sources/roi/legoroi.cpp +++ b/LEGO1/lego/sources/roi/legoroi.cpp @@ -4,6 +4,7 @@ #include "legolod.h" #include "misc/legocontainer.h" #include "misc/legostorage.h" +#include "mxgeometry/mxgeometry4d.h" #include "realtime/realtime.h" #include "shape/legobox.h" #include "shape/legosphere.h" diff --git a/LEGO1/mxgeometry/mxgeometry3d.h b/LEGO1/mxgeometry/mxgeometry3d.h index 1b41d03e5c..f35daeb21d 100644 --- a/LEGO1/mxgeometry/mxgeometry3d.h +++ b/LEGO1/mxgeometry/mxgeometry3d.h @@ -53,199 +53,4 @@ class Mx3DPointFloat : public Vector3 { float m_elements[3]; // 0x08 }; -// VTABLE: LEGO1 0x100d41e8 -// VTABLE: BETA10 0x101bab78 -// SIZE 0x18 -class Mx4DPointFloat : public Vector4 { -public: - // FUNCTION: LEGO1 0x10048290 - // FUNCTION: BETA10 0x100484c0 - Mx4DPointFloat() : Vector4(m_elements) {} - - // FUNCTION: BETA10 0x10073bb0 - Mx4DPointFloat(float p_x, float p_y, float p_z, float p_a) : Vector4(m_elements) - { - m_elements[0] = p_x; - m_elements[1] = p_y; - m_elements[2] = p_z; - m_elements[3] = p_a; - } - - Mx4DPointFloat(const Mx4DPointFloat& p_other) : Vector4(m_elements) { EqualsImpl(p_other.m_data); } - - // FUNCTION: LEGO1 0x10003200 - virtual void operator=(const Vector4& p_impl) { EqualsImpl(p_impl.m_data); } // vtable+0x98 - - // FUNCTION: BETA10 0x1004af10 - float& operator[](int idx) { return m_data[idx]; } - - // According to the PDB, BETA10 will not link this one if it is never used - // const float& operator[](int idx) const { return m_data[idx]; } - - // only used by a couple of BETA10 functions for some unknown reason - // FUNCTION: BETA10 0x1001c950 - float& index_operator(int idx) { return m_data[idx]; } - - // SYNTHETIC: LEGO1 0x10064b20 - // SYNTHETIC: BETA10 0x10070420 - // ??4Mx4DPointFloat@@QAEAAV0@ABV0@@Z - -private: - float m_elements[4]; // 0x08 -}; - -// SIZE 0x34 -class UnknownMx4DPointFloat { -public: - enum { - c_bit1 = 0x01, - c_bit2 = 0x02 - }; - - UnknownMx4DPointFloat() : m_unk0x30(0) {} - - // FUNCTION: BETA10 0x1004a9b0 - void BETA_1004a9b0(Matrix4& p_m1, Matrix4& p_m2) - { - BETA_1004a9f0(p_m1); - FUN_10004620(p_m2); - } - - // FUNCTION: BETA10 0x1004a9f0 - void BETA_1004a9f0(Matrix4& p_m) - { - p_m.ToQuaternion(m_unk0x00); - m_unk0x30 |= c_bit1; - } - - // FUNCTION: LEGO1 0x10004620 - // FUNCTION: BETA10 0x1004aa30 - void FUN_10004620(Matrix4& p_m) - { - p_m.ToQuaternion(m_unk0x18); - m_unk0x30 |= c_bit2; - } - - // FUNCTION: BETA10 0x10180b80 - void BETA_10180b80(Vector4& p_v) - { - m_unk0x00 = p_v; - m_unk0x30 |= c_bit1; - } - - // FUNCTION: BETA10 0x10180bc0 - void BETA_10180bc0(Vector4& p_v) - { - m_unk0x18 = p_v; - m_unk0x30 |= c_bit2; - } - - const Vector4& GetUnknown0x00() const { return m_unk0x00; } - const Vector4& GetUnknown0x18() const { return m_unk0x18; } - undefined4 GetUnknown0x30() const { return m_unk0x30; } - - inline int BETA_1004aaa0(Matrix4& p_matrix, float p_f); - inline long FUN_10004520(); - -private: - inline int FUN_100040a0(Vector4& p_v, float p_f); - - Mx4DPointFloat m_unk0x00; // 0x00 - Mx4DPointFloat m_unk0x18; // 0x18 - undefined4 m_unk0x30; // 0x30 -}; - -// FUNCTION: BETA10 0x1004aaa0 -inline int UnknownMx4DPointFloat::BETA_1004aaa0(Matrix4& p_matrix, float p_f) -{ - float data[4]; - Vector4 v(data); - - if (FUN_100040a0(v, p_f) == 0) { - return p_matrix.FromQuaternion(v); - } - - return -1; -} - -// FUNCTION: LEGO1 0x10004520 -inline long UnknownMx4DPointFloat::FUN_10004520() -{ - if (!m_unk0x30) { - return -1; - } - - Mx4DPointFloat v1; - Mx4DPointFloat v2; - - v1 = m_unk0x00; - v1 += m_unk0x18; - - v2 = m_unk0x00; - v2 -= m_unk0x18; - - if (v1.Dot(v1, v1) < v2.Dot(v2, v2)) { - m_unk0x18 *= -1.0f; - } - - return 0; -} - -// FUNCTION: LEGO1 0x100040a0 -// FUNCTION: BETA10 0x1004ab10 -inline int UnknownMx4DPointFloat::FUN_100040a0(Vector4& p_v, float p_f) -{ - if (m_unk0x30 == c_bit1) { - p_v = m_unk0x00; - p_v[3] = (float) ((1.0 - p_f) * acos((double) p_v[3]) * 2.0); - return p_v.NormalizeQuaternion(); - } - - if (m_unk0x30 == c_bit2) { - p_v = m_unk0x18; - p_v[3] = (float) (p_f * acos((double) p_v[3]) * 2.0); - return p_v.NormalizeQuaternion(); - } - - if (m_unk0x30 == (c_bit1 | c_bit2)) { - int i; - double d1 = p_v.Dot(m_unk0x00, m_unk0x18); - double a; - double b; - - if (d1 + 1.0 > 0.00001) { - if (1.0 - d1 > 0.00001) { - double d2 = acos(d1); - double denominator = sin(d2); - a = sin((1.0 - p_f) * d2) / denominator; - b = sin(p_f * d2) / denominator; - } - else { - a = 1.0 - p_f; - b = p_f; - } - - for (i = 0; i < 4; i++) { - p_v[i] = (float) (m_unk0x00[i] * a + m_unk0x18[i] * b); - } - } - else { - p_v[0] = -m_unk0x00[1]; - p_v[1] = m_unk0x00[0]; - p_v[2] = -m_unk0x00[3]; - p_v[3] = m_unk0x00[2]; - a = sin((1.0 - p_f) * 1.570796326794895); - b = sin(p_f * 1.570796326794895); - - for (i = 0; i < 3; i++) { - p_v[i] = (float) (m_unk0x00[i] * a + p_v[i] * b); - } - } - - return 0; - } - - return -1; -} - #endif // MXGEOMETRY3D_H diff --git a/LEGO1/mxgeometry/mxgeometry4d.h b/LEGO1/mxgeometry/mxgeometry4d.h new file mode 100644 index 0000000000..349854c116 --- /dev/null +++ b/LEGO1/mxgeometry/mxgeometry4d.h @@ -0,0 +1,197 @@ +#ifndef MXGEOMETRY4D_H +#define MXGEOMETRY4D_H + +#include "decomp.h" +#include "realtime/vector.h" + +// VTABLE: LEGO1 0x100d41e8 +// VTABLE: BETA10 0x101bab78 +// SIZE 0x18 +class Mx4DPointFloat : public Vector4 { +public: + // FUNCTION: LEGO1 0x10048290 + // FUNCTION: BETA10 0x100484c0 + Mx4DPointFloat() : Vector4(m_elements) {} + + // FUNCTION: BETA10 0x10073bb0 + Mx4DPointFloat(float p_x, float p_y, float p_z, float p_a) : Vector4(m_elements) + { + m_elements[0] = p_x; + m_elements[1] = p_y; + m_elements[2] = p_z; + m_elements[3] = p_a; + } + + Mx4DPointFloat(const Mx4DPointFloat& p_other) : Vector4(m_elements) { EqualsImpl(p_other.m_data); } + + // FUNCTION: LEGO1 0x10003200 + virtual void operator=(const Vector4& p_impl) { EqualsImpl(p_impl.m_data); } // vtable+0x98 + + // FUNCTION: BETA10 0x1004af10 + float& operator[](int idx) { return m_data[idx]; } + + // According to the PDB, BETA10 will not link this one if it is never used + // const float& operator[](int idx) const { return m_data[idx]; } + + // only used by a couple of BETA10 functions for some unknown reason + // FUNCTION: BETA10 0x1001c950 + float& index_operator(int idx) { return m_data[idx]; } + + // SYNTHETIC: LEGO1 0x10064b20 + // SYNTHETIC: BETA10 0x10070420 + // ??4Mx4DPointFloat@@QAEAAV0@ABV0@@Z + +private: + float m_elements[4]; // 0x08 +}; + +// SIZE 0x34 +class UnknownMx4DPointFloat { +public: + enum { + c_bit1 = 0x01, + c_bit2 = 0x02 + }; + + UnknownMx4DPointFloat() : m_unk0x30(0) {} + + // FUNCTION: BETA10 0x1004a9b0 + void BETA_1004a9b0(Matrix4& p_m1, Matrix4& p_m2) + { + BETA_1004a9f0(p_m1); + FUN_10004620(p_m2); + } + + // FUNCTION: BETA10 0x1004a9f0 + void BETA_1004a9f0(Matrix4& p_m) + { + p_m.ToQuaternion(m_unk0x00); + m_unk0x30 |= c_bit1; + } + + // FUNCTION: LEGO1 0x10004620 + // FUNCTION: BETA10 0x1004aa30 + void FUN_10004620(Matrix4& p_m) + { + p_m.ToQuaternion(m_unk0x18); + m_unk0x30 |= c_bit2; + } + + // FUNCTION: BETA10 0x10180b80 + void BETA_10180b80(Vector4& p_v) + { + m_unk0x00 = p_v; + m_unk0x30 |= c_bit1; + } + + // FUNCTION: BETA10 0x10180bc0 + void BETA_10180bc0(Vector4& p_v) + { + m_unk0x18 = p_v; + m_unk0x30 |= c_bit2; + } + + const Vector4& GetUnknown0x00() const { return m_unk0x00; } + const Vector4& GetUnknown0x18() const { return m_unk0x18; } + undefined4 GetUnknown0x30() const { return m_unk0x30; } + + // FUNCTION: BETA10 0x1004aaa0 + inline int BETA_1004aaa0(Matrix4& p_matrix, float p_f) + { + float data[4]; + Vector4 v(data); + + if (FUN_100040a0(v, p_f) == 0) { + return p_matrix.FromQuaternion(v); + } + + return -1; + } + + // FUNCTION: LEGO1 0x10004520 + inline long FUN_10004520() + { + if (!m_unk0x30) { + return -1; + } + + Mx4DPointFloat v1; + Mx4DPointFloat v2; + + v1 = m_unk0x00; + v1 += m_unk0x18; + + v2 = m_unk0x00; + v2 -= m_unk0x18; + + if (v1.Dot(v1, v1) < v2.Dot(v2, v2)) { + m_unk0x18 *= -1.0f; + } + + return 0; + } + +private: + // FUNCTION: LEGO1 0x100040a0 + // FUNCTION: BETA10 0x1004ab10 + inline int FUN_100040a0(Vector4& p_v, float p_f) + { + if (m_unk0x30 == c_bit1) { + p_v = m_unk0x00; + p_v[3] = (float) ((1.0 - p_f) * acos((double) p_v[3]) * 2.0); + return p_v.NormalizeQuaternion(); + } + + if (m_unk0x30 == c_bit2) { + p_v = m_unk0x18; + p_v[3] = (float) (p_f * acos((double) p_v[3]) * 2.0); + return p_v.NormalizeQuaternion(); + } + + if (m_unk0x30 == (c_bit1 | c_bit2)) { + int i; + double d1 = p_v.Dot(m_unk0x00, m_unk0x18); + double a; + double b; + + if (d1 + 1.0 > 0.00001) { + if (1.0 - d1 > 0.00001) { + double d2 = acos(d1); + double denominator = sin(d2); + a = sin((1.0 - p_f) * d2) / denominator; + b = sin(p_f * d2) / denominator; + } + else { + a = 1.0 - p_f; + b = p_f; + } + + for (i = 0; i < 4; i++) { + p_v[i] = (float) (m_unk0x00[i] * a + m_unk0x18[i] * b); + } + } + else { + p_v[0] = -m_unk0x00[1]; + p_v[1] = m_unk0x00[0]; + p_v[2] = -m_unk0x00[3]; + p_v[3] = m_unk0x00[2]; + a = sin((1.0 - p_f) * 1.570796326794895); + b = sin(p_f * 1.570796326794895); + + for (i = 0; i < 3; i++) { + p_v[i] = (float) (m_unk0x00[i] * a + p_v[i] * b); + } + } + + return 0; + } + + return -1; + } + + Mx4DPointFloat m_unk0x00; // 0x00 + Mx4DPointFloat m_unk0x18; // 0x18 + undefined4 m_unk0x30; // 0x30 +}; + +#endif // MXGEOMETRY4D_H diff --git a/LEGO1/mxgeometry/mxmatrix.h b/LEGO1/mxgeometry/mxmatrix.h index 9f1aa59fe3..c9aa762032 100644 --- a/LEGO1/mxgeometry/mxmatrix.h +++ b/LEGO1/mxgeometry/mxmatrix.h @@ -1,38 +1,6 @@ #ifndef MXMATRIX_H #define MXMATRIX_H -#include "realtime/matrix.h" - -// VTABLE: LEGO1 0x100d4300 -// VTABLE: BETA10 0x101b82e0 -// SIZE 0x48 -class MxMatrix : public Matrix4 { -public: - // FUNCTION: LEGO1 0x1006b120 - // FUNCTION: BETA10 0x10015370 - MxMatrix() : Matrix4(m_elements) {} - - // FUNCTION: LEGO1 0x10032770 - // FUNCTION: BETA10 0x1001ff30 - MxMatrix(const MxMatrix& p_matrix) : Matrix4(m_elements) { Equals(p_matrix); } - - // FUNCTION: BETA10 0x1000fc20 - MxMatrix(const Matrix4& p_matrix) : Matrix4(m_elements) { Equals(p_matrix); } - - // FUNCTION: BETA10 0x10010860 - float* operator[](int idx) { return m_data[idx]; } - - // FUNCTION: BETA10 0x1001c670 - const float* operator[](int idx) const { return m_data[idx]; } - - // FUNCTION: LEGO1 0x10002850 - void operator=(const Matrix4& p_matrix) override { Equals(p_matrix); } // vtable+0x28 - - // FUNCTION: LEGO1 0x10002860 - virtual void operator=(const MxMatrix& p_matrix) { Equals(p_matrix); } // vtable+0x48 - -private: - float m_elements[4][4]; // 0x08 -}; +#include "realtime/vector.h" #endif // MXMATRIX_H diff --git a/LEGO1/realtime/matrix.h b/LEGO1/realtime/matrix.h index 8704d739ff..3229511377 100644 --- a/LEGO1/realtime/matrix.h +++ b/LEGO1/realtime/matrix.h @@ -3,358 +3,7 @@ #include "vector.h" -#include - -struct UnknownMatrixType { - float m_data[4][4]; -}; - // Note: Many functions most likely take const references/pointers instead of non-const. // The class needs to undergo a very careful refactoring to fix that (no matches should break). -// VTABLE: LEGO1 0x100d4350 -// VTABLE: BETA10 0x101b8340 -// SIZE 0x08 -class Matrix4 { -public: - // FUNCTION: LEGO1 0x10004500 - // FUNCTION: BETA10 0x1000fc70 - Matrix4(float (*p_data)[4]) { SetData(p_data); } - - // Note: virtual function overloads appear in the virtual table - // in reverse order of appearance. - - // FUNCTION: LEGO1 0x10002320 - // FUNCTION: BETA10 0x1000fcb0 - virtual void Equals(float (*p_data)[4]) { memcpy(m_data, p_data, sizeof(float) * 4 * 4); } // vtable+0x04 - - // FUNCTION: LEGO1 0x10002340 - // FUNCTION: BETA10 0x1000fcf0 - virtual void Equals(const Matrix4& p_matrix) - { - memcpy(m_data, p_matrix.m_data, sizeof(float) * 4 * 4); - } // vtable+0x00 - - // FUNCTION: LEGO1 0x10002360 - // FUNCTION: BETA10 0x1000fd30 - virtual void SetData(float (*p_data)[4]) { m_data = p_data; } // vtable+0x0c - - // FUNCTION: LEGO1 0x10002370 - // FUNCTION: BETA10 0x1000fd60 - virtual void SetData(UnknownMatrixType& p_matrix) { m_data = p_matrix.m_data; } // vtable+0x08 - - // FUNCTION: LEGO1 0x10002380 - // FUNCTION: BETA10 0x1000fd90 - virtual float (*GetData())[4] { return m_data; } // vtable+0x14 - - // FUNCTION: LEGO1 0x10002390 - // FUNCTION: BETA10 0x1000fdc0 - virtual float (*GetData() const)[4] { return m_data; } // vtable+0x10 - - // FUNCTION: LEGO1 0x100023a0 - // FUNCTION: BETA10 0x1000fdf0 - virtual float* Element(int p_row, int p_col) { return &m_data[p_row][p_col]; } // vtable+0x1c - - // FUNCTION: LEGO1 0x100023c0 - // FUNCTION: BETA10 0x1000fe30 - virtual const float* Element(int p_row, int p_col) const { return &m_data[p_row][p_col]; } // vtable+0x18 - - // FUNCTION: LEGO1 0x100023e0 - // FUNCTION: BETA10 0x1000fe70 - virtual void Clear() { memset(m_data, 0, 16 * sizeof(float)); } // vtable+0x20 - - // FUNCTION: LEGO1 0x100023f0 - // FUNCTION: BETA10 0x1000feb0 - virtual void SetIdentity() - { - Clear(); - m_data[0][0] = 1.0f; - m_data[1][1] = 1.0f; - m_data[2][2] = 1.0f; - m_data[3][3] = 1.0f; - } // vtable+0x24 - - // FUNCTION: LEGO1 0x10002420 - // FUNCTION: BETA10 0x1000ff20 - virtual void operator=(const Matrix4& p_matrix) { Equals(p_matrix); } // vtable+0x28 - - // FUNCTION: LEGO1 0x10002430 - // FUNCTION: BETA10 0x1000ff50 - virtual Matrix4& operator+=(float (*p_data)[4]) - { - for (int i = 0; i < 16; i++) { - ((float*) m_data)[i] += ((float*) p_data)[i]; - } - return *this; - } // vtable+0x2c - - // FUNCTION: LEGO1 0x10002460 - // FUNCTION: BETA10 0x1000ffc0 - virtual void TranslateBy(const float& p_x, const float& p_y, const float& p_z) - { - m_data[3][0] += p_x; - m_data[3][1] += p_y; - m_data[3][2] += p_z; - } // vtable+0x30 - - // FUNCTION: LEGO1 0x100024a0 - // FUNCTION: BETA10 0x10010040 - virtual void SetTranslation(const float& p_x, const float& p_y, const float& p_z) - { - m_data[3][0] = p_x; - m_data[3][1] = p_y; - m_data[3][2] = p_z; - } // vtable+0x34 - - // FUNCTION: LEGO1 0x100024d0 - // FUNCTION: BETA10 0x100100a0 - virtual void Product(float (*p_a)[4], float (*p_b)[4]) - { - float* cur = (float*) m_data; - for (int row = 0; row < 4; row++) { - for (int col = 0; col < 4; col++) { - *cur = 0.0f; - for (int k = 0; k < 4; k++) { - *cur += p_a[row][k] * p_b[k][col]; - } - cur++; - } - } - } // vtable+0x3c - - // FUNCTION: LEGO1 0x10002530 - // FUNCTION: BETA10 0x10010180 - virtual void Product(const Matrix4& p_a, const Matrix4& p_b) { Product(p_a.m_data, p_b.m_data); } // vtable+0x38 - - inline virtual void ToQuaternion(Vector4& p_resultQuat); // vtable+0x40 - inline virtual int FromQuaternion(const Vector4& p_vec); // vtable+0x44 - - // FUNCTION: LEGO1 0x100a0ff0 - // FUNCTION: BETA10 0x1001fe60 - void Scale(const float& p_x, const float& p_y, const float& p_z) - { - for (int i = 0; i < 4; i++) { - m_data[i][0] *= p_x; - m_data[i][1] *= p_y; - m_data[i][2] *= p_z; - } - } - - // FUNCTION: BETA10 0x1001c6a0 - void RotateX(const float& p_angle) - { - float s = sin(p_angle); - float c = cos(p_angle); - float matrix[4][4]; - memcpy(matrix, m_data, sizeof(float) * 16); - for (int i = 0; i < 4; i++) { - m_data[i][1] = matrix[i][1] * c - matrix[i][2] * s; - m_data[i][2] = matrix[i][2] * c + matrix[i][1] * s; - } - } - - // FUNCTION: BETA10 0x1001fd60 - void RotateY(const float& p_angle) - { - float s = sin(p_angle); - float c = cos(p_angle); - float matrix[4][4]; - memcpy(matrix, m_data, sizeof(float) * 16); - for (int i = 0; i < 4; i++) { - m_data[i][0] = matrix[i][0] * c + matrix[i][2] * s; - m_data[i][2] = matrix[i][2] * c - matrix[i][0] * s; - } - } - - // FUNCTION: BETA10 0x1006ab10 - void RotateZ(const float& p_angle) - { - float s = sin(p_angle); - float c = cos(p_angle); - float matrix[4][4]; - memcpy(matrix, m_data, sizeof(float) * 16); - for (int i = 0; i < 4; i++) { - m_data[i][0] = matrix[i][0] * c - matrix[i][1] * s; - m_data[i][1] = matrix[i][1] * c + matrix[i][0] * s; - } - } - - inline int BETA_1005a590(Matrix4& p_mat); - - // FUNCTION: LEGO1 0x1006b500 - void Swap(int p_d1, int p_d2) - { - for (int i = 0; i < 4; i++) { - float e = m_data[p_d1][i]; - m_data[p_d1][i] = m_data[p_d2][i]; - m_data[p_d2][i] = e; - } - } - - float* operator[](int idx) { return m_data[idx]; } - const float* operator[](int idx) const { return m_data[idx]; } - -protected: - float (*m_data)[4]; -}; - -// FUNCTION: LEGO1 0x10002550 -// FUNCTION: BETA10 0x100101c0 -inline void Matrix4::ToQuaternion(Vector4& p_outQuat) -{ - float trace; - float localc = m_data[0][0] + m_data[1][1] + m_data[2][2]; - - if (localc > 0) { - trace = (float) sqrt(localc + 1.0); - p_outQuat[3] = trace * 0.5f; - trace = 0.5f / trace; - p_outQuat[0] = (m_data[2][1] - m_data[1][2]) * trace; - p_outQuat[1] = (m_data[0][2] - m_data[2][0]) * trace; - p_outQuat[2] = (m_data[1][0] - m_data[0][1]) * trace; - } - else { - // GLOBAL: LEGO1 0x100d4090 - static int rotateIndex[] = {1, 2, 0}; - - // Largest element along the trace - int largest = 0; - if (m_data[0][0] < m_data[1][1]) { - largest = 1; - } - if (*Element(largest, largest) < m_data[2][2]) { - largest = 2; - } - - int next = rotateIndex[largest]; - int nextNext = rotateIndex[next]; - - trace = (float) sqrt(*Element(largest, largest) - (*Element(nextNext, nextNext) + *Element(next, next)) + 1.0); - - p_outQuat[largest] = trace * 0.5f; - trace = 0.5f / trace; - - p_outQuat[3] = (*Element(nextNext, next) - *Element(next, nextNext)) * trace; - p_outQuat[next] = (*Element(largest, next) + *Element(next, largest)) * trace; - p_outQuat[nextNext] = (*Element(largest, nextNext) + *Element(nextNext, largest)) * trace; - } -} - -// FUNCTION: LEGO1 0x10002710 -// FUNCTION: BETA10 0x10010550 -inline int Matrix4::FromQuaternion(const Vector4& p_vec) -{ - float local14 = p_vec.LenSquared(); - - if (local14 > 0.0f) { - local14 = 2.0f / local14; - - float local24 = p_vec[0] * local14; - float local34 = p_vec[1] * local14; - float local10 = p_vec[2] * local14; - - float local28 = p_vec[3] * local24; - float local2c = p_vec[3] * local34; - float local30 = p_vec[3] * local10; - - float local38 = p_vec[0] * local24; - float local8 = p_vec[0] * local34; - float localc = p_vec[0] * local10; - - float local18 = p_vec[1] * local34; - float local1c = p_vec[1] * local10; - float local20 = p_vec[2] * local10; - - m_data[0][0] = 1.0f - (local18 + local20); - m_data[1][0] = local8 + local30; - m_data[2][0] = localc - local2c; - - m_data[0][1] = local8 - local30; - m_data[1][1] = 1.0f - (local38 + local20); - m_data[2][1] = local1c + local28; - - m_data[0][2] = local2c + localc; - m_data[1][2] = local1c - local28; - m_data[2][2] = 1.0f - (local18 + local38); - - m_data[3][0] = 0.0f; - m_data[3][1] = 0.0f; - m_data[3][2] = 0.0f; - m_data[3][3] = 1.0f; - - m_data[0][3] = 0.0f; - m_data[1][3] = 0.0f; - m_data[2][3] = 0.0f; - return 0; - } - else { - return -1; - } -} - -// FUNCTION: BETA10 0x1005a590 -inline int Matrix4::BETA_1005a590(Matrix4& p_mat) -{ - float local5c[4][4]; - Matrix4 localc(local5c); - - ((Matrix4&) localc) = *this; - p_mat.SetIdentity(); - - for (int i = 0; i < 4; i++) { - int local1c = i; - int local10; - - for (local10 = i + 1; local10 < 4; local10++) { - if (fabs(localc[local1c][i]) < fabs(localc[local10][i])) { - local1c = local10; - } - } - - if (local1c != i) { - localc.Swap(local1c, i); - p_mat.Swap(local1c, i); - } - - if (localc[i][i] < 0.001f && localc[i][i] > -0.001f) { - return -1; - } - - float local60 = localc[i][i]; - int local18; - - for (local18 = 0; local18 < 4; local18++) { - p_mat[i][local18] /= local60; - } - - for (local18 = 0; local18 < 4; local18++) { - localc[i][local18] /= local60; - } - - for (local10 = 0; local10 < 4; local10++) { - if (i != local10) { - float afStack70[4]; - - for (local18 = 0; local18 < 4; local18++) { - afStack70[local18] = p_mat[i][local18] * localc[local10][i]; - } - - for (local18 = 0; local18 < 4; local18++) { - p_mat[local10][local18] -= afStack70[local18]; - } - - for (local18 = 0; local18 < 4; local18++) { - afStack70[local18] = localc[i][local18] * localc[local10][i]; - } - - for (local18 = 0; local18 < 4; local18++) { - localc[local10][local18] -= afStack70[local18]; - } - } - } - } - - return 0; -} - #endif // MATRIX_H diff --git a/LEGO1/realtime/vector.h b/LEGO1/realtime/vector.h index e3e71476ba..0cbe48caff 100644 --- a/LEGO1/realtime/vector.h +++ b/LEGO1/realtime/vector.h @@ -236,14 +236,6 @@ class Vector3 : public Vector2 { // FUNCTION: LEGO1 0x10002300 virtual void EqualsCross(const float* p_a, const Vector3& p_b) { EqualsCrossImpl(p_a, p_b.m_data); } // vtable+0x78 - // FUNCTION: LEGO1 0x10003bf0 - virtual void Fill(const float& p_value) - { - m_data[0] = p_value; - m_data[1] = p_value; - m_data[2] = p_value; - } // vtable+0x84 - // Vector2 overrides // FUNCTION: LEGO1 0x10003a60 @@ -315,9 +307,333 @@ class Vector3 : public Vector2 { return m_data[0] * m_data[0] + m_data[1] * m_data[1] + m_data[2] * m_data[2]; } // vtable+0x40 + // FUNCTION: LEGO1 0x10003bf0 + virtual void Fill(const float& p_value) + { + m_data[0] = p_value; + m_data[1] = p_value; + m_data[2] = p_value; + } // vtable+0x84 + friend class Mx3DPointFloat; }; +struct UnknownMatrixType { + float m_data[4][4]; +}; + +// VTABLE: LEGO1 0x100d4350 +// VTABLE: BETA10 0x101b8340 +// SIZE 0x08 +class Matrix4 { +public: + // FUNCTION: LEGO1 0x10004500 + // FUNCTION: BETA10 0x1000fc70 + Matrix4(float (*p_data)[4]) { SetData(p_data); } + + // Note: virtual function overloads appear in the virtual table + // in reverse order of appearance. + + // FUNCTION: LEGO1 0x10002320 + // FUNCTION: BETA10 0x1000fcb0 + virtual void Equals(float (*p_data)[4]) { memcpy(m_data, p_data, sizeof(float) * 4 * 4); } // vtable+0x04 + + // FUNCTION: LEGO1 0x10002340 + // FUNCTION: BETA10 0x1000fcf0 + virtual void Equals(const Matrix4& p_matrix) + { + memcpy(m_data, p_matrix.m_data, sizeof(float) * 4 * 4); + } // vtable+0x00 + + // FUNCTION: LEGO1 0x10002360 + // FUNCTION: BETA10 0x1000fd30 + virtual void SetData(float (*p_data)[4]) { m_data = p_data; } // vtable+0x0c + + // FUNCTION: LEGO1 0x10002370 + // FUNCTION: BETA10 0x1000fd60 + virtual void SetData(UnknownMatrixType& p_matrix) { m_data = p_matrix.m_data; } // vtable+0x08 + + // FUNCTION: LEGO1 0x10002380 + // FUNCTION: BETA10 0x1000fd90 + virtual float (*GetData())[4] { return m_data; } // vtable+0x14 + + // FUNCTION: LEGO1 0x10002390 + // FUNCTION: BETA10 0x1000fdc0 + virtual float (*GetData() const)[4] { return m_data; } // vtable+0x10 + + // FUNCTION: LEGO1 0x100023a0 + // FUNCTION: BETA10 0x1000fdf0 + virtual float* Element(int p_row, int p_col) { return &m_data[p_row][p_col]; } // vtable+0x1c + + // FUNCTION: LEGO1 0x100023c0 + // FUNCTION: BETA10 0x1000fe30 + virtual const float* Element(int p_row, int p_col) const { return &m_data[p_row][p_col]; } // vtable+0x18 + + // FUNCTION: LEGO1 0x100023e0 + // FUNCTION: BETA10 0x1000fe70 + virtual void Clear() { memset(m_data, 0, 16 * sizeof(float)); } // vtable+0x20 + + // FUNCTION: LEGO1 0x100023f0 + // FUNCTION: BETA10 0x1000feb0 + virtual void SetIdentity() + { + Clear(); + m_data[0][0] = 1.0f; + m_data[1][1] = 1.0f; + m_data[2][2] = 1.0f; + m_data[3][3] = 1.0f; + } // vtable+0x24 + + // FUNCTION: LEGO1 0x10002420 + // FUNCTION: BETA10 0x1000ff20 + virtual void operator=(const Matrix4& p_matrix) { Equals(p_matrix); } // vtable+0x28 + + // FUNCTION: LEGO1 0x10002430 + // FUNCTION: BETA10 0x1000ff50 + virtual Matrix4& operator+=(float (*p_data)[4]) + { + for (int i = 0; i < 16; i++) { + ((float*) m_data)[i] += ((float*) p_data)[i]; + } + return *this; + } // vtable+0x2c + + // FUNCTION: LEGO1 0x10002460 + // FUNCTION: BETA10 0x1000ffc0 + virtual void TranslateBy(const float& p_x, const float& p_y, const float& p_z) + { + m_data[3][0] += p_x; + m_data[3][1] += p_y; + m_data[3][2] += p_z; + } // vtable+0x30 + + // FUNCTION: LEGO1 0x100024a0 + // FUNCTION: BETA10 0x10010040 + virtual void SetTranslation(const float& p_x, const float& p_y, const float& p_z) + { + m_data[3][0] = p_x; + m_data[3][1] = p_y; + m_data[3][2] = p_z; + } // vtable+0x34 + + // FUNCTION: LEGO1 0x100024d0 + // FUNCTION: BETA10 0x100100a0 + virtual void Product(float (*p_a)[4], float (*p_b)[4]) + { + float* cur = (float*) m_data; + for (int row = 0; row < 4; row++) { + for (int col = 0; col < 4; col++) { + *cur = 0.0f; + for (int k = 0; k < 4; k++) { + *cur += p_a[row][k] * p_b[k][col]; + } + cur++; + } + } + } // vtable+0x3c + + // FUNCTION: LEGO1 0x10002530 + // FUNCTION: BETA10 0x10010180 + virtual void Product(const Matrix4& p_a, const Matrix4& p_b) { Product(p_a.m_data, p_b.m_data); } // vtable+0x38 + + inline virtual void ToQuaternion(Vector3& p_resultQuat); // vtable+0x40 + inline virtual int FromQuaternion(const Vector3& p_vec); // vtable+0x44 + + // FUNCTION: LEGO1 0x100a0ff0 + // FUNCTION: BETA10 0x1001fe60 + void Scale(const float& p_x, const float& p_y, const float& p_z) + { + for (int i = 0; i < 4; i++) { + m_data[i][0] *= p_x; + m_data[i][1] *= p_y; + m_data[i][2] *= p_z; + } + } + + // FUNCTION: BETA10 0x1001c6a0 + void RotateX(const float& p_angle) + { + float s = sin(p_angle); + float c = cos(p_angle); + float matrix[4][4]; + memcpy(matrix, m_data, sizeof(float) * 16); + for (int i = 0; i < 4; i++) { + m_data[i][1] = matrix[i][1] * c - matrix[i][2] * s; + m_data[i][2] = matrix[i][2] * c + matrix[i][1] * s; + } + } + + // FUNCTION: BETA10 0x1001fd60 + void RotateY(const float& p_angle) + { + float s = sin(p_angle); + float c = cos(p_angle); + float matrix[4][4]; + memcpy(matrix, m_data, sizeof(float) * 16); + for (int i = 0; i < 4; i++) { + m_data[i][0] = matrix[i][0] * c + matrix[i][2] * s; + m_data[i][2] = matrix[i][2] * c - matrix[i][0] * s; + } + } + + // FUNCTION: BETA10 0x1006ab10 + void RotateZ(const float& p_angle) + { + float s = sin(p_angle); + float c = cos(p_angle); + float matrix[4][4]; + memcpy(matrix, m_data, sizeof(float) * 16); + for (int i = 0; i < 4; i++) { + m_data[i][0] = matrix[i][0] * c - matrix[i][1] * s; + m_data[i][1] = matrix[i][1] * c + matrix[i][0] * s; + } + } + + inline int BETA_1005a590(Matrix4& p_mat); + + // FUNCTION: LEGO1 0x1006b500 + void Swap(int p_d1, int p_d2) + { + for (int i = 0; i < 4; i++) { + float e = m_data[p_d1][i]; + m_data[p_d1][i] = m_data[p_d2][i]; + m_data[p_d2][i] = e; + } + } + + float* operator[](int idx) { return m_data[idx]; } + const float* operator[](int idx) const { return m_data[idx]; } + +protected: + float (*m_data)[4]; +}; + +// FUNCTION: LEGO1 0x10002550 +// FUNCTION: BETA10 0x100101c0 +inline void Matrix4::ToQuaternion(Vector3& p_outQuat) +{ + float trace; + float localc = m_data[0][0] + m_data[1][1] + m_data[2][2]; + + if (localc > 0) { + trace = (float) sqrt(localc + 1.0); + p_outQuat[3] = trace * 0.5f; + trace = 0.5f / trace; + p_outQuat[0] = (m_data[2][1] - m_data[1][2]) * trace; + p_outQuat[1] = (m_data[0][2] - m_data[2][0]) * trace; + p_outQuat[2] = (m_data[1][0] - m_data[0][1]) * trace; + } + else { + // GLOBAL: LEGO1 0x100d4090 + static int rotateIndex[] = {1, 2, 0}; + + // Largest element along the trace + int largest = 0; + if (m_data[0][0] < m_data[1][1]) { + largest = 1; + } + if (*Element(largest, largest) < m_data[2][2]) { + largest = 2; + } + + int next = rotateIndex[largest]; + int nextNext = rotateIndex[next]; + + trace = (float) sqrt(*Element(largest, largest) - (*Element(nextNext, nextNext) + *Element(next, next)) + 1.0); + + p_outQuat[largest] = trace * 0.5f; + trace = 0.5f / trace; + + p_outQuat[3] = (*Element(nextNext, next) - *Element(next, nextNext)) * trace; + p_outQuat[next] = (*Element(largest, next) + *Element(next, largest)) * trace; + p_outQuat[nextNext] = (*Element(largest, nextNext) + *Element(nextNext, largest)) * trace; + } +} + +// FUNCTION: LEGO1 0x10002710 +// FUNCTION: BETA10 0x10010550 +inline int Matrix4::FromQuaternion(const Vector3& p_vec) +{ + float local14 = p_vec.LenSquared(); + + if (local14 > 0.0f) { + local14 = 2.0f / local14; + + float local24 = p_vec[0] * local14; + float local34 = p_vec[1] * local14; + float local10 = p_vec[2] * local14; + + float local28 = p_vec[3] * local24; + float local2c = p_vec[3] * local34; + float local30 = p_vec[3] * local10; + + float local38 = p_vec[0] * local24; + float local8 = p_vec[0] * local34; + float localc = p_vec[0] * local10; + + float local18 = p_vec[1] * local34; + float local1c = p_vec[1] * local10; + float local20 = p_vec[2] * local10; + + m_data[0][0] = 1.0f - (local18 + local20); + m_data[1][0] = local8 + local30; + m_data[2][0] = localc - local2c; + + m_data[0][1] = local8 - local30; + m_data[1][1] = 1.0f - (local38 + local20); + m_data[2][1] = local1c + local28; + + m_data[0][2] = local2c + localc; + m_data[1][2] = local1c - local28; + m_data[2][2] = 1.0f - (local18 + local38); + + m_data[3][0] = 0.0f; + m_data[3][1] = 0.0f; + m_data[3][2] = 0.0f; + m_data[3][3] = 1.0f; + + m_data[0][3] = 0.0f; + m_data[1][3] = 0.0f; + m_data[2][3] = 0.0f; + return 0; + } + else { + return -1; + } +} + +// VTABLE: LEGO1 0x100d4300 +// VTABLE: BETA10 0x101b82e0 +// SIZE 0x48 +class MxMatrix : public Matrix4 { +public: + // FUNCTION: LEGO1 0x1006b120 + // FUNCTION: BETA10 0x10015370 + MxMatrix() : Matrix4(m_elements) {} + + // FUNCTION: LEGO1 0x10032770 + // FUNCTION: BETA10 0x1001ff30 + MxMatrix(const MxMatrix& p_matrix) : Matrix4(m_elements) { Equals(p_matrix); } + + // FUNCTION: BETA10 0x1000fc20 + MxMatrix(const Matrix4& p_matrix) : Matrix4(m_elements) { Equals(p_matrix); } + + // FUNCTION: BETA10 0x10010860 + float* operator[](int idx) { return m_data[idx]; } + + // FUNCTION: BETA10 0x1001c670 + const float* operator[](int idx) const { return m_data[idx]; } + + // FUNCTION: LEGO1 0x10002850 + void operator=(const Matrix4& p_matrix) override { Equals(p_matrix); } // vtable+0x28 + + // FUNCTION: LEGO1 0x10002860 + virtual void operator=(const MxMatrix& p_matrix) { Equals(p_matrix); } // vtable+0x48 + +private: + float m_elements[4][4]; // 0x08 +}; + // VTABLE: LEGO1 0x100d45a0 // VTABLE: BETA10 0x101bac38 // SIZE 0x08 @@ -339,24 +655,6 @@ class Vector4 : public Vector3 { // Note: virtual function overloads appear in the virtual table // in reverse order of appearance. - // FUNCTION: LEGO1 0x10002a40 - virtual void SetMatrixProduct(const float* p_vec, const float* p_mat) - { - m_data[0] = p_vec[0] * p_mat[0] + p_vec[1] * p_mat[4] + p_vec[2] * p_mat[8] + p_vec[3] * p_mat[12]; - m_data[1] = p_vec[0] * p_mat[1] + p_vec[1] * p_mat[5] + p_vec[2] * p_mat[9] + p_vec[4] * p_mat[13]; - m_data[2] = p_vec[0] * p_mat[2] + p_vec[1] * p_mat[6] + p_vec[2] * p_mat[10] + p_vec[4] * p_mat[14]; - m_data[3] = p_vec[0] * p_mat[3] + p_vec[1] * p_mat[7] + p_vec[2] * p_mat[11] + p_vec[4] * p_mat[15]; - } // vtable+0x8c - - // FUNCTION: LEGO1 0x10002ae0 - virtual void SetMatrixProduct(const Vector4& p_a, const float* p_b) - { - SetMatrixProduct(p_a.m_data, p_b); - } // vtable+0x88 - - inline virtual int NormalizeQuaternion(); // vtable+0x90 - inline virtual int EqualsHamiltonProduct(const Vector4& p_a, const Vector4& p_b); // vtable+0x94 - // Vector3 overrides // FUNCTION: LEGO1 0x10002870 @@ -422,6 +720,24 @@ class Vector4 : public Vector3 { // FUNCTION: LEGO1 0x10002a20 void EqualsImpl(const float* p_data) override { memcpy(m_data, p_data, sizeof(float) * 4); } // vtable+0x20 + // FUNCTION: LEGO1 0x10002a40 + virtual void SetMatrixProduct(const float* p_vec, const float* p_mat) + { + m_data[0] = p_vec[0] * p_mat[0] + p_vec[1] * p_mat[4] + p_vec[2] * p_mat[8] + p_vec[3] * p_mat[12]; + m_data[1] = p_vec[0] * p_mat[1] + p_vec[1] * p_mat[5] + p_vec[2] * p_mat[9] + p_vec[4] * p_mat[13]; + m_data[2] = p_vec[0] * p_mat[2] + p_vec[1] * p_mat[6] + p_vec[2] * p_mat[10] + p_vec[4] * p_mat[14]; + m_data[3] = p_vec[0] * p_mat[3] + p_vec[1] * p_mat[7] + p_vec[2] * p_mat[11] + p_vec[4] * p_mat[15]; + } // vtable+0x8c + + // FUNCTION: LEGO1 0x10002ae0 + virtual void SetMatrixProduct(const Vector4& p_a, const float* p_b) + { + SetMatrixProduct(p_a.m_data, p_b); + } // vtable+0x88 + + inline virtual int NormalizeQuaternion(); // vtable+0x90 + inline virtual int EqualsHamiltonProduct(const Vector4& p_a, const Vector4& p_b); // vtable+0x94 + // FUNCTION: LEGO1 0x10002b00 void Clear() override { memset(m_data, 0, sizeof(float) * 4); } // vtable+0x2c @@ -448,6 +764,71 @@ class Vector4 : public Vector3 { friend class Mx4DPointFloat; }; +// FUNCTION: BETA10 0x1005a590 +inline int Matrix4::BETA_1005a590(Matrix4& p_mat) +{ + float local5c[4][4]; + Matrix4 localc(local5c); + + ((Matrix4&) localc) = *this; + p_mat.SetIdentity(); + + for (int i = 0; i < 4; i++) { + int local1c = i; + int local10; + + for (local10 = i + 1; local10 < 4; local10++) { + if (fabs(localc[local1c][i]) < fabs(localc[local10][i])) { + local1c = local10; + } + } + + if (local1c != i) { + localc.Swap(local1c, i); + p_mat.Swap(local1c, i); + } + + if (localc[i][i] < 0.001f && localc[i][i] > -0.001f) { + return -1; + } + + float local60 = localc[i][i]; + int local18; + + for (local18 = 0; local18 < 4; local18++) { + p_mat[i][local18] /= local60; + } + + for (local18 = 0; local18 < 4; local18++) { + localc[i][local18] /= local60; + } + + for (local10 = 0; local10 < 4; local10++) { + if (i != local10) { + float afStack70[4]; + + for (local18 = 0; local18 < 4; local18++) { + afStack70[local18] = p_mat[i][local18] * localc[local10][i]; + } + + for (local18 = 0; local18 < 4; local18++) { + p_mat[local10][local18] -= afStack70[local18]; + } + + for (local18 = 0; local18 < 4; local18++) { + afStack70[local18] = localc[i][local18] * localc[local10][i]; + } + + for (local18 = 0; local18 < 4; local18++) { + localc[local10][local18] -= afStack70[local18]; + } + } + } + } + + return 0; +} + // FUNCTION: LEGO1 0x10002b70 // FUNCTION: BETA10 0x10048ad0 inline int Vector4::NormalizeQuaternion() From 7ea036d2f8068363f411b544b64cd36c85fd6090 Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Tue, 31 Dec 2024 11:35:58 -0700 Subject: [PATCH 02/16] Revert IslePathActor --- LEGO1/lego/legoomni/include/islepathactor.h | 37 +++++++++++---------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/LEGO1/lego/legoomni/include/islepathactor.h b/LEGO1/lego/legoomni/include/islepathactor.h index 4a2356691a..1aa5616a98 100644 --- a/LEGO1/lego/legoomni/include/islepathactor.h +++ b/LEGO1/lego/legoomni/include/islepathactor.h @@ -86,27 +86,10 @@ class IslePathActor : public LegoPathActor { IslePathActor(); - // FUNCTION: LEGO1 0x10002df0 - virtual MxLong HandleNotification0() { return 0; } // vtable+0xd0 - - // FUNCTION: LEGO1 0x10002e00 - virtual MxLong HandlePathStruct(LegoPathStructNotificationParam&) { return 0; } // vtable+0xdc - // FUNCTION: LEGO1 0x10002e10 ~IslePathActor() override { IslePathActor::Destroy(TRUE); } - // FUNCTION: LEGO1 0x10002e70 - virtual MxLong HandleClick() { return 0; } // vtable+0xcc - - // FUNCTION: LEGO1 0x10002e80 - virtual MxLong HandleControl(LegoControlManagerNotificationParam&) { return 0; } // vtable+0xd4 - - // FUNCTION: LEGO1 0x10002e90 - virtual MxLong HandleEndAnim(LegoEndAnimNotificationParam&) { return 0; } // vtable+0xd8 - - MxLong Notify(MxParam& p_param) override; // vtable+0x04 - MxResult Create(MxDSAction& p_dsAction) override; // vtable+0x18 - void Destroy(MxBool p_fromDestructor) override; // vtable+0x1c + MxLong Notify(MxParam& p_param) override; // vtable+0x04 // FUNCTION: LEGO1 0x10002ea0 // FUNCTION: BETA10 0x10023fa0 @@ -122,6 +105,24 @@ class IslePathActor : public LegoPathActor { return !strcmp(p_name, IslePathActor::ClassName()) || LegoPathActor::IsA(p_name); } + MxResult Create(MxDSAction& p_dsAction) override; // vtable+0x18 + void Destroy(MxBool p_fromDestructor) override; // vtable+0x1c + + // FUNCTION: LEGO1 0x10002e70 + virtual MxLong HandleClick() { return 0; } // vtable+0xcc + + // FUNCTION: LEGO1 0x10002df0 + virtual MxLong HandleNotification0() { return 0; } // vtable+0xd0 + + // FUNCTION: LEGO1 0x10002e80 + virtual MxLong HandleControl(LegoControlManagerNotificationParam&) { return 0; } // vtable+0xd4 + + // FUNCTION: LEGO1 0x10002e90 + virtual MxLong HandleEndAnim(LegoEndAnimNotificationParam&) { return 0; } // vtable+0xd8 + + // FUNCTION: LEGO1 0x10002e00 + virtual MxLong HandlePathStruct(LegoPathStructNotificationParam&) { return 0; } // vtable+0xdc + virtual void Enter(); // vtable+0xe0 virtual void Exit(); // vtable+0xe4 virtual void SpawnPlayer(LegoGameState::Area p_area, MxBool p_enter, MxU8 p_flags); // vtable+0xe8 From 50ac085f42ddc7f8069b2afcf359227129d03d84 Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Wed, 1 Jan 2025 09:40:17 -0700 Subject: [PATCH 03/16] Fix order --- LEGO1/lego/legoomni/include/islepathactor.h | 46 ++++++++++----------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/LEGO1/lego/legoomni/include/islepathactor.h b/LEGO1/lego/legoomni/include/islepathactor.h index 1aa5616a98..70a5870272 100644 --- a/LEGO1/lego/legoomni/include/islepathactor.h +++ b/LEGO1/lego/legoomni/include/islepathactor.h @@ -86,6 +86,26 @@ class IslePathActor : public LegoPathActor { IslePathActor(); + // FUNCTION: LEGO1 0x10002e70 + virtual MxLong HandleClick() { return 0; } // vtable+0xcc + + // FUNCTION: LEGO1 0x10002df0 + virtual MxLong HandleNotification0() { return 0; } // vtable+0xd0 + + // FUNCTION: LEGO1 0x10002e80 + virtual MxLong HandleControl(LegoControlManagerNotificationParam&) { return 0; } // vtable+0xd4 + + // FUNCTION: LEGO1 0x10002e90 + virtual MxLong HandleEndAnim(LegoEndAnimNotificationParam&) { return 0; } // vtable+0xd8 + + // FUNCTION: LEGO1 0x10002e00 + virtual MxLong HandlePathStruct(LegoPathStructNotificationParam&) { return 0; } // vtable+0xdc + + virtual void Enter(); // vtable+0xe0 + virtual void Exit(); // vtable+0xe4 + virtual void SpawnPlayer(LegoGameState::Area p_area, MxBool p_enter, MxU8 p_flags); // vtable+0xe8 + virtual void VTable0xec(MxMatrix p_transform, LegoPathBoundary* p_boundary, MxBool p_reset); // vtable+0xec + // FUNCTION: LEGO1 0x10002e10 ~IslePathActor() override { IslePathActor::Destroy(TRUE); } @@ -108,29 +128,6 @@ class IslePathActor : public LegoPathActor { MxResult Create(MxDSAction& p_dsAction) override; // vtable+0x18 void Destroy(MxBool p_fromDestructor) override; // vtable+0x1c - // FUNCTION: LEGO1 0x10002e70 - virtual MxLong HandleClick() { return 0; } // vtable+0xcc - - // FUNCTION: LEGO1 0x10002df0 - virtual MxLong HandleNotification0() { return 0; } // vtable+0xd0 - - // FUNCTION: LEGO1 0x10002e80 - virtual MxLong HandleControl(LegoControlManagerNotificationParam&) { return 0; } // vtable+0xd4 - - // FUNCTION: LEGO1 0x10002e90 - virtual MxLong HandleEndAnim(LegoEndAnimNotificationParam&) { return 0; } // vtable+0xd8 - - // FUNCTION: LEGO1 0x10002e00 - virtual MxLong HandlePathStruct(LegoPathStructNotificationParam&) { return 0; } // vtable+0xdc - - virtual void Enter(); // vtable+0xe0 - virtual void Exit(); // vtable+0xe4 - virtual void SpawnPlayer(LegoGameState::Area p_area, MxBool p_enter, MxU8 p_flags); // vtable+0xe8 - virtual void VTable0xec(MxMatrix p_transform, LegoPathBoundary* p_boundary, MxBool p_reset); // vtable+0xec - - // SYNTHETIC: LEGO1 0x10002ff0 - // IslePathActor::`scalar deleting destructor' - void FUN_1001b660(); void Reset() @@ -143,6 +140,9 @@ class IslePathActor : public LegoPathActor { static void RegisterSpawnLocations(); + // SYNTHETIC: LEGO1 0x10002ff0 + // IslePathActor::`scalar deleting destructor' + protected: LegoWorld* m_world; // 0x154 LegoPathActor* m_previousActor; // 0x158 From 4c53a91abaf53deec75f658d97bb407e871dc6cf Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Wed, 1 Jan 2025 11:39:27 -0700 Subject: [PATCH 04/16] Fix inlining --- LEGO1/lego/legoomni/src/actors/helicopter.cpp | 3 +- LEGO1/mxgeometry/mxgeometry4d.h | 46 +++++++++---------- 2 files changed, 24 insertions(+), 25 deletions(-) diff --git a/LEGO1/lego/legoomni/src/actors/helicopter.cpp b/LEGO1/lego/legoomni/src/actors/helicopter.cpp index bdec74e460..c08e852024 100644 --- a/LEGO1/lego/legoomni/src/actors/helicopter.cpp +++ b/LEGO1/lego/legoomni/src/actors/helicopter.cpp @@ -482,8 +482,7 @@ void Helicopter::FUN_100042a0(const Matrix4& p_matrix) m_unk0x1f0 = Timer()->GetTime(); - m_unk0x1f4.BETA_1004a9f0(local48); - m_unk0x1f4.FUN_10004620(local90); + m_unk0x1f4.BETA_1004a9b0(local48, local90); m_unk0x1f4.FUN_10004520(); } diff --git a/LEGO1/mxgeometry/mxgeometry4d.h b/LEGO1/mxgeometry/mxgeometry4d.h index 349854c116..051056e614 100644 --- a/LEGO1/mxgeometry/mxgeometry4d.h +++ b/LEGO1/mxgeometry/mxgeometry4d.h @@ -55,6 +55,29 @@ class UnknownMx4DPointFloat { UnknownMx4DPointFloat() : m_unk0x30(0) {} + // FUNCTION: LEGO1 0x10004520 + inline long FUN_10004520() + { + if (!m_unk0x30) { + return -1; + } + + Mx4DPointFloat v1; + Mx4DPointFloat v2; + + v1 = m_unk0x00; + v1 += m_unk0x18; + + v2 = m_unk0x00; + v2 -= m_unk0x18; + + if (v1.Dot(v1, v1) < v2.Dot(v2, v2)) { + m_unk0x18 *= -1.0f; + } + + return 0; + } + // FUNCTION: BETA10 0x1004a9b0 void BETA_1004a9b0(Matrix4& p_m1, Matrix4& p_m2) { @@ -108,29 +131,6 @@ class UnknownMx4DPointFloat { return -1; } - // FUNCTION: LEGO1 0x10004520 - inline long FUN_10004520() - { - if (!m_unk0x30) { - return -1; - } - - Mx4DPointFloat v1; - Mx4DPointFloat v2; - - v1 = m_unk0x00; - v1 += m_unk0x18; - - v2 = m_unk0x00; - v2 -= m_unk0x18; - - if (v1.Dot(v1, v1) < v2.Dot(v2, v2)) { - m_unk0x18 *= -1.0f; - } - - return 0; - } - private: // FUNCTION: LEGO1 0x100040a0 // FUNCTION: BETA10 0x1004ab10 From b0400f0995bbfb9daffb517aa1d10ed008d62fd1 Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Wed, 1 Jan 2025 11:49:05 -0700 Subject: [PATCH 05/16] Fixes --- LEGO1/lego/legoomni/include/helicopter.h | 13 ++++++------- LEGO1/realtime/vector.h | 3 --- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/LEGO1/lego/legoomni/include/helicopter.h b/LEGO1/lego/legoomni/include/helicopter.h index 2e49c024ae..c525e7da85 100644 --- a/LEGO1/lego/legoomni/include/helicopter.h +++ b/LEGO1/lego/legoomni/include/helicopter.h @@ -3,6 +3,7 @@ #include "islepathactor.h" #include "legostate.h" +#include "mxgeometry/mxgeometry4d.h" #include "realtime/matrix.h" class Act3; @@ -44,16 +45,17 @@ class HelicopterState : public LegoState { MxU32 m_unk0x08; // 0x08 }; -#include "mxgeometry/mxgeometry4d.h" - // VTABLE: LEGO1 0x100d40f8 // VTABLE: BETA10 0x101b9880 // SIZE 0x230 class Helicopter : public IslePathActor { public: + Helicopter(); + ~Helicopter() override; // vtable+0x00 + // FUNCTION: LEGO1 0x10003070 // FUNCTION: BETA10 0x1002b300 - virtual const char* ClassName() const override // vtable+0x0c + const char* ClassName() const override // vtable+0x0c { // STRING: LEGO1 0x100f0130 return "Helicopter"; @@ -61,14 +63,11 @@ class Helicopter : public IslePathActor { // FUNCTION: LEGO1 0x10003080 // FUNCTION: BETA10 0x1002b330 - virtual MxBool IsA(const char* p_name) const override // vtable+0x10 + MxBool IsA(const char* p_name) const override // vtable+0x10 { return !strcmp(p_name, Helicopter::ClassName()) || IslePathActor::IsA(p_name); } - Helicopter(); - ~Helicopter() override; // vtable+0x00 - MxResult Create(MxDSAction& p_dsAction) override; // vtable+0x18 void Animate(float p_time) override; // vtable+0x70 void VTable0x74(Matrix4& p_transform) override; // vtable+0x74 diff --git a/LEGO1/realtime/vector.h b/LEGO1/realtime/vector.h index 0cbe48caff..f81e506ecc 100644 --- a/LEGO1/realtime/vector.h +++ b/LEGO1/realtime/vector.h @@ -6,9 +6,6 @@ #include #include -// Note: Many functions most likely take const references/pointers instead of non-const. -// The class needs to undergo a very careful refactoring to fix that (no matches should break). - // VTABLE: LEGO1 0x100d4288 // VTABLE: BETA10 0x101b8440 // SIZE 0x08 From c27243d991072b7a6beaaa5225149b74380a8892 Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Fri, 3 Jan 2025 10:10:56 -0700 Subject: [PATCH 06/16] WIP --- LEGO1/realtime/vector.h | 528 +++++++++++++----------------------- LEGO1/realtime/vector2d.inl | 196 +++++++++++++ LEGO1/realtime/vector3d.inl | 112 ++++++++ 3 files changed, 490 insertions(+), 346 deletions(-) create mode 100644 LEGO1/realtime/vector2d.inl create mode 100644 LEGO1/realtime/vector3d.inl diff --git a/LEGO1/realtime/vector.h b/LEGO1/realtime/vector.h index f81e506ecc..3dd84bf569 100644 --- a/LEGO1/realtime/vector.h +++ b/LEGO1/realtime/vector.h @@ -6,6 +6,9 @@ #include #include +// Note: virtual function overloads appear in the virtual table +// in reverse order of appearance. + // VTABLE: LEGO1 0x100d4288 // VTABLE: BETA10 0x101b8440 // SIZE 0x08 @@ -15,142 +18,38 @@ class Vector2 { // FUNCTION: BETA10 0x100116a0 Vector2(float* p_data) { SetData(p_data); } - // Note: virtual function overloads appear in the virtual table - // in reverse order of appearance. - - // FUNCTION: LEGO1 0x10001f80 - virtual void AddImpl(const float* p_value) - { - m_data[0] += p_value[0]; - m_data[1] += p_value[1]; - } // vtable+0x04 - - // FUNCTION: LEGO1 0x10001fa0 - virtual void AddImpl(float p_value) - { - m_data[0] += p_value; - m_data[1] += p_value; - } // vtable+0x00 - - // FUNCTION: LEGO1 0x10001fc0 - virtual void SubImpl(const float* p_value) - { - m_data[0] -= p_value[0]; - m_data[1] -= p_value[1]; - } // vtable+0x08 - - // FUNCTION: LEGO1 0x10001fe0 - virtual void MulImpl(const float* p_value) - { - m_data[0] *= p_value[0]; - m_data[1] *= p_value[1]; - } // vtable+0x10 - - // FUNCTION: LEGO1 0x10002000 - virtual void MulImpl(const float& p_value) - { - m_data[0] *= p_value; - m_data[1] *= p_value; - } // vtable+0x0c - - // FUNCTION: LEGO1 0x10002020 - virtual void DivImpl(const float& p_value) - { - m_data[0] /= p_value; - m_data[1] /= p_value; - } // vtable+0x14 - - // FUNCTION: LEGO1 0x10002040 - virtual float DotImpl(const float* p_a, const float* p_b) const - { - return p_b[0] * p_a[0] + p_b[1] * p_a[1]; - } // vtable+0x18 - - // FUNCTION: LEGO1 0x10002060 - // FUNCTION: BETA10 0x10010c90 - virtual void SetData(float* p_data) { m_data = p_data; } // vtable+0x1c - - // FUNCTION: LEGO1 0x10002070 - virtual void EqualsImpl(const float* p_data) { memcpy(m_data, p_data, sizeof(float) * 2); } // vtable+0x20 - - // FUNCTION: LEGO1 0x10002090 - virtual float* GetData() { return m_data; } // vtable+0x28 - - // FUNCTION: LEGO1 0x100020a0 - virtual const float* GetData() const { return m_data; } // vtable+0x24 - - // FUNCTION: LEGO1 0x100020b0 - virtual void Clear() { memset(m_data, 0, sizeof(float) * 2); } // vtable+0x2c - - // FUNCTION: LEGO1 0x100020d0 - virtual float Dot(const float* p_a, const float* p_b) const { return DotImpl(p_a, p_b); } // vtable+0x3c - - // FUNCTION: LEGO1 0x100020f0 - // FUNCTION: BETA10 0x100108c0 - virtual float Dot(const Vector2& p_a, const Vector2& p_b) const - { - return DotImpl(p_a.m_data, p_b.m_data); - } // vtable+0x38 - - // FUNCTION: LEGO1 0x10002110 - virtual float Dot(const float* p_a, const Vector2& p_b) const { return DotImpl(p_a, p_b.m_data); } // vtable+0x34 - - // FUNCTION: LEGO1 0x10002130 - virtual float Dot(const Vector2& p_a, const float* p_b) const { return DotImpl(p_a.m_data, p_b); } // vtable+0x30 - - // FUNCTION: LEGO1 0x10002150 - virtual float LenSquared() const { return m_data[0] * m_data[0] + m_data[1] * m_data[1]; } // vtable+0x40 - - // FUNCTION: LEGO1 0x10002160 - // FUNCTION: BETA10 0x10010900 - virtual int Unitize() - { - float sq = LenSquared(); - - if (sq > 0.0f) { - float root = sqrt(sq); - if (root > 0.0f) { - DivImpl(root); - return 0; - } - } - - return -1; - } // vtable+0x44 - - // FUNCTION: LEGO1 0x100021c0 - virtual void operator+=(float p_value) { AddImpl(p_value); } // vtable+0x50 - - // FUNCTION: LEGO1 0x100021d0 - virtual void operator+=(const float* p_other) { AddImpl(p_other); } // vtable+0x4c - - // FUNCTION: LEGO1 0x100021e0 - virtual void operator+=(const Vector2& p_other) { AddImpl(p_other.m_data); } // vtable+0x48 - - // FUNCTION: LEGO1 0x100021f0 - virtual void operator-=(const float* p_other) { SubImpl(p_other); } // vtable+0x58 - - // FUNCTION: LEGO1 0x10002200 - virtual void operator-=(const Vector2& p_other) { SubImpl(p_other.m_data); } // vtable+0x54 - - // FUNCTION: LEGO1 0x10002210 - virtual void operator*=(const float* p_other) { MulImpl(p_other); } // vtable+0x64 - - // FUNCTION: LEGO1 0x10002220 - virtual void operator*=(const Vector2& p_other) { MulImpl(p_other.m_data); } // vtable+0x60 - - // FUNCTION: LEGO1 0x10002230 - virtual void operator*=(const float& p_value) { MulImpl(p_value); } // vtable+0x5c - - // FUNCTION: LEGO1 0x10002240 - virtual void operator/=(const float& p_value) { DivImpl(p_value); } // vtable+0x68 - - // FUNCTION: LEGO1 0x10002250 - virtual void SetVector(const float* p_other) { EqualsImpl(p_other); } // vtable+0x70 +protected: + inline virtual void AddImpl(const float* p_value); // vtable+0x04 + inline virtual void AddImpl(float p_value); // vtable+0x00 + inline virtual void SubImpl(const float* p_value); // vtable+0x08 + inline virtual void MulImpl(const float* p_value); // vtable+0x10 + inline virtual void MulImpl(const float& p_value); // vtable+0x0c + inline virtual void DivImpl(const float& p_value); // vtable+0x14 + inline virtual float DotImpl(const float* p_a, const float* p_b) const; // vtable+0x18 + inline virtual void SetData(float* p_data); // vtable+0x1c + inline virtual void EqualsImpl(const float* p_data); // vtable+0x20 - // FUNCTION: LEGO1 0x10002260 - // FUNCTION: BETA10 0x100110c0 - virtual void SetVector(const Vector2& p_other) { EqualsImpl(p_other.m_data); } // vtable+0x6c +public: + inline virtual float* GetData(); // vtable+0x28 + inline virtual const float* GetData() const; // vtable+0x24 + inline virtual void Clear(); // vtable+0x2c + inline virtual float Dot(const float* p_a, const float* p_b) const; // vtable+0x3c + inline virtual float Dot(const Vector2& p_a, const Vector2& p_b) const; // vtable+0x38 + inline virtual float Dot(const float* p_a, const Vector2& p_b) const; // vtable+0x34 + inline virtual float Dot(const Vector2& p_a, const float* p_b) const; // vtable+0x30 + inline virtual float LenSquared() const; // vtable+0x40 + inline virtual int Unitize(); // vtable+0x44 + inline virtual void operator+=(float p_value); // vtable+0x50 + inline virtual void operator+=(const float* p_other); // vtable+0x4c + inline virtual void operator+=(const Vector2& p_other); // vtable+0x48 + inline virtual void operator-=(const float* p_other); // vtable+0x58 + inline virtual void operator-=(const Vector2& p_other); // vtable+0x54 + inline virtual void operator*=(const float* p_other); // vtable+0x64 + inline virtual void operator*=(const Vector2& p_other); // vtable+0x60 + inline virtual void operator*=(const float& p_value); // vtable+0x5c + inline virtual void operator/=(const float& p_value); // vtable+0x68 + inline virtual void SetVector(const float* p_other); // vtable+0x70 + inline virtual void SetVector(const Vector2& p_other); // vtable+0x6c // Note: it's unclear whether Vector3::operator= has been defined explicitly // with the same function body as Vector2& operator=. The BETA indicates that; @@ -208,111 +107,76 @@ class Vector3 : public Vector2 { // FUNCTION: BETA10 0x100109a0 Vector3(const float* p_data) : Vector2((float*) p_data) {} - // Note: virtual function overloads appear in the virtual table - // in reverse order of appearance. - - // FUNCTION: LEGO1 0x10002270 - // FUNCTION: BETA10 0x10011350 - virtual void EqualsCrossImpl(const float* p_a, const float* p_b) - { - m_data[0] = p_a[1] * p_b[2] - p_a[2] * p_b[1]; - m_data[1] = p_a[2] * p_b[0] - p_a[0] * p_b[2]; - m_data[2] = p_a[0] * p_b[1] - p_a[1] * p_b[0]; - } // vtable+0x74 - - // FUNCTION: LEGO1 0x100022c0 - // FUNCTION: BETA10 0x10011430 - virtual void EqualsCross(const Vector3& p_a, const Vector3& p_b) - { - EqualsCrossImpl(p_a.m_data, p_b.m_data); - } // vtable+0x80 - - // FUNCTION: LEGO1 0x100022e0 - virtual void EqualsCross(const Vector3& p_a, const float* p_b) { EqualsCrossImpl(p_a.m_data, p_b); } // vtable+0x7c - - // FUNCTION: LEGO1 0x10002300 - virtual void EqualsCross(const float* p_a, const Vector3& p_b) { EqualsCrossImpl(p_a, p_b.m_data); } // vtable+0x78 - - // Vector2 overrides - - // FUNCTION: LEGO1 0x10003a60 - void AddImpl(const float* p_value) override - { - m_data[0] += p_value[0]; - m_data[1] += p_value[1]; - m_data[2] += p_value[2]; - } // vtable+0x04 +protected: + inline void AddImpl(const float* p_value) override; // vtable+0x04 + inline void AddImpl(float p_value) override; // vtable+0x00 + inline void SubImpl(const float* p_value) override; // vtable+0x08 + inline void MulImpl(const float* p_value) override; // vtable+0x10 + inline void MulImpl(const float& p_value) override; // vtable+0x0c + inline void DivImpl(const float& p_value) override; // vtable+0x14 + inline float DotImpl(const float* p_a, const float* p_b) const override; // vtable+0x18 + inline void EqualsImpl(const float* p_data) override; // vtable+0x20 + inline virtual void EqualsCrossImpl(const float* p_a, const float* p_b); // vtable+0x74 - // FUNCTION: LEGO1 0x10003a90 - void AddImpl(float p_value) override - { - m_data[0] += p_value; - m_data[1] += p_value; - m_data[2] += p_value; - } // vtable+0x00 +public: + inline void Clear() override; // vtable+0x2c + inline float LenSquared() const override; // vtable+0x40 + inline virtual void EqualsCross(const Vector3& p_a, const Vector3& p_b); // vtable+0x80 + inline virtual void EqualsCross(const Vector3& p_a, const float* p_b); // vtable+0x7c + inline virtual void EqualsCross(const float* p_a, const Vector3& p_b); // vtable+0x78 + inline virtual void Fill(const float& p_value); // vtable+0x84 - // FUNCTION: LEGO1 0x10003ac0 - void SubImpl(const float* p_value) override - { - m_data[0] -= p_value[0]; - m_data[1] -= p_value[1]; - m_data[2] -= p_value[2]; - } // vtable+0x08 + friend class Mx3DPointFloat; +}; - // FUNCTION: LEGO1 0x10003af0 - void MulImpl(const float* p_value) override - { - m_data[0] *= p_value[0]; - m_data[1] *= p_value[1]; - m_data[2] *= p_value[2]; - } // vtable+0x10 +#include "vector2d.inl" +#include "vector3d.inl" - // FUNCTION: LEGO1 0x10003b20 - void MulImpl(const float& p_value) override - { - m_data[0] *= p_value; - m_data[1] *= p_value; - m_data[2] *= p_value; - } // vtable+0x0c +// VTABLE: LEGO1 0x100d45a0 +// VTABLE: BETA10 0x101bac38 +// SIZE 0x08 +class Vector4 : public Vector3 { +public: + // FUNCTION: BETA10 0x10048780 + inline Vector4(float* p_data) : Vector3(p_data) {} - // FUNCTION: LEGO1 0x10003b50 - void DivImpl(const float& p_value) override - { - m_data[0] /= p_value; - m_data[1] /= p_value; - m_data[2] /= p_value; - } // vtable+0x14 + // Some code initializes a Vector4 from a `const float*` source. + // Example: `LegoCarBuild::VTable0x6c` + // Vector4 however is a class that can mutate its underlying source, making + // initialization with a const source fundamentally incompatible. + // BETA10 appears to have two separate constructors for Vector4 as well, + // supporting the theory that this decompilation is correct. - // FUNCTION: LEGO1 0x10003b80 - float DotImpl(const float* p_a, const float* p_b) const override - { - return p_a[0] * p_b[0] + p_a[2] * p_b[2] + p_a[1] * p_b[1]; - } // vtable+0x18 + // FUNCTION: BETA10 0x100701b0 + inline Vector4(const float* p_data) : Vector3((float*) p_data) {} - // FUNCTION: LEGO1 0x10003ba0 - // FUNCTION: BETA10 0x100113f0 - void EqualsImpl(const float* p_data) override { memcpy(m_data, p_data, sizeof(float) * 3); } // vtable+0x20 + // Note: virtual function overloads appear in the virtual table + // in reverse order of appearance. - // FUNCTION: LEGO1 0x10003bc0 - // FUNCTION: BETA10 0x100114f0 - void Clear() override { memset(m_data, 0, sizeof(float) * 3); } // vtable+0x2c + inline void AddImpl(const float* p_value) override; // vtable+0x04 + inline void AddImpl(float p_value) override; // vtable+0x00 + inline void SubImpl(const float* p_value) override; // vtable+0x08 + inline void MulImpl(const float* p_value) override; // vtable+0x10 + inline void MulImpl(const float& p_value) override; // vtable+0x0c + inline void DivImpl(const float& p_value) override; // vtable+0x14 + inline float DotImpl(const float* p_a, const float* p_b) const override; // vtable+0x18 + inline void EqualsImpl(const float* p_data) override; // vtable+0x20 + + inline void Clear() override; // vtable+0x2c + inline float LenSquared() const override; // vtable+0x40 + inline void Fill(const float& p_value) override; // vtable+0x84 + + inline virtual void SetMatrixProduct(const float* p_vec, const float* p_mat); // vtable+0x8c + inline virtual void SetMatrixProduct(const Vector4& p_a, const float* p_b); // vtable+0x88 + inline virtual int NormalizeQuaternion(); // vtable+0x90 + inline virtual int EqualsHamiltonProduct(const Vector4& p_a, const Vector4& p_b); // vtable+0x94 - // FUNCTION: LEGO1 0x10003bd0 - // FUNCTION: BETA10 0x10011530 - float LenSquared() const override - { - return m_data[0] * m_data[0] + m_data[1] * m_data[1] + m_data[2] * m_data[2]; - } // vtable+0x40 + float& operator[](int idx) { return m_data[idx]; } - // FUNCTION: LEGO1 0x10003bf0 - virtual void Fill(const float& p_value) - { - m_data[0] = p_value; - m_data[1] = p_value; - m_data[2] = p_value; - } // vtable+0x84 + // FUNCTION: BETA10 0x10010890 + const float& operator[](int idx) const { return m_data[idx]; } - friend class Mx3DPointFloat; + friend class Mx4DPointFloat; }; struct UnknownMatrixType { @@ -631,135 +495,107 @@ class MxMatrix : public Matrix4 { float m_elements[4][4]; // 0x08 }; -// VTABLE: LEGO1 0x100d45a0 -// VTABLE: BETA10 0x101bac38 -// SIZE 0x08 -class Vector4 : public Vector3 { -public: - // FUNCTION: BETA10 0x10048780 - Vector4(float* p_data) : Vector3(p_data) {} - - // Some code initializes a Vector4 from a `const float*` source. - // Example: `LegoCarBuild::VTable0x6c` - // Vector4 however is a class that can mutate its underlying source, making - // initialization with a const source fundamentally incompatible. - // BETA10 appears to have two separate constructors for Vector4 as well, - // supporting the theory that this decompilation is correct. - - // FUNCTION: BETA10 0x100701b0 - Vector4(const float* p_data) : Vector3((float*) p_data) {} - - // Note: virtual function overloads appear in the virtual table - // in reverse order of appearance. +// FUNCTION: LEGO1 0x10002870 +void Vector4::AddImpl(const float* p_value) +{ + m_data[0] += p_value[0]; + m_data[1] += p_value[1]; + m_data[2] += p_value[2]; + m_data[3] += p_value[3]; +} - // Vector3 overrides +// FUNCTION: LEGO1 0x100028b0 +void Vector4::AddImpl(float p_value) +{ + m_data[0] += p_value; + m_data[1] += p_value; + m_data[2] += p_value; + m_data[3] += p_value; +} - // FUNCTION: LEGO1 0x10002870 - void AddImpl(const float* p_value) override - { - m_data[0] += p_value[0]; - m_data[1] += p_value[1]; - m_data[2] += p_value[2]; - m_data[3] += p_value[3]; - } // vtable+0x04 - - // FUNCTION: LEGO1 0x100028b0 - void AddImpl(float p_value) override - { - m_data[0] += p_value; - m_data[1] += p_value; - m_data[2] += p_value; - m_data[3] += p_value; - } // vtable+0x00 +// FUNCTION: LEGO1 0x100028f0 +void Vector4::SubImpl(const float* p_value) +{ + m_data[0] -= p_value[0]; + m_data[1] -= p_value[1]; + m_data[2] -= p_value[2]; + m_data[3] -= p_value[3]; +} - // FUNCTION: LEGO1 0x100028f0 - void SubImpl(const float* p_value) override - { - m_data[0] -= p_value[0]; - m_data[1] -= p_value[1]; - m_data[2] -= p_value[2]; - m_data[3] -= p_value[3]; - } // vtable+0x08 - - // FUNCTION: LEGO1 0x10002930 - void MulImpl(const float* p_value) override - { - m_data[0] *= p_value[0]; - m_data[1] *= p_value[1]; - m_data[2] *= p_value[2]; - m_data[3] *= p_value[3]; - } // vtable+0x10 - - // FUNCTION: LEGO1 0x10002970 - void MulImpl(const float& p_value) override - { - m_data[0] *= p_value; - m_data[1] *= p_value; - m_data[2] *= p_value; - m_data[3] *= p_value; - } // vtable+0x0c - - // FUNCTION: LEGO1 0x100029b0 - void DivImpl(const float& p_value) override - { - m_data[0] /= p_value; - m_data[1] /= p_value; - m_data[2] /= p_value; - m_data[3] /= p_value; - } // vtable+0x14 - - // FUNCTION: LEGO1 0x100029f0 - float DotImpl(const float* p_a, const float* p_b) const override - { - return p_a[0] * p_b[0] + p_a[2] * p_b[2] + (p_a[1] * p_b[1] + p_a[3] * p_b[3]); - } // vtable+0x18 +// FUNCTION: LEGO1 0x10002930 +void Vector4::MulImpl(const float* p_value) +{ + m_data[0] *= p_value[0]; + m_data[1] *= p_value[1]; + m_data[2] *= p_value[2]; + m_data[3] *= p_value[3]; +} - // FUNCTION: LEGO1 0x10002a20 - void EqualsImpl(const float* p_data) override { memcpy(m_data, p_data, sizeof(float) * 4); } // vtable+0x20 +// FUNCTION: LEGO1 0x10002970 +void Vector4::MulImpl(const float& p_value) +{ + m_data[0] *= p_value; + m_data[1] *= p_value; + m_data[2] *= p_value; + m_data[3] *= p_value; +} - // FUNCTION: LEGO1 0x10002a40 - virtual void SetMatrixProduct(const float* p_vec, const float* p_mat) - { - m_data[0] = p_vec[0] * p_mat[0] + p_vec[1] * p_mat[4] + p_vec[2] * p_mat[8] + p_vec[3] * p_mat[12]; - m_data[1] = p_vec[0] * p_mat[1] + p_vec[1] * p_mat[5] + p_vec[2] * p_mat[9] + p_vec[4] * p_mat[13]; - m_data[2] = p_vec[0] * p_mat[2] + p_vec[1] * p_mat[6] + p_vec[2] * p_mat[10] + p_vec[4] * p_mat[14]; - m_data[3] = p_vec[0] * p_mat[3] + p_vec[1] * p_mat[7] + p_vec[2] * p_mat[11] + p_vec[4] * p_mat[15]; - } // vtable+0x8c - - // FUNCTION: LEGO1 0x10002ae0 - virtual void SetMatrixProduct(const Vector4& p_a, const float* p_b) - { - SetMatrixProduct(p_a.m_data, p_b); - } // vtable+0x88 +// FUNCTION: LEGO1 0x100029b0 +void Vector4::DivImpl(const float& p_value) +{ + m_data[0] /= p_value; + m_data[1] /= p_value; + m_data[2] /= p_value; + m_data[3] /= p_value; +} - inline virtual int NormalizeQuaternion(); // vtable+0x90 - inline virtual int EqualsHamiltonProduct(const Vector4& p_a, const Vector4& p_b); // vtable+0x94 +// FUNCTION: LEGO1 0x100029f0 +float Vector4::DotImpl(const float* p_a, const float* p_b) const +{ + return p_a[0] * p_b[0] + p_a[2] * p_b[2] + (p_a[1] * p_b[1] + p_a[3] * p_b[3]); +} - // FUNCTION: LEGO1 0x10002b00 - void Clear() override { memset(m_data, 0, sizeof(float) * 4); } // vtable+0x2c +// FUNCTION: LEGO1 0x10002a20 +void Vector4::EqualsImpl(const float* p_data) +{ + memcpy(m_data, p_data, sizeof(float) * 4); +} - // FUNCTION: LEGO1 0x10002b20 - float LenSquared() const override - { - return m_data[1] * m_data[1] + m_data[0] * m_data[0] + m_data[2] * m_data[2] + m_data[3] * m_data[3]; - } // vtable+0x40 +// FUNCTION: LEGO1 0x10002a40 +void Vector4::SetMatrixProduct(const float* p_vec, const float* p_mat) +{ + m_data[0] = p_vec[0] * p_mat[0] + p_vec[1] * p_mat[4] + p_vec[2] * p_mat[8] + p_vec[3] * p_mat[12]; + m_data[1] = p_vec[0] * p_mat[1] + p_vec[1] * p_mat[5] + p_vec[2] * p_mat[9] + p_vec[4] * p_mat[13]; + m_data[2] = p_vec[0] * p_mat[2] + p_vec[1] * p_mat[6] + p_vec[2] * p_mat[10] + p_vec[4] * p_mat[14]; + m_data[3] = p_vec[0] * p_mat[3] + p_vec[1] * p_mat[7] + p_vec[2] * p_mat[11] + p_vec[4] * p_mat[15]; +} - // FUNCTION: LEGO1 0x10002b40 - void Fill(const float& p_value) override - { - m_data[0] = p_value; - m_data[1] = p_value; - m_data[2] = p_value; - m_data[3] = p_value; - } // vtable+0x84 +// FUNCTION: LEGO1 0x10002ae0 +void Vector4::SetMatrixProduct(const Vector4& p_a, const float* p_b) +{ + SetMatrixProduct(p_a.m_data, p_b); +} - float& operator[](int idx) { return m_data[idx]; } +// FUNCTION: LEGO1 0x10002b00 +void Vector4::Clear() +{ + memset(m_data, 0, sizeof(float) * 4); +} - // FUNCTION: BETA10 0x10010890 - const float& operator[](int idx) const { return m_data[idx]; } +// FUNCTION: LEGO1 0x10002b20 +float Vector4::LenSquared() const +{ + return m_data[1] * m_data[1] + m_data[0] * m_data[0] + m_data[2] * m_data[2] + m_data[3] * m_data[3]; +} - friend class Mx4DPointFloat; -}; +// FUNCTION: LEGO1 0x10002b40 +void Vector4::Fill(const float& p_value) +{ + m_data[0] = p_value; + m_data[1] = p_value; + m_data[2] = p_value; + m_data[3] = p_value; +} // FUNCTION: BETA10 0x1005a590 inline int Matrix4::BETA_1005a590(Matrix4& p_mat) diff --git a/LEGO1/realtime/vector2d.inl b/LEGO1/realtime/vector2d.inl new file mode 100644 index 0000000000..366086131f --- /dev/null +++ b/LEGO1/realtime/vector2d.inl @@ -0,0 +1,196 @@ + +#include "vector.h" + +// FUNCTION: LEGO1 0x10001f80 +void Vector2::AddImpl(const float* p_value) +{ + m_data[0] += p_value[0]; + m_data[1] += p_value[1]; +} + +// FUNCTION: LEGO1 0x10001fa0 +void Vector2::AddImpl(float p_value) +{ + m_data[0] += p_value; + m_data[1] += p_value; +} + +// FUNCTION: LEGO1 0x10001fc0 +void Vector2::SubImpl(const float* p_value) +{ + m_data[0] -= p_value[0]; + m_data[1] -= p_value[1]; +} + +// FUNCTION: LEGO1 0x10001fe0 +void Vector2::MulImpl(const float* p_value) +{ + m_data[0] *= p_value[0]; + m_data[1] *= p_value[1]; +} + +// FUNCTION: LEGO1 0x10002000 +void Vector2::MulImpl(const float& p_value) +{ + m_data[0] *= p_value; + m_data[1] *= p_value; +} + +// FUNCTION: LEGO1 0x10002020 +void Vector2::DivImpl(const float& p_value) +{ + m_data[0] /= p_value; + m_data[1] /= p_value; +} + +// FUNCTION: LEGO1 0x10002040 +float Vector2::DotImpl(const float* p_a, const float* p_b) const +{ + return p_b[0] * p_a[0] + p_b[1] * p_a[1]; +} + +// FUNCTION: LEGO1 0x10002060 +// FUNCTION: BETA10 0x10010c90 +void Vector2::SetData(float* p_data) +{ + m_data = p_data; +} + +// FUNCTION: LEGO1 0x10002070 +void Vector2::EqualsImpl(const float* p_data) +{ + memcpy(m_data, p_data, sizeof(float) * 2); +} + +// FUNCTION: LEGO1 0x10002090 +float* Vector2::GetData() +{ + return m_data; +} + +// FUNCTION: LEGO1 0x100020a0 +const float* Vector2::GetData() const +{ + return m_data; +} + +// FUNCTION: LEGO1 0x100020b0 +void Vector2::Clear() +{ + memset(m_data, 0, sizeof(float) * 2); +} + +// FUNCTION: LEGO1 0x100020d0 +float Vector2::Dot(const float* p_a, const float* p_b) const +{ + return DotImpl(p_a, p_b); +} + +// FUNCTION: LEGO1 0x100020f0 +// FUNCTION: BETA10 0x100108c0 +float Vector2::Dot(const Vector2& p_a, const Vector2& p_b) const +{ + return DotImpl(p_a.m_data, p_b.m_data); +} + +// FUNCTION: LEGO1 0x10002110 +float Vector2::Dot(const float* p_a, const Vector2& p_b) const +{ + return DotImpl(p_a, p_b.m_data); +} + +// FUNCTION: LEGO1 0x10002130 +float Vector2::Dot(const Vector2& p_a, const float* p_b) const +{ + return DotImpl(p_a.m_data, p_b); +} + +// FUNCTION: LEGO1 0x10002150 +float Vector2::LenSquared() const +{ + return m_data[0] * m_data[0] + m_data[1] * m_data[1]; +} + +// FUNCTION: LEGO1 0x10002160 +// FUNCTION: BETA10 0x10010900 +int Vector2::Unitize() +{ + float sq = LenSquared(); + + if (sq > 0.0f) { + float root = sqrt(sq); + if (root > 0.0f) { + DivImpl(root); + return 0; + } + } + + return -1; +} + +// FUNCTION: LEGO1 0x100021c0 +void Vector2::operator+=(float p_value) +{ + AddImpl(p_value); +} + +// FUNCTION: LEGO1 0x100021d0 +void Vector2::operator+=(const float* p_other) +{ + AddImpl(p_other); +} + +// FUNCTION: LEGO1 0x100021e0 +void Vector2::operator+=(const Vector2& p_other) +{ + AddImpl(p_other.m_data); +} + +// FUNCTION: LEGO1 0x100021f0 +void Vector2::operator-=(const float* p_other) +{ + SubImpl(p_other); +} + +// FUNCTION: LEGO1 0x10002200 +void Vector2::operator-=(const Vector2& p_other) +{ + SubImpl(p_other.m_data); +} + +// FUNCTION: LEGO1 0x10002210 +void Vector2::operator*=(const float* p_other) +{ + MulImpl(p_other); +} + +// FUNCTION: LEGO1 0x10002220 +void Vector2::operator*=(const Vector2& p_other) +{ + MulImpl(p_other.m_data); +} + +// FUNCTION: LEGO1 0x10002230 +void Vector2::operator*=(const float& p_value) +{ + MulImpl(p_value); +} + +// FUNCTION: LEGO1 0x10002240 +void Vector2::operator/=(const float& p_value) +{ + DivImpl(p_value); +} + +// FUNCTION: LEGO1 0x10002250 +void Vector2::SetVector(const float* p_other) +{ + EqualsImpl(p_other); +} + +// FUNCTION: LEGO1 0x10002260 +// FUNCTION: BETA10 0x100110c0 +void Vector2::SetVector(const Vector2& p_other) +{ + EqualsImpl(p_other.m_data); +} diff --git a/LEGO1/realtime/vector3d.inl b/LEGO1/realtime/vector3d.inl new file mode 100644 index 0000000000..127b89994d --- /dev/null +++ b/LEGO1/realtime/vector3d.inl @@ -0,0 +1,112 @@ +#include "vector.h" + +// FUNCTION: LEGO1 0x10002270 +// FUNCTION: BETA10 0x10011350 +void Vector3::EqualsCrossImpl(const float* p_a, const float* p_b) +{ + m_data[0] = p_a[1] * p_b[2] - p_a[2] * p_b[1]; + m_data[1] = p_a[2] * p_b[0] - p_a[0] * p_b[2]; + m_data[2] = p_a[0] * p_b[1] - p_a[1] * p_b[0]; +} + +// FUNCTION: LEGO1 0x100022c0 +// FUNCTION: BETA10 0x10011430 +void Vector3::EqualsCross(const Vector3& p_a, const Vector3& p_b) +{ + EqualsCrossImpl(p_a.m_data, p_b.m_data); +} + +// FUNCTION: LEGO1 0x100022e0 +void Vector3::EqualsCross(const Vector3& p_a, const float* p_b) +{ + EqualsCrossImpl(p_a.m_data, p_b); +} + +// FUNCTION: LEGO1 0x10002300 +void Vector3::EqualsCross(const float* p_a, const Vector3& p_b) +{ + EqualsCrossImpl(p_a, p_b.m_data); +} + +// FUNCTION: LEGO1 0x10003a60 +void Vector3::AddImpl(const float* p_value) +{ + m_data[0] += p_value[0]; + m_data[1] += p_value[1]; + m_data[2] += p_value[2]; +} + +// FUNCTION: LEGO1 0x10003a90 +void Vector3::AddImpl(float p_value) +{ + m_data[0] += p_value; + m_data[1] += p_value; + m_data[2] += p_value; +} + +// FUNCTION: LEGO1 0x10003ac0 +void Vector3::SubImpl(const float* p_value) +{ + m_data[0] -= p_value[0]; + m_data[1] -= p_value[1]; + m_data[2] -= p_value[2]; +} + +// FUNCTION: LEGO1 0x10003af0 +void Vector3::MulImpl(const float* p_value) +{ + m_data[0] *= p_value[0]; + m_data[1] *= p_value[1]; + m_data[2] *= p_value[2]; +} + +// FUNCTION: LEGO1 0x10003b20 +void Vector3::MulImpl(const float& p_value) +{ + m_data[0] *= p_value; + m_data[1] *= p_value; + m_data[2] *= p_value; +} + +// FUNCTION: LEGO1 0x10003b50 +void Vector3::DivImpl(const float& p_value) +{ + m_data[0] /= p_value; + m_data[1] /= p_value; + m_data[2] /= p_value; +} + +// FUNCTION: LEGO1 0x10003b80 +float Vector3::DotImpl(const float* p_a, const float* p_b) const +{ + return p_a[0] * p_b[0] + p_a[2] * p_b[2] + p_a[1] * p_b[1]; +} + +// FUNCTION: LEGO1 0x10003ba0 +// FUNCTION: BETA10 0x100113f0 +void Vector3::EqualsImpl(const float* p_data) +{ + memcpy(m_data, p_data, sizeof(float) * 3); +} + +// FUNCTION: LEGO1 0x10003bc0 +// FUNCTION: BETA10 0x100114f0 +void Vector3::Clear() +{ + memset(m_data, 0, sizeof(float) * 3); +} + +// FUNCTION: LEGO1 0x10003bd0 +// FUNCTION: BETA10 0x10011530 +float Vector3::LenSquared() const +{ + return m_data[0] * m_data[0] + m_data[1] * m_data[1] + m_data[2] * m_data[2]; +} + +// FUNCTION: LEGO1 0x10003bf0 +void Vector3::Fill(const float& p_value) +{ + m_data[0] = p_value; + m_data[1] = p_value; + m_data[2] = p_value; +} From 948e4b84bd97641101e49541b74fce09cfa62cf9 Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Fri, 3 Jan 2025 11:16:14 -0700 Subject: [PATCH 07/16] WIP --- LEGO1/lego/legoomni/include/act3.h | 3 +- LEGO1/lego/legoomni/include/helicopter.h | 15 +- LEGO1/lego/legoomni/include/legoactor.h | 1 + .../legoomni/include/legoanimationmanager.h | 83 ++- LEGO1/lego/legoomni/include/legocarbuild.h | 3 +- LEGO1/lego/legoomni/include/legopathactor.h | 1 - LEGO1/lego/legoomni/src/actors/helicopter.cpp | 6 +- .../lego/legoomni/src/build/legocarbuild.cpp | 4 +- .../src/common/legoanimationmanager.cpp | 6 +- .../legoomni/src/video/legovideomanager.cpp | 2 +- LEGO1/lego/legoomni/src/worlds/act3.cpp | 8 +- LEGO1/lego/sources/anim/legoanim.cpp | 10 +- LEGO1/mxgeometry/mxgeometry3d.h | 3 +- LEGO1/mxgeometry/mxgeometry4d.h | 153 +---- LEGO1/mxgeometry/mxmatrix.h | 38 +- LEGO1/mxgeometry/mxquaternion.h | 155 +++++ LEGO1/realtime/matrix.h | 50 +- LEGO1/realtime/matrix4d.h | 362 ++++++++++++ LEGO1/realtime/vector.h | 535 +----------------- LEGO1/realtime/{vector2d.inl => vector2d.h} | 5 + LEGO1/realtime/{vector3d.inl => vector3d.h} | 6 + LEGO1/realtime/vector4d.h | 145 +++++ 22 files changed, 839 insertions(+), 755 deletions(-) create mode 100644 LEGO1/mxgeometry/mxquaternion.h create mode 100644 LEGO1/realtime/matrix4d.h rename LEGO1/realtime/{vector2d.inl => vector2d.h} (98%) rename LEGO1/realtime/{vector3d.inl => vector3d.h} (96%) create mode 100644 LEGO1/realtime/vector4d.h diff --git a/LEGO1/lego/legoomni/include/act3.h b/LEGO1/lego/legoomni/include/act3.h index 57012215ed..f517027791 100644 --- a/LEGO1/lego/legoomni/include/act3.h +++ b/LEGO1/lego/legoomni/include/act3.h @@ -10,6 +10,7 @@ class Act3Brickster; class Act3Cop; class Act3Shark; class Helicopter; +class MxQuaternionTransformer; // Macros confirmed by BETA10 #define MAX_PIZZAS 20 @@ -152,7 +153,7 @@ class Act3 : public LegoWorld { const Matrix4& p_destination, const Matrix4& p_startPosition, const Matrix4& p_endPosition, - const UnknownMx4DPointFloat& p_unk0x1f4 + const MxQuaternionTransformer& p_unk0x1f4 ); Act3State* m_state; // 0xf8 diff --git a/LEGO1/lego/legoomni/include/helicopter.h b/LEGO1/lego/legoomni/include/helicopter.h index c525e7da85..6f8193b09f 100644 --- a/LEGO1/lego/legoomni/include/helicopter.h +++ b/LEGO1/lego/legoomni/include/helicopter.h @@ -3,8 +3,7 @@ #include "islepathactor.h" #include "legostate.h" -#include "mxgeometry/mxgeometry4d.h" -#include "realtime/matrix.h" +#include "mxgeometry/mxquaternion.h" class Act3; @@ -89,12 +88,12 @@ class Helicopter : public IslePathActor { protected: void FUN_100042a0(const Matrix4& p_matrix); - MxMatrix m_unk0x160; // 0x160 - MxMatrix m_unk0x1a8; // 0x1a8 - float m_unk0x1f0; // 0x1f0 - UnknownMx4DPointFloat m_unk0x1f4; // 0x1f4 - HelicopterState* m_state; // 0x228 - MxAtomId m_script; // 0x22c + MxMatrix m_unk0x160; // 0x160 + MxMatrix m_unk0x1a8; // 0x1a8 + float m_unk0x1f0; // 0x1f0 + MxQuaternionTransformer m_unk0x1f4; // 0x1f4 + HelicopterState* m_state; // 0x228 + MxAtomId m_script; // 0x22c }; #endif // HELICOPTER_H diff --git a/LEGO1/lego/legoomni/include/legoactor.h b/LEGO1/lego/legoomni/include/legoactor.h index 7c29ee6b2b..47c399f945 100644 --- a/LEGO1/lego/legoomni/include/legoactor.h +++ b/LEGO1/lego/legoomni/include/legoactor.h @@ -3,6 +3,7 @@ #include "decomp.h" #include "legoentity.h" +#include "mxgeometry/mxmatrix.h" class LegoCacheSound; diff --git a/LEGO1/lego/legoomni/include/legoanimationmanager.h b/LEGO1/lego/legoomni/include/legoanimationmanager.h index 324307292c..5c7546e0fb 100644 --- a/LEGO1/lego/legoomni/include/legoanimationmanager.h +++ b/LEGO1/lego/legoomni/include/legoanimationmanager.h @@ -7,8 +7,7 @@ #include "legostate.h" #include "legotraninfolist.h" #include "mxcore.h" -#include "mxgeometry/mxgeometry3d.h" -#include "mxgeometry/mxgeometry4d.h" +#include "mxgeometry/mxquaternion.h" class LegoAnimPresenter; class LegoEntity; @@ -259,46 +258,46 @@ class LegoAnimationManager : public MxCore { void FUN_100648f0(LegoTranInfo* p_tranInfo, MxLong p_unk0x404); void FUN_10064b50(MxLong p_time); - LegoOmni::World m_worldId; // 0x08 - MxU16 m_animCount; // 0x0c - MxU16 m_unk0x0e; // 0x0e - MxU16 m_unk0x10; // 0x10 - AnimInfo* m_anims; // 0x14 - undefined2 m_unk0x18; // 0x18 - MxBool m_unk0x1a; // 0x1a - MxU32 m_unk0x1c; // 0x1c - LegoTranInfoList* m_tranInfoList; // 0x20 - LegoTranInfoList* m_tranInfoList2; // 0x24 - MxPresenter* m_unk0x28[2]; // 0x28 - MxLong m_unk0x30[2]; // 0x30 - MxBool m_unk0x38; // 0x38 - MxBool m_animRunning; // 0x39 - MxBool m_enableCamAnims; // 0x3a - Extra m_extras[40]; // 0x3c - MxU32 m_lastExtraCharacterId; // 0x3fc - MxBool m_unk0x400; // 0x400 - MxBool m_unk0x401; // 0x401 - MxBool m_unk0x402; // 0x402 - MxLong m_unk0x404; // 0x404 - MxLong m_unk0x408; // 0x408 - MxLong m_unk0x40c; // 0x40c - MxLong m_unk0x410; // 0x410 - MxU32 m_unk0x414; // 0x414 - MxU32 m_numAllowedExtras; // 0x418 - undefined4 m_unk0x41c; // 0x41c - AnimState* m_animState; // 0x420 - LegoROIList* m_unk0x424; // 0x424 - MxBool m_suspendedEnableCamAnims; // 0x428 - MxBool m_unk0x429; // 0x429 - MxBool m_unk0x42a; // 0x42a - MxBool m_suspended; // 0x42b - LegoTranInfo* m_unk0x42c; // 0x42c - MxBool m_unk0x430; // 0x430 - MxLong m_unk0x434; // 0x434 - MxLong m_unk0x438; // 0x438 - MxMatrix m_unk0x43c; // 0x43c - MxMatrix m_unk0x484; // 0x484 - UnknownMx4DPointFloat m_unk0x4cc; // 0x4cc + LegoOmni::World m_worldId; // 0x08 + MxU16 m_animCount; // 0x0c + MxU16 m_unk0x0e; // 0x0e + MxU16 m_unk0x10; // 0x10 + AnimInfo* m_anims; // 0x14 + undefined2 m_unk0x18; // 0x18 + MxBool m_unk0x1a; // 0x1a + MxU32 m_unk0x1c; // 0x1c + LegoTranInfoList* m_tranInfoList; // 0x20 + LegoTranInfoList* m_tranInfoList2; // 0x24 + MxPresenter* m_unk0x28[2]; // 0x28 + MxLong m_unk0x30[2]; // 0x30 + MxBool m_unk0x38; // 0x38 + MxBool m_animRunning; // 0x39 + MxBool m_enableCamAnims; // 0x3a + Extra m_extras[40]; // 0x3c + MxU32 m_lastExtraCharacterId; // 0x3fc + MxBool m_unk0x400; // 0x400 + MxBool m_unk0x401; // 0x401 + MxBool m_unk0x402; // 0x402 + MxLong m_unk0x404; // 0x404 + MxLong m_unk0x408; // 0x408 + MxLong m_unk0x40c; // 0x40c + MxLong m_unk0x410; // 0x410 + MxU32 m_unk0x414; // 0x414 + MxU32 m_numAllowedExtras; // 0x418 + undefined4 m_unk0x41c; // 0x41c + AnimState* m_animState; // 0x420 + LegoROIList* m_unk0x424; // 0x424 + MxBool m_suspendedEnableCamAnims; // 0x428 + MxBool m_unk0x429; // 0x429 + MxBool m_unk0x42a; // 0x42a + MxBool m_suspended; // 0x42b + LegoTranInfo* m_unk0x42c; // 0x42c + MxBool m_unk0x430; // 0x430 + MxLong m_unk0x434; // 0x434 + MxLong m_unk0x438; // 0x438 + MxMatrix m_unk0x43c; // 0x43c + MxMatrix m_unk0x484; // 0x484 + MxQuaternionTransformer m_unk0x4cc; // 0x4cc }; // TEMPLATE: LEGO1 0x10061750 diff --git a/LEGO1/lego/legoomni/include/legocarbuild.h b/LEGO1/lego/legoomni/include/legocarbuild.h index 336f67deaf..6be5f567d5 100644 --- a/LEGO1/lego/legoomni/include/legocarbuild.h +++ b/LEGO1/lego/legoomni/include/legocarbuild.h @@ -4,6 +4,7 @@ #include "legogamestate.h" #include "legostate.h" #include "legoworld.h" +#include "mxgeometry/mxquaternion.h" class LegoCarBuildAnimPresenter; class LegoControlManagerNotificationParam; @@ -189,7 +190,7 @@ class LegoCarBuild : public LegoWorld { MxS32 m_unk0x250[2]; // 0x250 LegoCarBuildAnimPresenter* m_unk0x258; // 0x258 - UnknownMx4DPointFloat m_unk0x25c; // 0x25c + MxQuaternionTransformer m_unk0x25c; // 0x25c // These two are likely locations in pixel space MxS32 m_unk0x290[2]; // 0x290 diff --git a/LEGO1/lego/legoomni/include/legopathactor.h b/LEGO1/lego/legoomni/include/legopathactor.h index 39cf0965e8..343cd59829 100644 --- a/LEGO1/lego/legoomni/include/legopathactor.h +++ b/LEGO1/lego/legoomni/include/legopathactor.h @@ -3,7 +3,6 @@ #include "legoactor.h" #include "misc/legounknown.h" -#include "mxgeometry/mxmatrix.h" #include "mxtypes.h" struct LegoEdge; diff --git a/LEGO1/lego/legoomni/src/actors/helicopter.cpp b/LEGO1/lego/legoomni/src/actors/helicopter.cpp index c08e852024..e9ede61b12 100644 --- a/LEGO1/lego/legoomni/src/actors/helicopter.cpp +++ b/LEGO1/lego/legoomni/src/actors/helicopter.cpp @@ -419,7 +419,7 @@ void Helicopter::Animate(float p_time) Vector3 v3(m_unk0x1a8[3]); mat.SetIdentity(); - m_unk0x1f4.BETA_1004aaa0(mat, f2); + m_unk0x1f4.InterpolateToMatrix(mat, f2); v2 = v3; v2 -= v1; @@ -482,8 +482,8 @@ void Helicopter::FUN_100042a0(const Matrix4& p_matrix) m_unk0x1f0 = Timer()->GetTime(); - m_unk0x1f4.BETA_1004a9b0(local48, local90); - m_unk0x1f4.FUN_10004520(); + m_unk0x1f4.Set(local48, local90); + m_unk0x1f4.NormalizeDirection(); } // FUNCTION: LEGO1 0x10004640 diff --git a/LEGO1/lego/legoomni/src/build/legocarbuild.cpp b/LEGO1/lego/legoomni/src/build/legocarbuild.cpp index ce45ab7594..2b75e91d86 100644 --- a/LEGO1/lego/legoomni/src/build/legocarbuild.cpp +++ b/LEGO1/lego/legoomni/src/build/legocarbuild.cpp @@ -358,7 +358,7 @@ void LegoCarBuild::VTable0x70() m_unk0x2a0 = sqrt((MxDouble) DISTSQRD2(m_unk0x290, m_unk0x298)); - m_unk0x25c.BETA_1004a9b0(m_unk0x178, m_unk0x208); + m_unk0x25c.Set(m_unk0x178, m_unk0x208); } // FUNCTION: LEGO1 0x10023130 @@ -406,7 +406,7 @@ void LegoCarBuild::FUN_10023130(MxLong p_x, MxLong p_y) MxFloat local1c = sqrt((double) (NORMSQRD2(local20))) / m_unk0x2a0; - m_unk0x25c.BETA_1004aaa0(local78, local1c); + m_unk0x25c.InterpolateToMatrix(local78, local1c); local78[3][0] = m_unk0x178[3][0] + local18[0]; local78[3][1] = m_unk0x178[3][1] + local18[1]; diff --git a/LEGO1/lego/legoomni/src/common/legoanimationmanager.cpp b/LEGO1/lego/legoomni/src/common/legoanimationmanager.cpp index 5206d93692..6ea3e3faa7 100644 --- a/LEGO1/lego/legoomni/src/common/legoanimationmanager.cpp +++ b/LEGO1/lego/legoomni/src/common/legoanimationmanager.cpp @@ -2797,8 +2797,8 @@ void LegoAnimationManager::FUN_100648f0(LegoTranInfo* p_tranInfo, MxLong p_unk0x LegoLocation* location = NavController()->GetLocation(p_tranInfo->m_location); if (location != NULL) { CalcLocalTransform(location->m_position, location->m_direction, location->m_up, m_unk0x484); - m_unk0x4cc.BETA_1004a9b0(m_unk0x43c, m_unk0x484); - m_unk0x4cc.FUN_10004520(); + m_unk0x4cc.Set(m_unk0x43c, m_unk0x484); + m_unk0x4cc.NormalizeDirection(); } else { p_tranInfo->m_flags &= ~LegoTranInfo::c_bit1; @@ -2832,7 +2832,7 @@ void LegoAnimationManager::FUN_10064b50(MxLong p_time) sub[1] = (m_unk0x484[3][1] - m_unk0x43c[3][1]) * und; sub[2] = (m_unk0x484[3][2] - m_unk0x43c[3][2]) * und; - m_unk0x4cc.BETA_1004aaa0(mat, (float) (p_time - m_unk0x434) / 1000.0f); + m_unk0x4cc.InterpolateToMatrix(mat, (float) (p_time - m_unk0x434) / 1000.0f); VPV3(mat[3], m_unk0x43c[3], sub); mat[3][3] = 1.0f; diff --git a/LEGO1/lego/legoomni/src/video/legovideomanager.cpp b/LEGO1/lego/legoomni/src/video/legovideomanager.cpp index fcaada4927..3d7f75a0eb 100644 --- a/LEGO1/lego/legoomni/src/video/legovideomanager.cpp +++ b/LEGO1/lego/legoomni/src/video/legovideomanager.cpp @@ -8,12 +8,12 @@ #include "mxdirectx/mxdirect3d.h" #include "mxdirectx/mxstopwatch.h" #include "mxdisplaysurface.h" +#include "mxgeometry/mxmatrix.h" #include "mxmisc.h" #include "mxpalette.h" #include "mxregion.h" #include "mxtimer.h" #include "mxtransitionmanager.h" -#include "realtime/matrix.h" #include "realtime/realtime.h" #include "roi/legoroi.h" #include "tgl/d3drm/impl.h" diff --git a/LEGO1/lego/legoomni/src/worlds/act3.cpp b/LEGO1/lego/legoomni/src/worlds/act3.cpp index 48c687558f..0043e4b601 100644 --- a/LEGO1/lego/legoomni/src/worlds/act3.cpp +++ b/LEGO1/lego/legoomni/src/worlds/act3.cpp @@ -799,7 +799,7 @@ void Act3::DebugCopter( const Matrix4& p_destination, const Matrix4& p_startPosition, const Matrix4& p_endPosition, - const UnknownMx4DPointFloat& p_unk0x1f4 + const MxQuaternionTransformer& p_unk0x1f4 ) { DebugPrintf("Copter matrix...\n\n"); @@ -831,10 +831,10 @@ void Act3::DebugCopter( Mx4DPointFloat unk0x00, unk0x18; - if (p_unk0x1f4.GetUnknown0x30() != 0) { + if (p_unk0x1f4.GetFlags() != 0) { // TODO: Match - unk0x00 = p_unk0x1f4.GetUnknown0x00(); - unk0x18 = p_unk0x1f4.GetUnknown0x18(); + unk0x00 = p_unk0x1f4.GetStartQuat(); + unk0x18 = p_unk0x1f4.GetEndQuat(); DebugPrintf("Source quaternion..."); // STRING: LEGO1 0x100f7864 diff --git a/LEGO1/lego/sources/anim/legoanim.cpp b/LEGO1/lego/sources/anim/legoanim.cpp index e367b8157e..562601a5c1 100644 --- a/LEGO1/lego/sources/anim/legoanim.cpp +++ b/LEGO1/lego/sources/anim/legoanim.cpp @@ -1,7 +1,7 @@ #include "legoanim.h" -#include "mxgeometry/mxgeometry4d.h" #include "mxgeometry/mxmatrix.h" +#include "mxgeometry/mxquaternion.h" #include @@ -852,7 +852,7 @@ inline void LegoAnimNodeData::GetTranslation( break; case 2: Mx4DPointFloat a; - UnknownMx4DPointFloat b; + MxQuaternionTransformer b; if (p_rotationKeys[i].TestBit1() || p_rotationKeys[i + 1].TestBit1()) { a[0] = p_rotationKeys[i].GetX(); @@ -879,9 +879,9 @@ inline void LegoAnimNodeData::GetTranslation( c[3] = p_rotationKeys[i + 1].GetAngle(); } - b.BETA_10180b80(a); - b.BETA_10180bc0(c); - b.BETA_1004aaa0( + b.SetStart(a); + b.SetEnd(c); + b.InterpolateToMatrix( p_matrix, (p_time - p_rotationKeys[i].GetTime()) / (p_rotationKeys[i + 1].GetTime() - p_rotationKeys[i].GetTime()) ); diff --git a/LEGO1/mxgeometry/mxgeometry3d.h b/LEGO1/mxgeometry/mxgeometry3d.h index f35daeb21d..f8fd3a03ed 100644 --- a/LEGO1/mxgeometry/mxgeometry3d.h +++ b/LEGO1/mxgeometry/mxgeometry3d.h @@ -2,8 +2,9 @@ #define MXGEOMETRY3D_H #include "decomp.h" -#include "realtime/matrix.h" #include "realtime/vector.h" +#include "realtime/vector2d.h" +#include "realtime/vector3d.h" // VTABLE: LEGO1 0x100d4488 // VTABLE: BETA10 0x101b84d0 diff --git a/LEGO1/mxgeometry/mxgeometry4d.h b/LEGO1/mxgeometry/mxgeometry4d.h index 051056e614..44102427ce 100644 --- a/LEGO1/mxgeometry/mxgeometry4d.h +++ b/LEGO1/mxgeometry/mxgeometry4d.h @@ -2,7 +2,9 @@ #define MXGEOMETRY4D_H #include "decomp.h" -#include "realtime/vector.h" +#include "realtime/matrix.h" +#include "realtime/matrix4d.h" +#include "realtime/vector4d.h" // VTABLE: LEGO1 0x100d41e8 // VTABLE: BETA10 0x101bab78 @@ -45,153 +47,4 @@ class Mx4DPointFloat : public Vector4 { float m_elements[4]; // 0x08 }; -// SIZE 0x34 -class UnknownMx4DPointFloat { -public: - enum { - c_bit1 = 0x01, - c_bit2 = 0x02 - }; - - UnknownMx4DPointFloat() : m_unk0x30(0) {} - - // FUNCTION: LEGO1 0x10004520 - inline long FUN_10004520() - { - if (!m_unk0x30) { - return -1; - } - - Mx4DPointFloat v1; - Mx4DPointFloat v2; - - v1 = m_unk0x00; - v1 += m_unk0x18; - - v2 = m_unk0x00; - v2 -= m_unk0x18; - - if (v1.Dot(v1, v1) < v2.Dot(v2, v2)) { - m_unk0x18 *= -1.0f; - } - - return 0; - } - - // FUNCTION: BETA10 0x1004a9b0 - void BETA_1004a9b0(Matrix4& p_m1, Matrix4& p_m2) - { - BETA_1004a9f0(p_m1); - FUN_10004620(p_m2); - } - - // FUNCTION: BETA10 0x1004a9f0 - void BETA_1004a9f0(Matrix4& p_m) - { - p_m.ToQuaternion(m_unk0x00); - m_unk0x30 |= c_bit1; - } - - // FUNCTION: LEGO1 0x10004620 - // FUNCTION: BETA10 0x1004aa30 - void FUN_10004620(Matrix4& p_m) - { - p_m.ToQuaternion(m_unk0x18); - m_unk0x30 |= c_bit2; - } - - // FUNCTION: BETA10 0x10180b80 - void BETA_10180b80(Vector4& p_v) - { - m_unk0x00 = p_v; - m_unk0x30 |= c_bit1; - } - - // FUNCTION: BETA10 0x10180bc0 - void BETA_10180bc0(Vector4& p_v) - { - m_unk0x18 = p_v; - m_unk0x30 |= c_bit2; - } - - const Vector4& GetUnknown0x00() const { return m_unk0x00; } - const Vector4& GetUnknown0x18() const { return m_unk0x18; } - undefined4 GetUnknown0x30() const { return m_unk0x30; } - - // FUNCTION: BETA10 0x1004aaa0 - inline int BETA_1004aaa0(Matrix4& p_matrix, float p_f) - { - float data[4]; - Vector4 v(data); - - if (FUN_100040a0(v, p_f) == 0) { - return p_matrix.FromQuaternion(v); - } - - return -1; - } - -private: - // FUNCTION: LEGO1 0x100040a0 - // FUNCTION: BETA10 0x1004ab10 - inline int FUN_100040a0(Vector4& p_v, float p_f) - { - if (m_unk0x30 == c_bit1) { - p_v = m_unk0x00; - p_v[3] = (float) ((1.0 - p_f) * acos((double) p_v[3]) * 2.0); - return p_v.NormalizeQuaternion(); - } - - if (m_unk0x30 == c_bit2) { - p_v = m_unk0x18; - p_v[3] = (float) (p_f * acos((double) p_v[3]) * 2.0); - return p_v.NormalizeQuaternion(); - } - - if (m_unk0x30 == (c_bit1 | c_bit2)) { - int i; - double d1 = p_v.Dot(m_unk0x00, m_unk0x18); - double a; - double b; - - if (d1 + 1.0 > 0.00001) { - if (1.0 - d1 > 0.00001) { - double d2 = acos(d1); - double denominator = sin(d2); - a = sin((1.0 - p_f) * d2) / denominator; - b = sin(p_f * d2) / denominator; - } - else { - a = 1.0 - p_f; - b = p_f; - } - - for (i = 0; i < 4; i++) { - p_v[i] = (float) (m_unk0x00[i] * a + m_unk0x18[i] * b); - } - } - else { - p_v[0] = -m_unk0x00[1]; - p_v[1] = m_unk0x00[0]; - p_v[2] = -m_unk0x00[3]; - p_v[3] = m_unk0x00[2]; - a = sin((1.0 - p_f) * 1.570796326794895); - b = sin(p_f * 1.570796326794895); - - for (i = 0; i < 3; i++) { - p_v[i] = (float) (m_unk0x00[i] * a + p_v[i] * b); - } - } - - return 0; - } - - return -1; - } - - Mx4DPointFloat m_unk0x00; // 0x00 - Mx4DPointFloat m_unk0x18; // 0x18 - undefined4 m_unk0x30; // 0x30 -}; - #endif // MXGEOMETRY4D_H diff --git a/LEGO1/mxgeometry/mxmatrix.h b/LEGO1/mxgeometry/mxmatrix.h index c9aa762032..6b5b928411 100644 --- a/LEGO1/mxgeometry/mxmatrix.h +++ b/LEGO1/mxgeometry/mxmatrix.h @@ -1,6 +1,42 @@ #ifndef MXMATRIX_H #define MXMATRIX_H -#include "realtime/vector.h" +#include "realtime/matrix.h" +#include "realtime/matrix4d.h" + +// VTABLE: LEGO1 0x100d4300 +// VTABLE: BETA10 0x101b82e0 +// SIZE 0x48 +class MxMatrix : public Matrix4 { +public: + // FUNCTION: LEGO1 0x1006b120 + // FUNCTION: BETA10 0x10015370 + MxMatrix() : Matrix4(m_elements) {} + + // FUNCTION: LEGO1 0x10032770 + // FUNCTION: BETA10 0x1001ff30 + MxMatrix(const MxMatrix& p_matrix) : Matrix4(m_elements) { Equals(p_matrix); } + + // FUNCTION: BETA10 0x1000fc20 + MxMatrix(const Matrix4& p_matrix) : Matrix4(m_elements) { Equals(p_matrix); } + + // FUNCTION: BETA10 0x10010860 + float* operator[](int idx) { return m_data[idx]; } + + // FUNCTION: BETA10 0x1001c670 + const float* operator[](int idx) const { return m_data[idx]; } + + // FUNCTION: LEGO1 0x10002850 + void operator=(const Matrix4& p_matrix) override { Equals(p_matrix); } // vtable+0x28 + + // FUNCTION: LEGO1 0x10002860 + virtual void operator=(const MxMatrix& p_matrix) { Equals(p_matrix); } // vtable+0x48 + +private: + float m_elements[4][4]; // 0x08 +}; + +// Must be included here for correct ordering in binary +#include "realtime/vector4d.h" #endif // MXMATRIX_H diff --git a/LEGO1/mxgeometry/mxquaternion.h b/LEGO1/mxgeometry/mxquaternion.h new file mode 100644 index 0000000000..2738eda836 --- /dev/null +++ b/LEGO1/mxgeometry/mxquaternion.h @@ -0,0 +1,155 @@ +#ifndef MXQUATERNION_H +#define MXQUATERNION_H + +#include "mxgeometry4d.h" + +// SIZE 0x34 +class MxQuaternionTransformer { +public: + enum { + c_startInit = 0x01, + c_endInit = 0x02 + }; + + MxQuaternionTransformer() : m_flags(0) {} + + // FUNCTION: LEGO1 0x10004520 + inline long NormalizeDirection() + { + if (!m_flags) { + return -1; + } + + Mx4DPointFloat v1; + Mx4DPointFloat v2; + + v1 = m_startQuat; + v1 += m_endQuat; + + v2 = m_startQuat; + v2 -= m_endQuat; + + if (v1.Dot(v1, v1) < v2.Dot(v2, v2)) { + m_endQuat *= -1.0f; + } + + return 0; + } + + // FUNCTION: BETA10 0x1004a9b0 + void Set(Matrix4& p_m1, Matrix4& p_m2) + { + SetStart(p_m1); + SetEnd(p_m2); + } + + // FUNCTION: BETA10 0x1004a9f0 + void SetStart(Matrix4& p_m) + { + p_m.ToQuaternion(m_startQuat); + m_flags |= c_startInit; + } + + // FUNCTION: LEGO1 0x10004620 + // FUNCTION: BETA10 0x1004aa30 + void SetEnd(Matrix4& p_m) + { + p_m.ToQuaternion(m_endQuat); + m_flags |= c_endInit; + } + + // FUNCTION: BETA10 0x10180b80 + void SetStart(Vector4& p_v) + { + m_startQuat = p_v; + m_flags |= c_startInit; + } + + // FUNCTION: BETA10 0x10180bc0 + void SetEnd(Vector4& p_v) + { + m_endQuat = p_v; + m_flags |= c_endInit; + } + + const Vector4& GetStartQuat() const { return m_startQuat; } + const Vector4& GetEndQuat() const { return m_endQuat; } + undefined4 GetFlags() const { return m_flags; } + + // FUNCTION: BETA10 0x1004aaa0 + inline int InterpolateToMatrix(Matrix4& p_matrix, float p_f) + { + float data[4]; + Vector4 v(data); + + if (Interpolate(v, p_f) == 0) { + return p_matrix.FromQuaternion(v); + } + + return -1; + } + +private: + // FUNCTION: LEGO1 0x100040a0 + // FUNCTION: BETA10 0x1004ab10 + inline int Interpolate(Vector4& p_v, float p_f) + { + if (m_flags == c_startInit) { + p_v = m_startQuat; + p_v[3] = (float) ((1.0 - p_f) * acos((double) p_v[3]) * 2.0); + return p_v.NormalizeQuaternion(); + } + + if (m_flags == c_endInit) { + p_v = m_endQuat; + p_v[3] = (float) (p_f * acos((double) p_v[3]) * 2.0); + return p_v.NormalizeQuaternion(); + } + + if (m_flags == (c_startInit | c_endInit)) { + int i; + double d1 = p_v.Dot(m_startQuat, m_endQuat); + double a; + double b; + + if (d1 + 1.0 > 0.00001) { + if (1.0 - d1 > 0.00001) { + double d2 = acos(d1); + double denominator = sin(d2); + a = sin((1.0 - p_f) * d2) / denominator; + b = sin(p_f * d2) / denominator; + } + else { + a = 1.0 - p_f; + b = p_f; + } + + for (i = 0; i < 4; i++) { + p_v[i] = (float) (m_startQuat[i] * a + m_endQuat[i] * b); + } + } + else { + p_v[0] = -m_startQuat[1]; + p_v[1] = m_startQuat[0]; + p_v[2] = -m_startQuat[3]; + p_v[3] = m_startQuat[2]; + a = sin((1.0 - p_f) * 1.570796326794895); + b = sin(p_f * 1.570796326794895); + + for (i = 0; i < 3; i++) { + p_v[i] = (float) (m_startQuat[i] * a + p_v[i] * b); + } + } + + return 0; + } + + return -1; + } + + Mx4DPointFloat m_startQuat; // 0x00 + Mx4DPointFloat m_endQuat; // 0x18 + MxU32 m_flags; // 0x30 +}; + +#endif // MXQUATERION_H diff --git a/LEGO1/realtime/matrix.h b/LEGO1/realtime/matrix.h index 3229511377..816d86cb60 100644 --- a/LEGO1/realtime/matrix.h +++ b/LEGO1/realtime/matrix.h @@ -3,7 +3,53 @@ #include "vector.h" -// Note: Many functions most likely take const references/pointers instead of non-const. -// The class needs to undergo a very careful refactoring to fix that (no matches should break). +// Note: virtual function overloads appear in the virtual table +// in reverse order of appearance. + +struct UnknownMatrixType { + float m_data[4][4]; +}; + +// VTABLE: LEGO1 0x100d4350 +// VTABLE: BETA10 0x101b8340 +// SIZE 0x08 +class Matrix4 { +public: + // FUNCTION: LEGO1 0x10004500 + // FUNCTION: BETA10 0x1000fc70 + Matrix4(float (*p_data)[4]) { SetData(p_data); } + + inline virtual void Equals(float (*p_data)[4]); // vtable+0x04 + inline virtual void Equals(const Matrix4& p_matrix); // vtable+0x00 + inline virtual void SetData(float (*p_data)[4]); // vtable+0x0c + inline virtual void SetData(UnknownMatrixType& p_matrix); // vtable+0x08 + inline virtual float (*GetData())[4]; // vtable+0x14 + inline virtual float (*GetData() const)[4]; // vtable+0x10 + inline virtual float* Element(int p_row, int p_col); // vtable+0x1c + inline virtual const float* Element(int p_row, int p_col) const; // vtable+0x18 + inline virtual void Clear(); // vtable+0x20 + inline virtual void SetIdentity(); // vtable+0x24 + inline virtual void operator=(const Matrix4& p_matrix); // vtable+0x28 + inline virtual Matrix4& operator+=(float (*p_data)[4]); // vtable+0x2c + inline virtual void TranslateBy(const float& p_x, const float& p_y, const float& p_z); // vtable+0x30 + inline virtual void SetTranslation(const float& p_x, const float& p_y, const float& p_z); // vtable+0x34 + inline virtual void Product(float (*p_a)[4], float (*p_b)[4]); // vtable+0x3c + inline virtual void Product(const Matrix4& p_a, const Matrix4& p_b); // vtable+0x38 + inline virtual void ToQuaternion(Vector4& p_resultQuat); // vtable+0x40 + inline virtual int FromQuaternion(const Vector4& p_vec); // vtable+0x44 + + inline void Scale(const float& p_x, const float& p_y, const float& p_z); + inline void RotateX(const float& p_angle); + inline void RotateY(const float& p_angle); + inline void RotateZ(const float& p_angle); + inline int BETA_1005a590(Matrix4& p_mat); + inline void Swap(int p_d1, int p_d2); + + float* operator[](int idx) { return m_data[idx]; } + const float* operator[](int idx) const { return m_data[idx]; } + +protected: + float (*m_data)[4]; +}; #endif // MATRIX_H diff --git a/LEGO1/realtime/matrix4d.h b/LEGO1/realtime/matrix4d.h new file mode 100644 index 0000000000..506f4e7408 --- /dev/null +++ b/LEGO1/realtime/matrix4d.h @@ -0,0 +1,362 @@ +#ifndef MATRIX4D_H +#define MATRIX4D_H + +#include "matrix.h" + +// FUNCTION: LEGO1 0x10002320 +// FUNCTION: BETA10 0x1000fcb0 +void Matrix4::Equals(float (*p_data)[4]) +{ + memcpy(m_data, p_data, sizeof(float) * 4 * 4); +} + +// FUNCTION: LEGO1 0x10002340 +// FUNCTION: BETA10 0x1000fcf0 +void Matrix4::Equals(const Matrix4& p_matrix) +{ + memcpy(m_data, p_matrix.m_data, sizeof(float) * 4 * 4); +} + +// FUNCTION: LEGO1 0x10002360 +// FUNCTION: BETA10 0x1000fd30 +void Matrix4::SetData(float (*p_data)[4]) +{ + m_data = p_data; +} + +// FUNCTION: LEGO1 0x10002370 +// FUNCTION: BETA10 0x1000fd60 +void Matrix4::SetData(UnknownMatrixType& p_matrix) +{ + m_data = p_matrix.m_data; +} + +// FUNCTION: LEGO1 0x10002380 +// FUNCTION: BETA10 0x1000fd90 +float (*Matrix4::GetData())[4] +{ + return m_data; +} + +// FUNCTION: LEGO1 0x10002390 +// FUNCTION: BETA10 0x1000fdc0 +float (*Matrix4::GetData() const)[4] +{ + return m_data; +} + +// FUNCTION: LEGO1 0x100023a0 +// FUNCTION: BETA10 0x1000fdf0 +float* Matrix4::Element(int p_row, int p_col) +{ + return &m_data[p_row][p_col]; +} + +// FUNCTION: LEGO1 0x100023c0 +// FUNCTION: BETA10 0x1000fe30 +const float* Matrix4::Element(int p_row, int p_col) const +{ + return &m_data[p_row][p_col]; +} + +// FUNCTION: LEGO1 0x100023e0 +// FUNCTION: BETA10 0x1000fe70 +void Matrix4::Clear() +{ + memset(m_data, 0, 16 * sizeof(float)); +} + +// FUNCTION: LEGO1 0x100023f0 +// FUNCTION: BETA10 0x1000feb0 +void Matrix4::SetIdentity() +{ + Clear(); + m_data[0][0] = 1.0f; + m_data[1][1] = 1.0f; + m_data[2][2] = 1.0f; + m_data[3][3] = 1.0f; +} + +// FUNCTION: LEGO1 0x10002420 +// FUNCTION: BETA10 0x1000ff20 +void Matrix4::operator=(const Matrix4& p_matrix) +{ + Equals(p_matrix); +} + +// FUNCTION: LEGO1 0x10002430 +// FUNCTION: BETA10 0x1000ff50 +Matrix4& Matrix4::operator+=(float (*p_data)[4]) +{ + for (int i = 0; i < 16; i++) { + ((float*) m_data)[i] += ((float*) p_data)[i]; + } + + return *this; +} + +// FUNCTION: LEGO1 0x10002460 +// FUNCTION: BETA10 0x1000ffc0 +void Matrix4::TranslateBy(const float& p_x, const float& p_y, const float& p_z) +{ + m_data[3][0] += p_x; + m_data[3][1] += p_y; + m_data[3][2] += p_z; +} + +// FUNCTION: LEGO1 0x100024a0 +// FUNCTION: BETA10 0x10010040 +void Matrix4::SetTranslation(const float& p_x, const float& p_y, const float& p_z) +{ + m_data[3][0] = p_x; + m_data[3][1] = p_y; + m_data[3][2] = p_z; +} + +// FUNCTION: LEGO1 0x100024d0 +// FUNCTION: BETA10 0x100100a0 +void Matrix4::Product(float (*p_a)[4], float (*p_b)[4]) +{ + float* cur = (float*) m_data; + + for (int row = 0; row < 4; row++) { + for (int col = 0; col < 4; col++) { + *cur = 0.0f; + for (int k = 0; k < 4; k++) { + *cur += p_a[row][k] * p_b[k][col]; + } + cur++; + } + } +} + +// FUNCTION: LEGO1 0x10002530 +// FUNCTION: BETA10 0x10010180 +void Matrix4::Product(const Matrix4& p_a, const Matrix4& p_b) +{ + Product(p_a.m_data, p_b.m_data); +} + +// FUNCTION: LEGO1 0x10002550 +// FUNCTION: BETA10 0x100101c0 +void Matrix4::ToQuaternion(Vector4& p_outQuat) +{ + float trace; + float localc = m_data[0][0] + m_data[1][1] + m_data[2][2]; + + if (localc > 0) { + trace = (float) sqrt(localc + 1.0); + p_outQuat[3] = trace * 0.5f; + trace = 0.5f / trace; + p_outQuat[0] = (m_data[2][1] - m_data[1][2]) * trace; + p_outQuat[1] = (m_data[0][2] - m_data[2][0]) * trace; + p_outQuat[2] = (m_data[1][0] - m_data[0][1]) * trace; + } + else { + // GLOBAL: LEGO1 0x100d4090 + static int rotateIndex[] = {1, 2, 0}; + + // Largest element along the trace + int largest = 0; + if (m_data[0][0] < m_data[1][1]) { + largest = 1; + } + if (*Element(largest, largest) < m_data[2][2]) { + largest = 2; + } + + int next = rotateIndex[largest]; + int nextNext = rotateIndex[next]; + + trace = (float) sqrt(*Element(largest, largest) - (*Element(nextNext, nextNext) + *Element(next, next)) + 1.0); + + p_outQuat[largest] = trace * 0.5f; + trace = 0.5f / trace; + + p_outQuat[3] = (*Element(nextNext, next) - *Element(next, nextNext)) * trace; + p_outQuat[next] = (*Element(largest, next) + *Element(next, largest)) * trace; + p_outQuat[nextNext] = (*Element(largest, nextNext) + *Element(nextNext, largest)) * trace; + } +} + +// FUNCTION: LEGO1 0x10002710 +// FUNCTION: BETA10 0x10010550 +int Matrix4::FromQuaternion(const Vector4& p_vec) +{ + float local14 = p_vec.LenSquared(); + + if (local14 > 0.0f) { + local14 = 2.0f / local14; + + float local24 = p_vec[0] * local14; + float local34 = p_vec[1] * local14; + float local10 = p_vec[2] * local14; + + float local28 = p_vec[3] * local24; + float local2c = p_vec[3] * local34; + float local30 = p_vec[3] * local10; + + float local38 = p_vec[0] * local24; + float local8 = p_vec[0] * local34; + float localc = p_vec[0] * local10; + + float local18 = p_vec[1] * local34; + float local1c = p_vec[1] * local10; + float local20 = p_vec[2] * local10; + + m_data[0][0] = 1.0f - (local18 + local20); + m_data[1][0] = local8 + local30; + m_data[2][0] = localc - local2c; + + m_data[0][1] = local8 - local30; + m_data[1][1] = 1.0f - (local38 + local20); + m_data[2][1] = local1c + local28; + + m_data[0][2] = local2c + localc; + m_data[1][2] = local1c - local28; + m_data[2][2] = 1.0f - (local18 + local38); + + m_data[3][0] = 0.0f; + m_data[3][1] = 0.0f; + m_data[3][2] = 0.0f; + m_data[3][3] = 1.0f; + + m_data[0][3] = 0.0f; + m_data[1][3] = 0.0f; + m_data[2][3] = 0.0f; + return 0; + } + else { + return -1; + } +} + +// FUNCTION: LEGO1 0x100a0ff0 +// FUNCTION: BETA10 0x1001fe60 +void Matrix4::Scale(const float& p_x, const float& p_y, const float& p_z) +{ + for (int i = 0; i < 4; i++) { + m_data[i][0] *= p_x; + m_data[i][1] *= p_y; + m_data[i][2] *= p_z; + } +} + +// FUNCTION: BETA10 0x1001c6a0 +void Matrix4::RotateX(const float& p_angle) +{ + float s = sin(p_angle); + float c = cos(p_angle); + float matrix[4][4]; + memcpy(matrix, m_data, sizeof(float) * 16); + + for (int i = 0; i < 4; i++) { + m_data[i][1] = matrix[i][1] * c - matrix[i][2] * s; + m_data[i][2] = matrix[i][2] * c + matrix[i][1] * s; + } +} + +// FUNCTION: BETA10 0x1001fd60 +void Matrix4::RotateY(const float& p_angle) +{ + float s = sin(p_angle); + float c = cos(p_angle); + float matrix[4][4]; + memcpy(matrix, m_data, sizeof(float) * 16); + + for (int i = 0; i < 4; i++) { + m_data[i][0] = matrix[i][0] * c + matrix[i][2] * s; + m_data[i][2] = matrix[i][2] * c - matrix[i][0] * s; + } +} + +// FUNCTION: BETA10 0x1006ab10 +void Matrix4::RotateZ(const float& p_angle) +{ + float s = sin(p_angle); + float c = cos(p_angle); + float matrix[4][4]; + memcpy(matrix, m_data, sizeof(float) * 16); + + for (int i = 0; i < 4; i++) { + m_data[i][0] = matrix[i][0] * c - matrix[i][1] * s; + m_data[i][1] = matrix[i][1] * c + matrix[i][0] * s; + } +} + +// FUNCTION: BETA10 0x1005a590 +int Matrix4::BETA_1005a590(Matrix4& p_mat) +{ + float local5c[4][4]; + Matrix4 localc(local5c); + + ((Matrix4&) localc) = *this; + p_mat.SetIdentity(); + + for (int i = 0; i < 4; i++) { + int local1c = i; + int local10; + + for (local10 = i + 1; local10 < 4; local10++) { + if (fabs(localc[local1c][i]) < fabs(localc[local10][i])) { + local1c = local10; + } + } + + if (local1c != i) { + localc.Swap(local1c, i); + p_mat.Swap(local1c, i); + } + + if (localc[i][i] < 0.001f && localc[i][i] > -0.001f) { + return -1; + } + + float local60 = localc[i][i]; + int local18; + + for (local18 = 0; local18 < 4; local18++) { + p_mat[i][local18] /= local60; + } + + for (local18 = 0; local18 < 4; local18++) { + localc[i][local18] /= local60; + } + + for (local10 = 0; local10 < 4; local10++) { + if (i != local10) { + float afStack70[4]; + + for (local18 = 0; local18 < 4; local18++) { + afStack70[local18] = p_mat[i][local18] * localc[local10][i]; + } + + for (local18 = 0; local18 < 4; local18++) { + p_mat[local10][local18] -= afStack70[local18]; + } + + for (local18 = 0; local18 < 4; local18++) { + afStack70[local18] = localc[i][local18] * localc[local10][i]; + } + + for (local18 = 0; local18 < 4; local18++) { + localc[local10][local18] -= afStack70[local18]; + } + } + } + } + + return 0; +} + +// FUNCTION: LEGO1 0x1006b500 +void Matrix4::Swap(int p_d1, int p_d2) +{ + for (int i = 0; i < 4; i++) { + float e = m_data[p_d1][i]; + m_data[p_d1][i] = m_data[p_d2][i]; + m_data[p_d2][i] = e; + } +} + +#endif // MATRIX4D_H diff --git a/LEGO1/realtime/vector.h b/LEGO1/realtime/vector.h index 3dd84bf569..58569d7fb0 100644 --- a/LEGO1/realtime/vector.h +++ b/LEGO1/realtime/vector.h @@ -129,9 +129,6 @@ class Vector3 : public Vector2 { friend class Mx3DPointFloat; }; -#include "vector2d.inl" -#include "vector3d.inl" - // VTABLE: LEGO1 0x100d45a0 // VTABLE: BETA10 0x101bac38 // SIZE 0x08 @@ -150,9 +147,7 @@ class Vector4 : public Vector3 { // FUNCTION: BETA10 0x100701b0 inline Vector4(const float* p_data) : Vector3((float*) p_data) {} - // Note: virtual function overloads appear in the virtual table - // in reverse order of appearance. - +protected: inline void AddImpl(const float* p_value) override; // vtable+0x04 inline void AddImpl(float p_value) override; // vtable+0x00 inline void SubImpl(const float* p_value) override; // vtable+0x08 @@ -162,10 +157,10 @@ class Vector4 : public Vector3 { inline float DotImpl(const float* p_a, const float* p_b) const override; // vtable+0x18 inline void EqualsImpl(const float* p_data) override; // vtable+0x20 - inline void Clear() override; // vtable+0x2c - inline float LenSquared() const override; // vtable+0x40 - inline void Fill(const float& p_value) override; // vtable+0x84 - +public: + inline void Clear() override; // vtable+0x2c + inline float LenSquared() const override; // vtable+0x40 + inline void Fill(const float& p_value) override; // vtable+0x84 inline virtual void SetMatrixProduct(const float* p_vec, const float* p_mat); // vtable+0x8c inline virtual void SetMatrixProduct(const Vector4& p_a, const float* p_b); // vtable+0x88 inline virtual int NormalizeQuaternion(); // vtable+0x90 @@ -179,524 +174,4 @@ class Vector4 : public Vector3 { friend class Mx4DPointFloat; }; -struct UnknownMatrixType { - float m_data[4][4]; -}; - -// VTABLE: LEGO1 0x100d4350 -// VTABLE: BETA10 0x101b8340 -// SIZE 0x08 -class Matrix4 { -public: - // FUNCTION: LEGO1 0x10004500 - // FUNCTION: BETA10 0x1000fc70 - Matrix4(float (*p_data)[4]) { SetData(p_data); } - - // Note: virtual function overloads appear in the virtual table - // in reverse order of appearance. - - // FUNCTION: LEGO1 0x10002320 - // FUNCTION: BETA10 0x1000fcb0 - virtual void Equals(float (*p_data)[4]) { memcpy(m_data, p_data, sizeof(float) * 4 * 4); } // vtable+0x04 - - // FUNCTION: LEGO1 0x10002340 - // FUNCTION: BETA10 0x1000fcf0 - virtual void Equals(const Matrix4& p_matrix) - { - memcpy(m_data, p_matrix.m_data, sizeof(float) * 4 * 4); - } // vtable+0x00 - - // FUNCTION: LEGO1 0x10002360 - // FUNCTION: BETA10 0x1000fd30 - virtual void SetData(float (*p_data)[4]) { m_data = p_data; } // vtable+0x0c - - // FUNCTION: LEGO1 0x10002370 - // FUNCTION: BETA10 0x1000fd60 - virtual void SetData(UnknownMatrixType& p_matrix) { m_data = p_matrix.m_data; } // vtable+0x08 - - // FUNCTION: LEGO1 0x10002380 - // FUNCTION: BETA10 0x1000fd90 - virtual float (*GetData())[4] { return m_data; } // vtable+0x14 - - // FUNCTION: LEGO1 0x10002390 - // FUNCTION: BETA10 0x1000fdc0 - virtual float (*GetData() const)[4] { return m_data; } // vtable+0x10 - - // FUNCTION: LEGO1 0x100023a0 - // FUNCTION: BETA10 0x1000fdf0 - virtual float* Element(int p_row, int p_col) { return &m_data[p_row][p_col]; } // vtable+0x1c - - // FUNCTION: LEGO1 0x100023c0 - // FUNCTION: BETA10 0x1000fe30 - virtual const float* Element(int p_row, int p_col) const { return &m_data[p_row][p_col]; } // vtable+0x18 - - // FUNCTION: LEGO1 0x100023e0 - // FUNCTION: BETA10 0x1000fe70 - virtual void Clear() { memset(m_data, 0, 16 * sizeof(float)); } // vtable+0x20 - - // FUNCTION: LEGO1 0x100023f0 - // FUNCTION: BETA10 0x1000feb0 - virtual void SetIdentity() - { - Clear(); - m_data[0][0] = 1.0f; - m_data[1][1] = 1.0f; - m_data[2][2] = 1.0f; - m_data[3][3] = 1.0f; - } // vtable+0x24 - - // FUNCTION: LEGO1 0x10002420 - // FUNCTION: BETA10 0x1000ff20 - virtual void operator=(const Matrix4& p_matrix) { Equals(p_matrix); } // vtable+0x28 - - // FUNCTION: LEGO1 0x10002430 - // FUNCTION: BETA10 0x1000ff50 - virtual Matrix4& operator+=(float (*p_data)[4]) - { - for (int i = 0; i < 16; i++) { - ((float*) m_data)[i] += ((float*) p_data)[i]; - } - return *this; - } // vtable+0x2c - - // FUNCTION: LEGO1 0x10002460 - // FUNCTION: BETA10 0x1000ffc0 - virtual void TranslateBy(const float& p_x, const float& p_y, const float& p_z) - { - m_data[3][0] += p_x; - m_data[3][1] += p_y; - m_data[3][2] += p_z; - } // vtable+0x30 - - // FUNCTION: LEGO1 0x100024a0 - // FUNCTION: BETA10 0x10010040 - virtual void SetTranslation(const float& p_x, const float& p_y, const float& p_z) - { - m_data[3][0] = p_x; - m_data[3][1] = p_y; - m_data[3][2] = p_z; - } // vtable+0x34 - - // FUNCTION: LEGO1 0x100024d0 - // FUNCTION: BETA10 0x100100a0 - virtual void Product(float (*p_a)[4], float (*p_b)[4]) - { - float* cur = (float*) m_data; - for (int row = 0; row < 4; row++) { - for (int col = 0; col < 4; col++) { - *cur = 0.0f; - for (int k = 0; k < 4; k++) { - *cur += p_a[row][k] * p_b[k][col]; - } - cur++; - } - } - } // vtable+0x3c - - // FUNCTION: LEGO1 0x10002530 - // FUNCTION: BETA10 0x10010180 - virtual void Product(const Matrix4& p_a, const Matrix4& p_b) { Product(p_a.m_data, p_b.m_data); } // vtable+0x38 - - inline virtual void ToQuaternion(Vector3& p_resultQuat); // vtable+0x40 - inline virtual int FromQuaternion(const Vector3& p_vec); // vtable+0x44 - - // FUNCTION: LEGO1 0x100a0ff0 - // FUNCTION: BETA10 0x1001fe60 - void Scale(const float& p_x, const float& p_y, const float& p_z) - { - for (int i = 0; i < 4; i++) { - m_data[i][0] *= p_x; - m_data[i][1] *= p_y; - m_data[i][2] *= p_z; - } - } - - // FUNCTION: BETA10 0x1001c6a0 - void RotateX(const float& p_angle) - { - float s = sin(p_angle); - float c = cos(p_angle); - float matrix[4][4]; - memcpy(matrix, m_data, sizeof(float) * 16); - for (int i = 0; i < 4; i++) { - m_data[i][1] = matrix[i][1] * c - matrix[i][2] * s; - m_data[i][2] = matrix[i][2] * c + matrix[i][1] * s; - } - } - - // FUNCTION: BETA10 0x1001fd60 - void RotateY(const float& p_angle) - { - float s = sin(p_angle); - float c = cos(p_angle); - float matrix[4][4]; - memcpy(matrix, m_data, sizeof(float) * 16); - for (int i = 0; i < 4; i++) { - m_data[i][0] = matrix[i][0] * c + matrix[i][2] * s; - m_data[i][2] = matrix[i][2] * c - matrix[i][0] * s; - } - } - - // FUNCTION: BETA10 0x1006ab10 - void RotateZ(const float& p_angle) - { - float s = sin(p_angle); - float c = cos(p_angle); - float matrix[4][4]; - memcpy(matrix, m_data, sizeof(float) * 16); - for (int i = 0; i < 4; i++) { - m_data[i][0] = matrix[i][0] * c - matrix[i][1] * s; - m_data[i][1] = matrix[i][1] * c + matrix[i][0] * s; - } - } - - inline int BETA_1005a590(Matrix4& p_mat); - - // FUNCTION: LEGO1 0x1006b500 - void Swap(int p_d1, int p_d2) - { - for (int i = 0; i < 4; i++) { - float e = m_data[p_d1][i]; - m_data[p_d1][i] = m_data[p_d2][i]; - m_data[p_d2][i] = e; - } - } - - float* operator[](int idx) { return m_data[idx]; } - const float* operator[](int idx) const { return m_data[idx]; } - -protected: - float (*m_data)[4]; -}; - -// FUNCTION: LEGO1 0x10002550 -// FUNCTION: BETA10 0x100101c0 -inline void Matrix4::ToQuaternion(Vector3& p_outQuat) -{ - float trace; - float localc = m_data[0][0] + m_data[1][1] + m_data[2][2]; - - if (localc > 0) { - trace = (float) sqrt(localc + 1.0); - p_outQuat[3] = trace * 0.5f; - trace = 0.5f / trace; - p_outQuat[0] = (m_data[2][1] - m_data[1][2]) * trace; - p_outQuat[1] = (m_data[0][2] - m_data[2][0]) * trace; - p_outQuat[2] = (m_data[1][0] - m_data[0][1]) * trace; - } - else { - // GLOBAL: LEGO1 0x100d4090 - static int rotateIndex[] = {1, 2, 0}; - - // Largest element along the trace - int largest = 0; - if (m_data[0][0] < m_data[1][1]) { - largest = 1; - } - if (*Element(largest, largest) < m_data[2][2]) { - largest = 2; - } - - int next = rotateIndex[largest]; - int nextNext = rotateIndex[next]; - - trace = (float) sqrt(*Element(largest, largest) - (*Element(nextNext, nextNext) + *Element(next, next)) + 1.0); - - p_outQuat[largest] = trace * 0.5f; - trace = 0.5f / trace; - - p_outQuat[3] = (*Element(nextNext, next) - *Element(next, nextNext)) * trace; - p_outQuat[next] = (*Element(largest, next) + *Element(next, largest)) * trace; - p_outQuat[nextNext] = (*Element(largest, nextNext) + *Element(nextNext, largest)) * trace; - } -} - -// FUNCTION: LEGO1 0x10002710 -// FUNCTION: BETA10 0x10010550 -inline int Matrix4::FromQuaternion(const Vector3& p_vec) -{ - float local14 = p_vec.LenSquared(); - - if (local14 > 0.0f) { - local14 = 2.0f / local14; - - float local24 = p_vec[0] * local14; - float local34 = p_vec[1] * local14; - float local10 = p_vec[2] * local14; - - float local28 = p_vec[3] * local24; - float local2c = p_vec[3] * local34; - float local30 = p_vec[3] * local10; - - float local38 = p_vec[0] * local24; - float local8 = p_vec[0] * local34; - float localc = p_vec[0] * local10; - - float local18 = p_vec[1] * local34; - float local1c = p_vec[1] * local10; - float local20 = p_vec[2] * local10; - - m_data[0][0] = 1.0f - (local18 + local20); - m_data[1][0] = local8 + local30; - m_data[2][0] = localc - local2c; - - m_data[0][1] = local8 - local30; - m_data[1][1] = 1.0f - (local38 + local20); - m_data[2][1] = local1c + local28; - - m_data[0][2] = local2c + localc; - m_data[1][2] = local1c - local28; - m_data[2][2] = 1.0f - (local18 + local38); - - m_data[3][0] = 0.0f; - m_data[3][1] = 0.0f; - m_data[3][2] = 0.0f; - m_data[3][3] = 1.0f; - - m_data[0][3] = 0.0f; - m_data[1][3] = 0.0f; - m_data[2][3] = 0.0f; - return 0; - } - else { - return -1; - } -} - -// VTABLE: LEGO1 0x100d4300 -// VTABLE: BETA10 0x101b82e0 -// SIZE 0x48 -class MxMatrix : public Matrix4 { -public: - // FUNCTION: LEGO1 0x1006b120 - // FUNCTION: BETA10 0x10015370 - MxMatrix() : Matrix4(m_elements) {} - - // FUNCTION: LEGO1 0x10032770 - // FUNCTION: BETA10 0x1001ff30 - MxMatrix(const MxMatrix& p_matrix) : Matrix4(m_elements) { Equals(p_matrix); } - - // FUNCTION: BETA10 0x1000fc20 - MxMatrix(const Matrix4& p_matrix) : Matrix4(m_elements) { Equals(p_matrix); } - - // FUNCTION: BETA10 0x10010860 - float* operator[](int idx) { return m_data[idx]; } - - // FUNCTION: BETA10 0x1001c670 - const float* operator[](int idx) const { return m_data[idx]; } - - // FUNCTION: LEGO1 0x10002850 - void operator=(const Matrix4& p_matrix) override { Equals(p_matrix); } // vtable+0x28 - - // FUNCTION: LEGO1 0x10002860 - virtual void operator=(const MxMatrix& p_matrix) { Equals(p_matrix); } // vtable+0x48 - -private: - float m_elements[4][4]; // 0x08 -}; - -// FUNCTION: LEGO1 0x10002870 -void Vector4::AddImpl(const float* p_value) -{ - m_data[0] += p_value[0]; - m_data[1] += p_value[1]; - m_data[2] += p_value[2]; - m_data[3] += p_value[3]; -} - -// FUNCTION: LEGO1 0x100028b0 -void Vector4::AddImpl(float p_value) -{ - m_data[0] += p_value; - m_data[1] += p_value; - m_data[2] += p_value; - m_data[3] += p_value; -} - -// FUNCTION: LEGO1 0x100028f0 -void Vector4::SubImpl(const float* p_value) -{ - m_data[0] -= p_value[0]; - m_data[1] -= p_value[1]; - m_data[2] -= p_value[2]; - m_data[3] -= p_value[3]; -} - -// FUNCTION: LEGO1 0x10002930 -void Vector4::MulImpl(const float* p_value) -{ - m_data[0] *= p_value[0]; - m_data[1] *= p_value[1]; - m_data[2] *= p_value[2]; - m_data[3] *= p_value[3]; -} - -// FUNCTION: LEGO1 0x10002970 -void Vector4::MulImpl(const float& p_value) -{ - m_data[0] *= p_value; - m_data[1] *= p_value; - m_data[2] *= p_value; - m_data[3] *= p_value; -} - -// FUNCTION: LEGO1 0x100029b0 -void Vector4::DivImpl(const float& p_value) -{ - m_data[0] /= p_value; - m_data[1] /= p_value; - m_data[2] /= p_value; - m_data[3] /= p_value; -} - -// FUNCTION: LEGO1 0x100029f0 -float Vector4::DotImpl(const float* p_a, const float* p_b) const -{ - return p_a[0] * p_b[0] + p_a[2] * p_b[2] + (p_a[1] * p_b[1] + p_a[3] * p_b[3]); -} - -// FUNCTION: LEGO1 0x10002a20 -void Vector4::EqualsImpl(const float* p_data) -{ - memcpy(m_data, p_data, sizeof(float) * 4); -} - -// FUNCTION: LEGO1 0x10002a40 -void Vector4::SetMatrixProduct(const float* p_vec, const float* p_mat) -{ - m_data[0] = p_vec[0] * p_mat[0] + p_vec[1] * p_mat[4] + p_vec[2] * p_mat[8] + p_vec[3] * p_mat[12]; - m_data[1] = p_vec[0] * p_mat[1] + p_vec[1] * p_mat[5] + p_vec[2] * p_mat[9] + p_vec[4] * p_mat[13]; - m_data[2] = p_vec[0] * p_mat[2] + p_vec[1] * p_mat[6] + p_vec[2] * p_mat[10] + p_vec[4] * p_mat[14]; - m_data[3] = p_vec[0] * p_mat[3] + p_vec[1] * p_mat[7] + p_vec[2] * p_mat[11] + p_vec[4] * p_mat[15]; -} - -// FUNCTION: LEGO1 0x10002ae0 -void Vector4::SetMatrixProduct(const Vector4& p_a, const float* p_b) -{ - SetMatrixProduct(p_a.m_data, p_b); -} - -// FUNCTION: LEGO1 0x10002b00 -void Vector4::Clear() -{ - memset(m_data, 0, sizeof(float) * 4); -} - -// FUNCTION: LEGO1 0x10002b20 -float Vector4::LenSquared() const -{ - return m_data[1] * m_data[1] + m_data[0] * m_data[0] + m_data[2] * m_data[2] + m_data[3] * m_data[3]; -} - -// FUNCTION: LEGO1 0x10002b40 -void Vector4::Fill(const float& p_value) -{ - m_data[0] = p_value; - m_data[1] = p_value; - m_data[2] = p_value; - m_data[3] = p_value; -} - -// FUNCTION: BETA10 0x1005a590 -inline int Matrix4::BETA_1005a590(Matrix4& p_mat) -{ - float local5c[4][4]; - Matrix4 localc(local5c); - - ((Matrix4&) localc) = *this; - p_mat.SetIdentity(); - - for (int i = 0; i < 4; i++) { - int local1c = i; - int local10; - - for (local10 = i + 1; local10 < 4; local10++) { - if (fabs(localc[local1c][i]) < fabs(localc[local10][i])) { - local1c = local10; - } - } - - if (local1c != i) { - localc.Swap(local1c, i); - p_mat.Swap(local1c, i); - } - - if (localc[i][i] < 0.001f && localc[i][i] > -0.001f) { - return -1; - } - - float local60 = localc[i][i]; - int local18; - - for (local18 = 0; local18 < 4; local18++) { - p_mat[i][local18] /= local60; - } - - for (local18 = 0; local18 < 4; local18++) { - localc[i][local18] /= local60; - } - - for (local10 = 0; local10 < 4; local10++) { - if (i != local10) { - float afStack70[4]; - - for (local18 = 0; local18 < 4; local18++) { - afStack70[local18] = p_mat[i][local18] * localc[local10][i]; - } - - for (local18 = 0; local18 < 4; local18++) { - p_mat[local10][local18] -= afStack70[local18]; - } - - for (local18 = 0; local18 < 4; local18++) { - afStack70[local18] = localc[i][local18] * localc[local10][i]; - } - - for (local18 = 0; local18 < 4; local18++) { - localc[local10][local18] -= afStack70[local18]; - } - } - } - } - - return 0; -} - -// FUNCTION: LEGO1 0x10002b70 -// FUNCTION: BETA10 0x10048ad0 -inline int Vector4::NormalizeQuaternion() -{ - float length = m_data[0] * m_data[0] + m_data[1] * m_data[1] + m_data[2] * m_data[2]; - - if (length > 0.0f) { - float theta = m_data[3] * 0.5f; - float magnitude = sin((double) theta); - m_data[3] = cos((double) theta); - - magnitude = magnitude / (float) sqrt((double) length); - m_data[0] *= magnitude; - m_data[1] *= magnitude; - m_data[2] *= magnitude; - return 0; - } - else { - return -1; - } -} - -// FUNCTION: LEGO1 0x10002bf0 -// FUNCTION: BETA10 0x10048c20 -inline int Vector4::EqualsHamiltonProduct(const Vector4& p_a, const Vector4& p_b) -{ - m_data[3] = p_a.m_data[3] * p_b.m_data[3] - - (p_a.m_data[0] * p_b.m_data[0] + p_a.m_data[2] * p_b.m_data[2] + p_a.m_data[1] * p_b.m_data[1]); - - Vector3::EqualsCrossImpl(p_a.m_data, p_b.m_data); - - m_data[0] = p_b.m_data[3] * p_a.m_data[0] + p_a.m_data[3] * p_b.m_data[0] + m_data[0]; - m_data[1] = p_b.m_data[1] * p_a.m_data[3] + p_a.m_data[1] * p_b.m_data[3] + m_data[1]; - m_data[2] = p_b.m_data[2] * p_a.m_data[3] + p_a.m_data[2] * p_b.m_data[3] + m_data[2]; - return 0; -} - #endif // VECTOR_H diff --git a/LEGO1/realtime/vector2d.inl b/LEGO1/realtime/vector2d.h similarity index 98% rename from LEGO1/realtime/vector2d.inl rename to LEGO1/realtime/vector2d.h index 366086131f..c998f35682 100644 --- a/LEGO1/realtime/vector2d.inl +++ b/LEGO1/realtime/vector2d.h @@ -1,4 +1,7 @@ +#ifndef VECTOR2D_H +#define VECTOR2D_H + #include "vector.h" // FUNCTION: LEGO1 0x10001f80 @@ -194,3 +197,5 @@ void Vector2::SetVector(const Vector2& p_other) { EqualsImpl(p_other.m_data); } + +#endif // VECTOR2D_H diff --git a/LEGO1/realtime/vector3d.inl b/LEGO1/realtime/vector3d.h similarity index 96% rename from LEGO1/realtime/vector3d.inl rename to LEGO1/realtime/vector3d.h index 127b89994d..28a7cd2632 100644 --- a/LEGO1/realtime/vector3d.inl +++ b/LEGO1/realtime/vector3d.h @@ -1,4 +1,8 @@ +#ifndef VECTOR3D_H +#define VECTOR3D_H + #include "vector.h" +#include "vector2d.h" // FUNCTION: LEGO1 0x10002270 // FUNCTION: BETA10 0x10011350 @@ -110,3 +114,5 @@ void Vector3::Fill(const float& p_value) m_data[1] = p_value; m_data[2] = p_value; } + +#endif // VECTOR3D_H diff --git a/LEGO1/realtime/vector4d.h b/LEGO1/realtime/vector4d.h new file mode 100644 index 0000000000..a94e8f093c --- /dev/null +++ b/LEGO1/realtime/vector4d.h @@ -0,0 +1,145 @@ +#ifndef VECTOR4D_H +#define VECTOR4D_H + +#include "vector.h" + +// FUNCTION: LEGO1 0x10002870 +void Vector4::AddImpl(const float* p_value) +{ + m_data[0] += p_value[0]; + m_data[1] += p_value[1]; + m_data[2] += p_value[2]; + m_data[3] += p_value[3]; +} + +// FUNCTION: LEGO1 0x100028b0 +void Vector4::AddImpl(float p_value) +{ + m_data[0] += p_value; + m_data[1] += p_value; + m_data[2] += p_value; + m_data[3] += p_value; +} + +// FUNCTION: LEGO1 0x100028f0 +void Vector4::SubImpl(const float* p_value) +{ + m_data[0] -= p_value[0]; + m_data[1] -= p_value[1]; + m_data[2] -= p_value[2]; + m_data[3] -= p_value[3]; +} + +// FUNCTION: LEGO1 0x10002930 +void Vector4::MulImpl(const float* p_value) +{ + m_data[0] *= p_value[0]; + m_data[1] *= p_value[1]; + m_data[2] *= p_value[2]; + m_data[3] *= p_value[3]; +} + +// FUNCTION: LEGO1 0x10002970 +void Vector4::MulImpl(const float& p_value) +{ + m_data[0] *= p_value; + m_data[1] *= p_value; + m_data[2] *= p_value; + m_data[3] *= p_value; +} + +// FUNCTION: LEGO1 0x100029b0 +void Vector4::DivImpl(const float& p_value) +{ + m_data[0] /= p_value; + m_data[1] /= p_value; + m_data[2] /= p_value; + m_data[3] /= p_value; +} + +// FUNCTION: LEGO1 0x100029f0 +float Vector4::DotImpl(const float* p_a, const float* p_b) const +{ + return p_a[0] * p_b[0] + p_a[2] * p_b[2] + (p_a[1] * p_b[1] + p_a[3] * p_b[3]); +} + +// FUNCTION: LEGO1 0x10002a20 +void Vector4::EqualsImpl(const float* p_data) +{ + memcpy(m_data, p_data, sizeof(float) * 4); +} + +// FUNCTION: LEGO1 0x10002a40 +void Vector4::SetMatrixProduct(const float* p_vec, const float* p_mat) +{ + m_data[0] = p_vec[0] * p_mat[0] + p_vec[1] * p_mat[4] + p_vec[2] * p_mat[8] + p_vec[3] * p_mat[12]; + m_data[1] = p_vec[0] * p_mat[1] + p_vec[1] * p_mat[5] + p_vec[2] * p_mat[9] + p_vec[4] * p_mat[13]; + m_data[2] = p_vec[0] * p_mat[2] + p_vec[1] * p_mat[6] + p_vec[2] * p_mat[10] + p_vec[4] * p_mat[14]; + m_data[3] = p_vec[0] * p_mat[3] + p_vec[1] * p_mat[7] + p_vec[2] * p_mat[11] + p_vec[4] * p_mat[15]; +} + +// FUNCTION: LEGO1 0x10002ae0 +void Vector4::SetMatrixProduct(const Vector4& p_a, const float* p_b) +{ + SetMatrixProduct(p_a.m_data, p_b); +} + +// FUNCTION: LEGO1 0x10002b00 +void Vector4::Clear() +{ + memset(m_data, 0, sizeof(float) * 4); +} + +// FUNCTION: LEGO1 0x10002b20 +float Vector4::LenSquared() const +{ + return m_data[1] * m_data[1] + m_data[0] * m_data[0] + m_data[2] * m_data[2] + m_data[3] * m_data[3]; +} + +// FUNCTION: LEGO1 0x10002b40 +void Vector4::Fill(const float& p_value) +{ + m_data[0] = p_value; + m_data[1] = p_value; + m_data[2] = p_value; + m_data[3] = p_value; +} + +// FUNCTION: LEGO1 0x10002b70 +// FUNCTION: BETA10 0x10048ad0 +int Vector4::NormalizeQuaternion() +{ + float length = m_data[0] * m_data[0] + m_data[1] * m_data[1] + m_data[2] * m_data[2]; + + if (length > 0.0f) { + float theta = m_data[3] * 0.5f; + float magnitude = sin((double) theta); + m_data[3] = cos((double) theta); + + magnitude = magnitude / (float) sqrt((double) length); + m_data[0] *= magnitude; + m_data[1] *= magnitude; + m_data[2] *= magnitude; + return 0; + } + else { + return -1; + } +} + +// FUNCTION: LEGO1 0x10002bf0 +// FUNCTION: BETA10 0x10048c20 +int Vector4::EqualsHamiltonProduct(const Vector4& p_a, const Vector4& p_b) +{ + m_data[3] = p_a.m_data[3] * p_b.m_data[3] - + (p_a.m_data[0] * p_b.m_data[0] + p_a.m_data[2] * p_b.m_data[2] + p_a.m_data[1] * p_b.m_data[1]); + + Vector3::EqualsCrossImpl(p_a.m_data, p_b.m_data); + + m_data[0] = p_b.m_data[3] * p_a.m_data[0] + p_a.m_data[3] * p_b.m_data[0] + m_data[0]; + m_data[1] = p_b.m_data[1] * p_a.m_data[3] + p_a.m_data[1] * p_b.m_data[3] + m_data[1]; + m_data[2] = p_b.m_data[2] * p_a.m_data[3] + p_a.m_data[2] * p_b.m_data[3] + m_data[2]; + return 0; +} + +#endif // VECTOR4D_H From 2005083f2790c81617f1d62ca9c806ac2a5021ed Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Fri, 3 Jan 2025 11:20:11 -0700 Subject: [PATCH 08/16] Refactor --- LEGO1/realtime/matrix4d.h | 3 +++ LEGO1/realtime/vector.h | 56 +++++++++++++++++---------------------- LEGO1/realtime/vector2d.h | 3 +++ 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/LEGO1/realtime/matrix4d.h b/LEGO1/realtime/matrix4d.h index 506f4e7408..2bf22a85eb 100644 --- a/LEGO1/realtime/matrix4d.h +++ b/LEGO1/realtime/matrix4d.h @@ -3,6 +3,9 @@ #include "matrix.h" +#include +#include + // FUNCTION: LEGO1 0x10002320 // FUNCTION: BETA10 0x1000fcb0 void Matrix4::Equals(float (*p_data)[4]) diff --git a/LEGO1/realtime/vector.h b/LEGO1/realtime/vector.h index 58569d7fb0..adc880fc0c 100644 --- a/LEGO1/realtime/vector.h +++ b/LEGO1/realtime/vector.h @@ -3,9 +3,6 @@ #include "compat.h" -#include -#include - // Note: virtual function overloads appear in the virtual table // in reverse order of appearance. @@ -13,11 +10,6 @@ // VTABLE: BETA10 0x101b8440 // SIZE 0x08 class Vector2 { -public: - // FUNCTION: LEGO1 0x1000c0f0 - // FUNCTION: BETA10 0x100116a0 - Vector2(float* p_data) { SetData(p_data); } - protected: inline virtual void AddImpl(const float* p_value); // vtable+0x04 inline virtual void AddImpl(float p_value); // vtable+0x00 @@ -30,6 +22,10 @@ class Vector2 { inline virtual void EqualsImpl(const float* p_data); // vtable+0x20 public: + // FUNCTION: LEGO1 0x1000c0f0 + // FUNCTION: BETA10 0x100116a0 + Vector2(float* p_data) { SetData(p_data); } + inline virtual float* GetData(); // vtable+0x28 inline virtual const float* GetData() const; // vtable+0x24 inline virtual void Clear(); // vtable+0x2c @@ -94,6 +90,17 @@ class Vector2 { // VTABLE: BETA10 0x101b8398 // SIZE 0x08 class Vector3 : public Vector2 { +protected: + inline void AddImpl(const float* p_value) override; // vtable+0x04 + inline void AddImpl(float p_value) override; // vtable+0x00 + inline void SubImpl(const float* p_value) override; // vtable+0x08 + inline void MulImpl(const float* p_value) override; // vtable+0x10 + inline void MulImpl(const float& p_value) override; // vtable+0x0c + inline void DivImpl(const float& p_value) override; // vtable+0x14 + inline float DotImpl(const float* p_a, const float* p_b) const override; // vtable+0x18 + inline void EqualsImpl(const float* p_data) override; // vtable+0x20 + inline virtual void EqualsCrossImpl(const float* p_a, const float* p_b); // vtable+0x74 + public: // FUNCTION: LEGO1 0x1001d150 // FUNCTION: BETA10 0x10011660 @@ -107,18 +114,6 @@ class Vector3 : public Vector2 { // FUNCTION: BETA10 0x100109a0 Vector3(const float* p_data) : Vector2((float*) p_data) {} -protected: - inline void AddImpl(const float* p_value) override; // vtable+0x04 - inline void AddImpl(float p_value) override; // vtable+0x00 - inline void SubImpl(const float* p_value) override; // vtable+0x08 - inline void MulImpl(const float* p_value) override; // vtable+0x10 - inline void MulImpl(const float& p_value) override; // vtable+0x0c - inline void DivImpl(const float& p_value) override; // vtable+0x14 - inline float DotImpl(const float* p_a, const float* p_b) const override; // vtable+0x18 - inline void EqualsImpl(const float* p_data) override; // vtable+0x20 - inline virtual void EqualsCrossImpl(const float* p_a, const float* p_b); // vtable+0x74 - -public: inline void Clear() override; // vtable+0x2c inline float LenSquared() const override; // vtable+0x40 inline virtual void EqualsCross(const Vector3& p_a, const Vector3& p_b); // vtable+0x80 @@ -133,6 +128,16 @@ class Vector3 : public Vector2 { // VTABLE: BETA10 0x101bac38 // SIZE 0x08 class Vector4 : public Vector3 { +protected: + inline void AddImpl(const float* p_value) override; // vtable+0x04 + inline void AddImpl(float p_value) override; // vtable+0x00 + inline void SubImpl(const float* p_value) override; // vtable+0x08 + inline void MulImpl(const float* p_value) override; // vtable+0x10 + inline void MulImpl(const float& p_value) override; // vtable+0x0c + inline void DivImpl(const float& p_value) override; // vtable+0x14 + inline float DotImpl(const float* p_a, const float* p_b) const override; // vtable+0x18 + inline void EqualsImpl(const float* p_data) override; // vtable+0x20 + public: // FUNCTION: BETA10 0x10048780 inline Vector4(float* p_data) : Vector3(p_data) {} @@ -147,17 +152,6 @@ class Vector4 : public Vector3 { // FUNCTION: BETA10 0x100701b0 inline Vector4(const float* p_data) : Vector3((float*) p_data) {} -protected: - inline void AddImpl(const float* p_value) override; // vtable+0x04 - inline void AddImpl(float p_value) override; // vtable+0x00 - inline void SubImpl(const float* p_value) override; // vtable+0x08 - inline void MulImpl(const float* p_value) override; // vtable+0x10 - inline void MulImpl(const float& p_value) override; // vtable+0x0c - inline void DivImpl(const float& p_value) override; // vtable+0x14 - inline float DotImpl(const float* p_a, const float* p_b) const override; // vtable+0x18 - inline void EqualsImpl(const float* p_data) override; // vtable+0x20 - -public: inline void Clear() override; // vtable+0x2c inline float LenSquared() const override; // vtable+0x40 inline void Fill(const float& p_value) override; // vtable+0x84 diff --git a/LEGO1/realtime/vector2d.h b/LEGO1/realtime/vector2d.h index c998f35682..d80e767ca6 100644 --- a/LEGO1/realtime/vector2d.h +++ b/LEGO1/realtime/vector2d.h @@ -4,6 +4,9 @@ #include "vector.h" +#include +#include + // FUNCTION: LEGO1 0x10001f80 void Vector2::AddImpl(const float* p_value) { From a885c3fab35af29ecbe8311ca6ecc85d13f5dabd Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Fri, 3 Jan 2025 11:23:34 -0700 Subject: [PATCH 09/16] Refactor --- LEGO1/realtime/matrix.h | 6 +++--- LEGO1/realtime/vector.h | 5 ++--- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/LEGO1/realtime/matrix.h b/LEGO1/realtime/matrix.h index 816d86cb60..c792f4da52 100644 --- a/LEGO1/realtime/matrix.h +++ b/LEGO1/realtime/matrix.h @@ -14,6 +14,9 @@ struct UnknownMatrixType { // VTABLE: BETA10 0x101b8340 // SIZE 0x08 class Matrix4 { +protected: + float (*m_data)[4]; + public: // FUNCTION: LEGO1 0x10004500 // FUNCTION: BETA10 0x1000fc70 @@ -47,9 +50,6 @@ class Matrix4 { float* operator[](int idx) { return m_data[idx]; } const float* operator[](int idx) const { return m_data[idx]; } - -protected: - float (*m_data)[4]; }; #endif // MATRIX_H diff --git a/LEGO1/realtime/vector.h b/LEGO1/realtime/vector.h index adc880fc0c..8b6a72306a 100644 --- a/LEGO1/realtime/vector.h +++ b/LEGO1/realtime/vector.h @@ -21,6 +21,8 @@ class Vector2 { inline virtual void SetData(float* p_data); // vtable+0x1c inline virtual void EqualsImpl(const float* p_data); // vtable+0x20 + float* m_data; // 0x04 + public: // FUNCTION: LEGO1 0x1000c0f0 // FUNCTION: BETA10 0x100116a0 @@ -81,9 +83,6 @@ class Vector2 { // FUNCTION: BETA10 0x1001d170 const float& operator[](int idx) const { return m_data[idx]; } - -protected: - float* m_data; // 0x04 }; // VTABLE: LEGO1 0x100d4518 From 3ac775d9708fd9181f37c9c82df59207a3f27a67 Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Fri, 3 Jan 2025 11:43:20 -0700 Subject: [PATCH 10/16] Fix operators --- LEGO1/realtime/vector.h | 26 ++------------------------ LEGO1/realtime/vector2d.h | 4 ++-- 2 files changed, 4 insertions(+), 26 deletions(-) diff --git a/LEGO1/realtime/vector.h b/LEGO1/realtime/vector.h index 8b6a72306a..2fbe5ddc37 100644 --- a/LEGO1/realtime/vector.h +++ b/LEGO1/realtime/vector.h @@ -46,24 +46,8 @@ class Vector2 { inline virtual void operator*=(const Vector2& p_other); // vtable+0x60 inline virtual void operator*=(const float& p_value); // vtable+0x5c inline virtual void operator/=(const float& p_value); // vtable+0x68 - inline virtual void SetVector(const float* p_other); // vtable+0x70 - inline virtual void SetVector(const Vector2& p_other); // vtable+0x6c - - // Note: it's unclear whether Vector3::operator= has been defined explicitly - // with the same function body as Vector2& operator=. The BETA indicates that; - // however, it makes LEGO1 0x10010be0 disappear and worsens matches in - // at least these functions: - // LEGO1 0x100109b0 - // LEGO1 0x10023130 - // LEGO1 0x1002de10 - // LEGO1 0x10050a80 - // LEGO1 0x10053980 - // LEGO1 0x100648f0 - // LEGO1 0x10064b50 - // LEGO1 0x10084030 - // LEGO1 0x100a9410 - // However, defining it as in the BETA improves at least these functions: - // LEGO1 0x10042300 + inline virtual void operator=(const float* p_other); // vtable+0x70 + inline virtual void operator=(const Vector2& p_other); // vtable+0x6c // SYNTHETIC: LEGO1 0x10010be0 // SYNTHETIC: BETA10 0x100121e0 @@ -72,12 +56,6 @@ class Vector2 { // SYNTHETIC: BETA10 0x1004af40 // Vector4::operator= - Vector2& operator=(const Vector2& p_other) - { - Vector2::SetVector(p_other); - return *this; - } - // FUNCTION: BETA10 0x1001d140 float& operator[](int idx) { return m_data[idx]; } diff --git a/LEGO1/realtime/vector2d.h b/LEGO1/realtime/vector2d.h index d80e767ca6..d3b5316d83 100644 --- a/LEGO1/realtime/vector2d.h +++ b/LEGO1/realtime/vector2d.h @@ -189,14 +189,14 @@ void Vector2::operator/=(const float& p_value) } // FUNCTION: LEGO1 0x10002250 -void Vector2::SetVector(const float* p_other) +void Vector2::operator=(const float* p_other) { EqualsImpl(p_other); } // FUNCTION: LEGO1 0x10002260 // FUNCTION: BETA10 0x100110c0 -void Vector2::SetVector(const Vector2& p_other) +void Vector2::operator=(const Vector2& p_other) { EqualsImpl(p_other.m_data); } From 686d9ba136f9dbf140b9141d11dad167b6a0dad4 Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Fri, 3 Jan 2025 11:47:14 -0700 Subject: [PATCH 11/16] Remove obsolete inline keyword --- LEGO1/realtime/vector.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/LEGO1/realtime/vector.h b/LEGO1/realtime/vector.h index 2fbe5ddc37..e087e24d0e 100644 --- a/LEGO1/realtime/vector.h +++ b/LEGO1/realtime/vector.h @@ -117,7 +117,7 @@ class Vector4 : public Vector3 { public: // FUNCTION: BETA10 0x10048780 - inline Vector4(float* p_data) : Vector3(p_data) {} + Vector4(float* p_data) : Vector3(p_data) {} // Some code initializes a Vector4 from a `const float*` source. // Example: `LegoCarBuild::VTable0x6c` @@ -127,7 +127,7 @@ class Vector4 : public Vector3 { // supporting the theory that this decompilation is correct. // FUNCTION: BETA10 0x100701b0 - inline Vector4(const float* p_data) : Vector3((float*) p_data) {} + Vector4(const float* p_data) : Vector3((float*) p_data) {} inline void Clear() override; // vtable+0x2c inline float LenSquared() const override; // vtable+0x40 From 3ecdb5480a95b453a47d591edfb542e2965c9e77 Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Fri, 3 Jan 2025 11:59:59 -0700 Subject: [PATCH 12/16] Fix ctors --- LEGO1/realtime/vector.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/LEGO1/realtime/vector.h b/LEGO1/realtime/vector.h index e087e24d0e..defaab5730 100644 --- a/LEGO1/realtime/vector.h +++ b/LEGO1/realtime/vector.h @@ -28,6 +28,9 @@ class Vector2 { // FUNCTION: BETA10 0x100116a0 Vector2(float* p_data) { SetData(p_data); } + // FUNCTION: BETA10 0x100109e0 + Vector2(const float* p_data) { m_data = (float*) p_data; } + inline virtual float* GetData(); // vtable+0x28 inline virtual const float* GetData() const; // vtable+0x24 inline virtual void Clear(); // vtable+0x2c @@ -89,7 +92,7 @@ class Vector3 : public Vector2 { // initialization with a const source fundamentally incompatible. // FUNCTION: BETA10 0x100109a0 - Vector3(const float* p_data) : Vector2((float*) p_data) {} + Vector3(const float* p_data) : Vector2(p_data) {} inline void Clear() override; // vtable+0x2c inline float LenSquared() const override; // vtable+0x40 @@ -127,7 +130,7 @@ class Vector4 : public Vector3 { // supporting the theory that this decompilation is correct. // FUNCTION: BETA10 0x100701b0 - Vector4(const float* p_data) : Vector3((float*) p_data) {} + Vector4(const float* p_data) : Vector3(p_data) {} inline void Clear() override; // vtable+0x2c inline float LenSquared() const override; // vtable+0x40 From 60bc264bff0b7ce09f4f42dc54f1c43bd4677da1 Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Fri, 3 Jan 2025 12:14:30 -0700 Subject: [PATCH 13/16] Refactor --- LEGO1/lego/legoomni/src/actors/helicopter.cpp | 2 +- .../lego/legoomni/src/build/legocarbuild.cpp | 2 +- .../src/common/legoanimationmanager.cpp | 2 +- LEGO1/mxgeometry/mxquaternion.h | 244 +++++++++--------- 4 files changed, 130 insertions(+), 120 deletions(-) diff --git a/LEGO1/lego/legoomni/src/actors/helicopter.cpp b/LEGO1/lego/legoomni/src/actors/helicopter.cpp index e9ede61b12..7751a828e5 100644 --- a/LEGO1/lego/legoomni/src/actors/helicopter.cpp +++ b/LEGO1/lego/legoomni/src/actors/helicopter.cpp @@ -482,7 +482,7 @@ void Helicopter::FUN_100042a0(const Matrix4& p_matrix) m_unk0x1f0 = Timer()->GetTime(); - m_unk0x1f4.Set(local48, local90); + m_unk0x1f4.SetStartEnd(local48, local90); m_unk0x1f4.NormalizeDirection(); } diff --git a/LEGO1/lego/legoomni/src/build/legocarbuild.cpp b/LEGO1/lego/legoomni/src/build/legocarbuild.cpp index 2b75e91d86..2187a4c204 100644 --- a/LEGO1/lego/legoomni/src/build/legocarbuild.cpp +++ b/LEGO1/lego/legoomni/src/build/legocarbuild.cpp @@ -358,7 +358,7 @@ void LegoCarBuild::VTable0x70() m_unk0x2a0 = sqrt((MxDouble) DISTSQRD2(m_unk0x290, m_unk0x298)); - m_unk0x25c.Set(m_unk0x178, m_unk0x208); + m_unk0x25c.SetStartEnd(m_unk0x178, m_unk0x208); } // FUNCTION: LEGO1 0x10023130 diff --git a/LEGO1/lego/legoomni/src/common/legoanimationmanager.cpp b/LEGO1/lego/legoomni/src/common/legoanimationmanager.cpp index 6ea3e3faa7..aa1a6b4097 100644 --- a/LEGO1/lego/legoomni/src/common/legoanimationmanager.cpp +++ b/LEGO1/lego/legoomni/src/common/legoanimationmanager.cpp @@ -2797,7 +2797,7 @@ void LegoAnimationManager::FUN_100648f0(LegoTranInfo* p_tranInfo, MxLong p_unk0x LegoLocation* location = NavController()->GetLocation(p_tranInfo->m_location); if (location != NULL) { CalcLocalTransform(location->m_position, location->m_direction, location->m_up, m_unk0x484); - m_unk0x4cc.Set(m_unk0x43c, m_unk0x484); + m_unk0x4cc.SetStartEnd(m_unk0x43c, m_unk0x484); m_unk0x4cc.NormalizeDirection(); } else { diff --git a/LEGO1/mxgeometry/mxquaternion.h b/LEGO1/mxgeometry/mxquaternion.h index 2738eda836..a5fb006b9c 100644 --- a/LEGO1/mxgeometry/mxquaternion.h +++ b/LEGO1/mxgeometry/mxquaternion.h @@ -7,149 +7,159 @@ class MxQuaternionTransformer { public: enum { - c_startInit = 0x01, - c_endInit = 0x02 + c_startSet = 0x01, + c_endSet = 0x02 }; MxQuaternionTransformer() : m_flags(0) {} - // FUNCTION: LEGO1 0x10004520 - inline long NormalizeDirection() - { - if (!m_flags) { - return -1; - } - - Mx4DPointFloat v1; - Mx4DPointFloat v2; + inline long NormalizeDirection(); + inline void SetStartEnd(Matrix4& p_m1, Matrix4& p_m2); + inline void SetStart(Matrix4& p_m); + inline void SetEnd(Matrix4& p_m); + inline void SetStart(Vector4& p_v); + inline void SetEnd(Vector4& p_v); + inline int InterpolateToMatrix(Matrix4& p_matrix, float p_f); - v1 = m_startQuat; - v1 += m_endQuat; + const Vector4& GetStartQuat() const { return m_startQuat; } + const Vector4& GetEndQuat() const { return m_endQuat; } + undefined4 GetFlags() const { return m_flags; } - v2 = m_startQuat; - v2 -= m_endQuat; +private: + inline int Interpolate(Vector4& p_v, float p_f); - if (v1.Dot(v1, v1) < v2.Dot(v2, v2)) { - m_endQuat *= -1.0f; - } + Mx4DPointFloat m_startQuat; // 0x00 + Mx4DPointFloat m_endQuat; // 0x18 + MxU32 m_flags; // 0x30 +}; - return 0; +// FUNCTION: LEGO1 0x10004520 +long MxQuaternionTransformer::NormalizeDirection() +{ + if (!m_flags) { + return -1; } - // FUNCTION: BETA10 0x1004a9b0 - void Set(Matrix4& p_m1, Matrix4& p_m2) - { - SetStart(p_m1); - SetEnd(p_m2); - } + Mx4DPointFloat v1; + Mx4DPointFloat v2; - // FUNCTION: BETA10 0x1004a9f0 - void SetStart(Matrix4& p_m) - { - p_m.ToQuaternion(m_startQuat); - m_flags |= c_startInit; - } + v1 = m_startQuat; + v1 += m_endQuat; - // FUNCTION: LEGO1 0x10004620 - // FUNCTION: BETA10 0x1004aa30 - void SetEnd(Matrix4& p_m) - { - p_m.ToQuaternion(m_endQuat); - m_flags |= c_endInit; - } + v2 = m_startQuat; + v2 -= m_endQuat; - // FUNCTION: BETA10 0x10180b80 - void SetStart(Vector4& p_v) - { - m_startQuat = p_v; - m_flags |= c_startInit; + if (v1.Dot(v1, v1) < v2.Dot(v2, v2)) { + m_endQuat *= -1.0f; } - // FUNCTION: BETA10 0x10180bc0 - void SetEnd(Vector4& p_v) - { - m_endQuat = p_v; - m_flags |= c_endInit; + return 0; +} + +// FUNCTION: BETA10 0x1004a9b0 +void MxQuaternionTransformer::SetStartEnd(Matrix4& p_m1, Matrix4& p_m2) +{ + SetStart(p_m1); + SetEnd(p_m2); +} + +// FUNCTION: BETA10 0x1004a9f0 +void MxQuaternionTransformer::SetStart(Matrix4& p_m) +{ + p_m.ToQuaternion(m_startQuat); + m_flags |= c_startSet; +} + +// FUNCTION: LEGO1 0x10004620 +// FUNCTION: BETA10 0x1004aa30 +void MxQuaternionTransformer::SetEnd(Matrix4& p_m) +{ + p_m.ToQuaternion(m_endQuat); + m_flags |= c_endSet; +} + +// FUNCTION: BETA10 0x10180b80 +void MxQuaternionTransformer::SetStart(Vector4& p_v) +{ + m_startQuat = p_v; + m_flags |= c_startSet; +} + +// FUNCTION: BETA10 0x10180bc0 +void MxQuaternionTransformer::SetEnd(Vector4& p_v) +{ + m_endQuat = p_v; + m_flags |= c_endSet; +} + +// FUNCTION: BETA10 0x1004aaa0 +int MxQuaternionTransformer::InterpolateToMatrix(Matrix4& p_matrix, float p_f) +{ + float data[4]; + Vector4 v(data); + + if (Interpolate(v, p_f) == 0) { + return p_matrix.FromQuaternion(v); } - const Vector4& GetStartQuat() const { return m_startQuat; } - const Vector4& GetEndQuat() const { return m_endQuat; } - undefined4 GetFlags() const { return m_flags; } - - // FUNCTION: BETA10 0x1004aaa0 - inline int InterpolateToMatrix(Matrix4& p_matrix, float p_f) - { - float data[4]; - Vector4 v(data); - - if (Interpolate(v, p_f) == 0) { - return p_matrix.FromQuaternion(v); - } - - return -1; + return -1; +} + +// FUNCTION: LEGO1 0x100040a0 +// FUNCTION: BETA10 0x1004ab10 +int MxQuaternionTransformer::Interpolate(Vector4& p_v, float p_f) +{ + if (m_flags == c_startSet) { + p_v = m_startQuat; + p_v[3] = (float) ((1.0 - p_f) * acos((double) p_v[3]) * 2.0); + return p_v.NormalizeQuaternion(); } -private: - // FUNCTION: LEGO1 0x100040a0 - // FUNCTION: BETA10 0x1004ab10 - inline int Interpolate(Vector4& p_v, float p_f) - { - if (m_flags == c_startInit) { - p_v = m_startQuat; - p_v[3] = (float) ((1.0 - p_f) * acos((double) p_v[3]) * 2.0); - return p_v.NormalizeQuaternion(); - } - - if (m_flags == c_endInit) { - p_v = m_endQuat; - p_v[3] = (float) (p_f * acos((double) p_v[3]) * 2.0); - return p_v.NormalizeQuaternion(); - } + if (m_flags == c_endSet) { + p_v = m_endQuat; + p_v[3] = (float) (p_f * acos((double) p_v[3]) * 2.0); + return p_v.NormalizeQuaternion(); + } - if (m_flags == (c_startInit | c_endInit)) { - int i; - double d1 = p_v.Dot(m_startQuat, m_endQuat); - double a; - double b; - - if (d1 + 1.0 > 0.00001) { - if (1.0 - d1 > 0.00001) { - double d2 = acos(d1); - double denominator = sin(d2); - a = sin((1.0 - p_f) * d2) / denominator; - b = sin(p_f * d2) / denominator; - } - else { - a = 1.0 - p_f; - b = p_f; - } - - for (i = 0; i < 4; i++) { - p_v[i] = (float) (m_startQuat[i] * a + m_endQuat[i] * b); - } + if (m_flags == (c_startSet | c_endSet)) { + int i; + double d1 = p_v.Dot(m_startQuat, m_endQuat); + double a; + double b; + + if (d1 + 1.0 > 0.00001) { + if (1.0 - d1 > 0.00001) { + double d2 = acos(d1); + double denominator = sin(d2); + a = sin((1.0 - p_f) * d2) / denominator; + b = sin(p_f * d2) / denominator; } else { - p_v[0] = -m_startQuat[1]; - p_v[1] = m_startQuat[0]; - p_v[2] = -m_startQuat[3]; - p_v[3] = m_startQuat[2]; - a = sin((1.0 - p_f) * 1.570796326794895); - b = sin(p_f * 1.570796326794895); - - for (i = 0; i < 3; i++) { - p_v[i] = (float) (m_startQuat[i] * a + p_v[i] * b); - } + a = 1.0 - p_f; + b = p_f; } - return 0; + for (i = 0; i < 4; i++) { + p_v[i] = (float) (m_startQuat[i] * a + m_endQuat[i] * b); + } + } + else { + p_v[0] = -m_startQuat[1]; + p_v[1] = m_startQuat[0]; + p_v[2] = -m_startQuat[3]; + p_v[3] = m_startQuat[2]; + a = sin((1.0 - p_f) * 1.570796326794895); + b = sin(p_f * 1.570796326794895); + + for (i = 0; i < 3; i++) { + p_v[i] = (float) (m_startQuat[i] * a + p_v[i] * b); + } } - return -1; + return 0; } - Mx4DPointFloat m_startQuat; // 0x00 - Mx4DPointFloat m_endQuat; // 0x18 - MxU32 m_flags; // 0x30 -}; + return -1; +} -#endif // MXQUATERION_H +#endif // MXQUATERNION_H From f7d13683d0d369428bebc9e8c90f3df4851c7e23 Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Fri, 3 Jan 2025 12:21:55 -0700 Subject: [PATCH 14/16] Rename files --- LEGO1/mxgeometry/mxgeometry3d.h | 4 ++-- LEGO1/mxgeometry/mxgeometry4d.h | 4 ++-- LEGO1/mxgeometry/mxmatrix.h | 4 ++-- LEGO1/realtime/{matrix4d.h => matrix4d.inl.h} | 0 LEGO1/realtime/{vector2d.h => vector2d.inl.h} | 0 LEGO1/realtime/{vector3d.h => vector3d.inl.h} | 2 +- LEGO1/realtime/{vector4d.h => vector4d.inl.h} | 0 7 files changed, 7 insertions(+), 7 deletions(-) rename LEGO1/realtime/{matrix4d.h => matrix4d.inl.h} (100%) rename LEGO1/realtime/{vector2d.h => vector2d.inl.h} (100%) rename LEGO1/realtime/{vector3d.h => vector3d.inl.h} (98%) rename LEGO1/realtime/{vector4d.h => vector4d.inl.h} (100%) diff --git a/LEGO1/mxgeometry/mxgeometry3d.h b/LEGO1/mxgeometry/mxgeometry3d.h index f8fd3a03ed..209eb1d415 100644 --- a/LEGO1/mxgeometry/mxgeometry3d.h +++ b/LEGO1/mxgeometry/mxgeometry3d.h @@ -3,8 +3,8 @@ #include "decomp.h" #include "realtime/vector.h" -#include "realtime/vector2d.h" -#include "realtime/vector3d.h" +#include "realtime/vector2d.inl.h" +#include "realtime/vector3d.inl.h" // VTABLE: LEGO1 0x100d4488 // VTABLE: BETA10 0x101b84d0 diff --git a/LEGO1/mxgeometry/mxgeometry4d.h b/LEGO1/mxgeometry/mxgeometry4d.h index 44102427ce..591b2babf3 100644 --- a/LEGO1/mxgeometry/mxgeometry4d.h +++ b/LEGO1/mxgeometry/mxgeometry4d.h @@ -3,8 +3,8 @@ #include "decomp.h" #include "realtime/matrix.h" -#include "realtime/matrix4d.h" -#include "realtime/vector4d.h" +#include "realtime/matrix4d.inl.h" +#include "realtime/vector4d.inl.h" // VTABLE: LEGO1 0x100d41e8 // VTABLE: BETA10 0x101bab78 diff --git a/LEGO1/mxgeometry/mxmatrix.h b/LEGO1/mxgeometry/mxmatrix.h index 6b5b928411..929dc3c605 100644 --- a/LEGO1/mxgeometry/mxmatrix.h +++ b/LEGO1/mxgeometry/mxmatrix.h @@ -2,7 +2,7 @@ #define MXMATRIX_H #include "realtime/matrix.h" -#include "realtime/matrix4d.h" +#include "realtime/matrix4d.inl.h" // VTABLE: LEGO1 0x100d4300 // VTABLE: BETA10 0x101b82e0 @@ -37,6 +37,6 @@ class MxMatrix : public Matrix4 { }; // Must be included here for correct ordering in binary -#include "realtime/vector4d.h" +#include "realtime/vector4d.inl.h" #endif // MXMATRIX_H diff --git a/LEGO1/realtime/matrix4d.h b/LEGO1/realtime/matrix4d.inl.h similarity index 100% rename from LEGO1/realtime/matrix4d.h rename to LEGO1/realtime/matrix4d.inl.h diff --git a/LEGO1/realtime/vector2d.h b/LEGO1/realtime/vector2d.inl.h similarity index 100% rename from LEGO1/realtime/vector2d.h rename to LEGO1/realtime/vector2d.inl.h diff --git a/LEGO1/realtime/vector3d.h b/LEGO1/realtime/vector3d.inl.h similarity index 98% rename from LEGO1/realtime/vector3d.h rename to LEGO1/realtime/vector3d.inl.h index 28a7cd2632..bf3157b570 100644 --- a/LEGO1/realtime/vector3d.h +++ b/LEGO1/realtime/vector3d.inl.h @@ -2,7 +2,7 @@ #define VECTOR3D_H #include "vector.h" -#include "vector2d.h" +#include "vector2d.inl.h" // FUNCTION: LEGO1 0x10002270 // FUNCTION: BETA10 0x10011350 diff --git a/LEGO1/realtime/vector4d.h b/LEGO1/realtime/vector4d.inl.h similarity index 100% rename from LEGO1/realtime/vector4d.h rename to LEGO1/realtime/vector4d.inl.h From 73a5b549a60500747c714d799114937ee3b1312b Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Fri, 3 Jan 2025 12:27:38 -0700 Subject: [PATCH 15/16] Refactor --- LEGO1/mxgeometry/mxgeometry3d.h | 2 -- LEGO1/mxgeometry/mxgeometry4d.h | 2 -- LEGO1/mxgeometry/mxmatrix.h | 5 +++-- LEGO1/realtime/vector3d.inl.h | 1 - 4 files changed, 3 insertions(+), 7 deletions(-) diff --git a/LEGO1/mxgeometry/mxgeometry3d.h b/LEGO1/mxgeometry/mxgeometry3d.h index 209eb1d415..578d31b229 100644 --- a/LEGO1/mxgeometry/mxgeometry3d.h +++ b/LEGO1/mxgeometry/mxgeometry3d.h @@ -2,8 +2,6 @@ #define MXGEOMETRY3D_H #include "decomp.h" -#include "realtime/vector.h" -#include "realtime/vector2d.inl.h" #include "realtime/vector3d.inl.h" // VTABLE: LEGO1 0x100d4488 diff --git a/LEGO1/mxgeometry/mxgeometry4d.h b/LEGO1/mxgeometry/mxgeometry4d.h index 591b2babf3..4ebeeb5a53 100644 --- a/LEGO1/mxgeometry/mxgeometry4d.h +++ b/LEGO1/mxgeometry/mxgeometry4d.h @@ -2,8 +2,6 @@ #define MXGEOMETRY4D_H #include "decomp.h" -#include "realtime/matrix.h" -#include "realtime/matrix4d.inl.h" #include "realtime/vector4d.inl.h" // VTABLE: LEGO1 0x100d41e8 diff --git a/LEGO1/mxgeometry/mxmatrix.h b/LEGO1/mxgeometry/mxmatrix.h index 929dc3c605..a31a5d4efb 100644 --- a/LEGO1/mxgeometry/mxmatrix.h +++ b/LEGO1/mxgeometry/mxmatrix.h @@ -1,7 +1,6 @@ #ifndef MXMATRIX_H #define MXMATRIX_H -#include "realtime/matrix.h" #include "realtime/matrix4d.inl.h" // VTABLE: LEGO1 0x100d4300 @@ -36,7 +35,9 @@ class MxMatrix : public Matrix4 { float m_elements[4][4]; // 0x08 }; -// Must be included here for correct ordering in binary +// Must be included here (not before MxMatrix) for correct ordering in binary. +// FromQuaternion and ToQuaternion in Matrix4 depend on Vector4. +// There's a chance they included mxgeometry4d.h after including this somewhere. #include "realtime/vector4d.inl.h" #endif // MXMATRIX_H diff --git a/LEGO1/realtime/vector3d.inl.h b/LEGO1/realtime/vector3d.inl.h index bf3157b570..517b777fe9 100644 --- a/LEGO1/realtime/vector3d.inl.h +++ b/LEGO1/realtime/vector3d.inl.h @@ -1,7 +1,6 @@ #ifndef VECTOR3D_H #define VECTOR3D_H -#include "vector.h" #include "vector2d.inl.h" // FUNCTION: LEGO1 0x10002270 From e6d3ac96fa5a2847d8ac85fc259297e3b98a2e39 Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Fri, 3 Jan 2025 12:51:20 -0700 Subject: [PATCH 16/16] Remove empty line --- LEGO1/realtime/vector2d.inl.h | 1 - 1 file changed, 1 deletion(-) diff --git a/LEGO1/realtime/vector2d.inl.h b/LEGO1/realtime/vector2d.inl.h index d3b5316d83..95e7ea7d61 100644 --- a/LEGO1/realtime/vector2d.inl.h +++ b/LEGO1/realtime/vector2d.inl.h @@ -1,4 +1,3 @@ - #ifndef VECTOR2D_H #define VECTOR2D_H