Improve several functions in vector.h (#1049)

* Improve some functions in vector.h

- Add BETA10 references
- inline some functions based on BETA10
- Identify and improve `Vector4::EqualsHamiltonProduct`

* Fix BETA10 offset

* Fix BETA10 annotation order

---------

Co-authored-by: jonschz <jonschz@users.noreply.github.com>
This commit is contained in:
jonschz 2024-06-30 22:45:10 +02:00 committed by GitHub
parent 4a87c3bc44
commit fb34f86171
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 26 additions and 21 deletions

View file

@ -43,6 +43,7 @@ class Mx3DPointFloat : public Vector3 {
}; };
// VTABLE: LEGO1 0x100d41e8 // VTABLE: LEGO1 0x100d41e8
// VTABLE: BETA10 0x101bab78
// SIZE 0x18 // SIZE 0x18
class Mx4DPointFloat : public Vector4 { class Mx4DPointFloat : public Vector4 {
public: public:

View file

@ -178,7 +178,8 @@ class Vector3 : public Vector2 {
// in reverse order of appearance. // in reverse order of appearance.
// FUNCTION: LEGO1 0x10002270 // FUNCTION: LEGO1 0x10002270
virtual void EqualsCrossImpl(float* p_a, float* p_b) // FUNCTION: BETA10 0x100064a1
inline virtual void EqualsCrossImpl(float* p_a, float* p_b)
{ {
m_data[0] = p_a[1] * p_b[2] - p_a[2] * p_b[1]; 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[1] = p_a[2] * p_b[0] - p_a[0] * p_b[2];
@ -229,7 +230,7 @@ class Vector3 : public Vector2 {
} // vtable+0x08 } // vtable+0x08
// FUNCTION: LEGO1 0x10003b20 // FUNCTION: LEGO1 0x10003b20
void MulScalarImpl(float* p_value) override inline void MulScalarImpl(float* p_value) override
{ {
m_data[0] *= *p_value; m_data[0] *= *p_value;
m_data[1] *= *p_value; m_data[1] *= *p_value;
@ -274,6 +275,7 @@ class Vector3 : public Vector2 {
}; };
// VTABLE: LEGO1 0x100d45a0 // VTABLE: LEGO1 0x100d45a0
// VTABLE: BETA10 0x101bac38
// SIZE 0x08 // SIZE 0x08
class Vector4 : public Vector3 { class Vector4 : public Vector3 {
public: public:
@ -294,8 +296,8 @@ class Vector4 : public Vector3 {
// FUNCTION: LEGO1 0x10002ae0 // FUNCTION: LEGO1 0x10002ae0
virtual void SetMatrixProduct(Vector4* p_a, float* p_b) { SetMatrixProduct(p_a->m_data, p_b); } // vtable+0x88 virtual void SetMatrixProduct(Vector4* p_a, float* p_b) { SetMatrixProduct(p_a->m_data, p_b); } // vtable+0x88
inline virtual int NormalizeQuaternion(); // vtable+0x90 inline virtual int NormalizeQuaternion(); // vtable+0x90
inline virtual void UnknownQuaternionOp(Vector4* p_a, Vector4* p_b); // vtable+0x94 inline virtual int EqualsHamiltonProduct(Vector4* p_a, Vector4* p_b); // vtable+0x94
// Vector3 overrides // Vector3 overrides
@ -383,40 +385,42 @@ class Vector4 : public Vector3 {
friend class Mx4DPointFloat; friend class Mx4DPointFloat;
}; };
// Note close yet, included because I'm at least confident I know what operation // FUNCTION: LEGO1 0x10002b70
// it's trying to do. // FUNCTION: BETA10 0x10048ad0
// STUB: LEGO1 0x10002b70
inline int Vector4::NormalizeQuaternion() inline int Vector4::NormalizeQuaternion()
{ {
float* v = m_data; float* v = m_data;
float magnitude = v[1] * v[1] + v[2] * v[2] + v[0] * v[0]; float magnitude = v[0] * v[0] + v[2] * v[2] + v[1] * v[1];
if (magnitude > 0.0f) { if (magnitude > 0.0f) {
float theta = v[3] * 0.5f; float theta = v[3] * 0.5f;
v[3] = cos(theta); v[3] = cos(theta);
float frac = sin(theta); magnitude = sin(theta) / sqrt(magnitude);
magnitude = frac / sqrt(magnitude); Vector3::MulScalarImpl(&magnitude);
v[0] *= magnitude;
v[1] *= magnitude;
v[2] *= magnitude;
return 0; return 0;
} }
return -1; return -1;
} }
// FUNCTION: LEGO1 0x10002bf0 inline static float QuaternionProductScalarPart(float* bDat, float* aDat)
inline void Vector4::UnknownQuaternionOp(Vector4* p_a, Vector4* p_b)
{ {
float* bDat = p_b->m_data; // We have no indication from the beta that this function exists,
float* aDat = p_a->m_data; // but it helps with the stack layout of Vector4::EqualsHamiltonProduct()
return aDat[3] * bDat[3] - (aDat[0] * bDat[0] + aDat[2] * bDat[2] + aDat[1] * bDat[1]);
}
this->m_data[3] = aDat[3] * bDat[3] - (bDat[0] * aDat[0] + aDat[2] * bDat[2] + aDat[1] * aDat[1]); // FUNCTION: LEGO1 0x10002bf0
this->m_data[0] = bDat[2] * aDat[1] - bDat[1] * aDat[2]; // FUNCTION: BETA10 0x10048c20
this->m_data[1] = aDat[2] * bDat[0] - bDat[2] * aDat[0]; inline int Vector4::EqualsHamiltonProduct(Vector4* p_a, Vector4* p_b)
this->m_data[2] = bDat[1] * aDat[0] - aDat[1] * bDat[0]; {
m_data[3] = QuaternionProductScalarPart(p_a->m_data, p_b->m_data);
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[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[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]; 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 #endif // VECTOR_H