From 123f143514bac3866e823a5401c89531f2982463 Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Sun, 19 Nov 2023 07:45:43 -0500 Subject: [PATCH] Add Vector3/Vector4 to Data vector --- LEGO1/realtime/matrix.h | 8 ++++---- LEGO1/realtime/vector.h | 36 ++++++++++++------------------------ 2 files changed, 16 insertions(+), 28 deletions(-) diff --git a/LEGO1/realtime/matrix.h b/LEGO1/realtime/matrix.h index 602e50ef..e5653650 100644 --- a/LEGO1/realtime/matrix.h +++ b/LEGO1/realtime/matrix.h @@ -65,7 +65,7 @@ class Matrix4Impl { virtual void ToQuaternion(Vector4Impl* p_resultQuat); virtual int FUN_10002710(const Vector3Impl* p_vec); - inline float& operator[](size_t idx) { return (*m_data)[idx >> 2][idx & 3]; } + inline float& operator[](size_t idx) { return ((float*) m_data)[idx]; } protected: Matrix4* m_data; @@ -75,8 +75,8 @@ class Matrix4Impl { // SIZE 0x48 class Matrix4Data : public Matrix4Impl { public: - inline Matrix4Data() : Matrix4Impl(m) {} - inline Matrix4Data(Matrix4Data& p_other) : Matrix4Impl(m) { m = *p_other.m_data; } + inline Matrix4Data() : Matrix4Impl(m_matrix) {} + inline Matrix4Data(Matrix4Data& p_other) : Matrix4Impl(m_matrix) { m_matrix = *p_other.m_data; } inline Matrix4& GetMatrix() { return *m_data; } // No idea why there's another equals. Maybe to some other type like the @@ -84,7 +84,7 @@ class Matrix4Data : public Matrix4Impl { // vtable + 0x44 virtual void operator=(const Matrix4Data& p_other); - Matrix4 m; + Matrix4 m_matrix; }; #endif // MATRIX_H diff --git a/LEGO1/realtime/vector.h b/LEGO1/realtime/vector.h index 4f3fbe60..aaed9556 100644 --- a/LEGO1/realtime/vector.h +++ b/LEGO1/realtime/vector.h @@ -186,43 +186,31 @@ class Vector4Impl : public Vector3Impl { // SIZE 0x14 class Vector3Data : public Vector3Impl { public: - inline Vector3Data() : Vector3Impl(storage) {} - inline Vector3Data(float p_x, float p_y, float p_z) : Vector3Impl(storage), x(p_x), y(p_y), z(p_z) {} - - union { - float storage[3]; - struct { - float x; - float y; - float z; - }; - }; + inline Vector3Data() : Vector3Impl(m_vector.elements) {} + inline Vector3Data(float p_x, float p_y, float p_z) : Vector3Impl(m_vector.elements), m_vector(p_x, p_y, p_z) {} void CopyFrom(Vector3Data& p_other) { EqualsImpl(p_other.m_data); - float* dest = this->storage; - float* src = p_other.storage; - for (size_t i = sizeof(storage) / sizeof(float); i > 0; --i) + float* dest = m_vector.elements; + float* src = p_other.m_vector.elements; + for (size_t i = sizeof(m_vector) / sizeof(float); i > 0; --i) *dest++ = *src++; } + +private: + Vector3 m_vector; }; // VTABLE 0x100d41e8 // SIZE 0x18 class Vector4Data : public Vector4Impl { public: - inline Vector4Data() : Vector4Impl(storage) {} - union { - float storage[4]; - struct { - float x; - float y; - float z; - float w; - }; - }; + inline Vector4Data() : Vector4Impl(m_vector.elements) {} + +private: + Vector4 m_vector; }; #endif // VECTOR_H