mirror of
https://github.com/isledecomp/isle.git
synced 2025-10-23 00:14:22 +00:00
Order functions in binary up to the end of Helicopter
; refactor vector/matrix classes (#1309)
* Order experimentation * Revert IslePathActor * Fix order * Fix inlining * Fixes * WIP * WIP * Refactor * Refactor * Fix operators * Remove obsolete inline keyword * Fix ctors * Refactor * Rename files * Refactor * Remove empty line
This commit is contained in:

committed by
GitHub

parent
b8f1364ac7
commit
c54805fde8
@@ -2,8 +2,7 @@
|
||||
#define MXGEOMETRY3D_H
|
||||
|
||||
#include "decomp.h"
|
||||
#include "realtime/matrix.h"
|
||||
#include "realtime/vector.h"
|
||||
#include "realtime/vector3d.inl.h"
|
||||
|
||||
// VTABLE: LEGO1 0x100d4488
|
||||
// VTABLE: BETA10 0x101b84d0
|
||||
@@ -53,199 +52,4 @@ private:
|
||||
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
|
||||
|
48
LEGO1/mxgeometry/mxgeometry4d.h
Normal file
48
LEGO1/mxgeometry/mxgeometry4d.h
Normal file
@@ -0,0 +1,48 @@
|
||||
#ifndef MXGEOMETRY4D_H
|
||||
#define MXGEOMETRY4D_H
|
||||
|
||||
#include "decomp.h"
|
||||
#include "realtime/vector4d.inl.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
|
||||
};
|
||||
|
||||
#endif // MXGEOMETRY4D_H
|
@@ -1,7 +1,7 @@
|
||||
#ifndef MXMATRIX_H
|
||||
#define MXMATRIX_H
|
||||
|
||||
#include "realtime/matrix.h"
|
||||
#include "realtime/matrix4d.inl.h"
|
||||
|
||||
// VTABLE: LEGO1 0x100d4300
|
||||
// VTABLE: BETA10 0x101b82e0
|
||||
@@ -35,4 +35,9 @@ private:
|
||||
float m_elements[4][4]; // 0x08
|
||||
};
|
||||
|
||||
// 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
|
||||
|
165
LEGO1/mxgeometry/mxquaternion.h
Normal file
165
LEGO1/mxgeometry/mxquaternion.h
Normal file
@@ -0,0 +1,165 @@
|
||||
#ifndef MXQUATERNION_H
|
||||
#define MXQUATERNION_H
|
||||
|
||||
#include "mxgeometry4d.h"
|
||||
|
||||
// SIZE 0x34
|
||||
class MxQuaternionTransformer {
|
||||
public:
|
||||
enum {
|
||||
c_startSet = 0x01,
|
||||
c_endSet = 0x02
|
||||
};
|
||||
|
||||
MxQuaternionTransformer() : m_flags(0) {}
|
||||
|
||||
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);
|
||||
|
||||
const Vector4& GetStartQuat() const { return m_startQuat; }
|
||||
const Vector4& GetEndQuat() const { return m_endQuat; }
|
||||
undefined4 GetFlags() const { return m_flags; }
|
||||
|
||||
private:
|
||||
inline int Interpolate(Vector4& p_v, float p_f);
|
||||
|
||||
Mx4DPointFloat m_startQuat; // 0x00
|
||||
Mx4DPointFloat m_endQuat; // 0x18
|
||||
MxU32 m_flags; // 0x30
|
||||
};
|
||||
|
||||
// FUNCTION: LEGO1 0x10004520
|
||||
long MxQuaternionTransformer::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 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);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
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_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 {
|
||||
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;
|
||||
}
|
||||
|
||||
#endif // MXQUATERNION_H
|
Reference in New Issue
Block a user