Implement LegoAnimNodeData::GetRotation (#661)

* WIP

* Improve matches
This commit is contained in:
Christian Semmler
2024-03-12 13:21:58 -04:00
committed by GitHub
parent e3d7188ec9
commit 02838d0f57
7 changed files with 208 additions and 85 deletions

View File

@@ -5,18 +5,6 @@
#include "islepathactor.h"
#include "realtime/matrix.h"
// SIZE 0x34
class HelicopterSubclass {
public:
inline HelicopterSubclass() : m_unk0x30(0) {}
MxResult FUN_100040a0(Vector4& p_v, float p_f);
private:
Mx4DPointFloat m_unk0x00; // 0x00
Mx4DPointFloat m_unk0x18; // 0x18
undefined4 m_unk0x30; // 0x30
};
// VTABLE: LEGO1 0x100d40f8
// SIZE 0x230
class Helicopter : public IslePathActor {
@@ -49,12 +37,12 @@ public:
// Helicopter::`scalar deleting destructor'
protected:
MxMatrix m_unk0x160; // 0x160
MxMatrix m_unk0x1a8; // 0x1a8
float m_unk0x1f0; // 0x1f0
HelicopterSubclass m_unk0x1f4; // 0x1f4
HelicopterState* m_state; // 0x228
MxAtomId m_script; // 0x22c
MxMatrix m_unk0x160; // 0x160
MxMatrix m_unk0x1a8; // 0x1a8
float m_unk0x1f0; // 0x1f0
UnknownMx4DPointFloat m_unk0x1f4; // 0x1f4
HelicopterState* m_state; // 0x228
MxAtomId m_script; // 0x22c
private:
void GetState();

View File

@@ -366,51 +366,3 @@ void Helicopter::VTable0x70(float p_float)
}
}
}
// FUNCTION: LEGO1 0x100040a0
MxResult HelicopterSubclass::FUN_100040a0(Vector4& p_v, float p_f)
{
MxU32 state = m_unk0x30;
if (state == 1) {
p_v.EqualsImpl(m_unk0x00.GetData());
p_v[3] = acos(p_v[3]) * (1 - p_f) * 2.0;
return p_v.NormalizeQuaternion();
}
else if (state == 2) {
p_v.EqualsImpl(m_unk0x18.GetData());
p_v[3] = acos(p_v[3]) * p_f * 2.0;
return p_v.NormalizeQuaternion();
}
else if (state == 3) {
double d1 = p_v.Dot(&m_unk0x00, &m_unk0x18), d2;
if (d1 + 1 > 0.00001) {
if (1 - d1 > 0.00001) {
double d = acos(d1);
sin(d);
d1 = sin((1 - p_f) * d) / sin(d);
d2 = sin(p_f * d) / sin(d);
}
else {
d1 = 1 - p_f;
d2 = p_f;
}
for (MxS32 i = 0; i < 4; i++) {
p_v[i] = m_unk0x18[i] * d2 + m_unk0x00[i] * d1;
}
return SUCCESS;
}
p_v[0] = -m_unk0x00[1];
p_v[1] = m_unk0x00[1];
p_v[2] = -m_unk0x00[3];
p_v[3] = m_unk0x00[2];
d1 = sin((1 - p_f) * 1.570796326794895);
d2 = sin(p_f * 1.570796326794895);
for (MxS32 i = 0; i < 3; i++) {
p_v[i] = m_unk0x00[i] * d1 + p_v[i] * d2;
}
return SUCCESS;
}
else {
return FAILURE;
}
}

View File

@@ -449,7 +449,7 @@ LegoResult LegoAnimNodeData::CreateLocalTransform(LegoFloat p_time, Matrix4& p_m
// FUNCTION: LEGO1 0x100a0600
inline void LegoAnimNodeData::GetTranslation(
LegoU32 p_numTranslationKeys,
LegoU16 p_numTranslationKeys,
LegoTranslationKey* p_translationKeys,
LegoFloat p_time,
Matrix4& p_matrix,
@@ -511,20 +511,72 @@ inline void LegoAnimNodeData::GetTranslation(
p_matrix.TranslateBy(&x, &y, &z);
}
// STUB: LEGO1 0x100a06f0
// FUNCTION: LEGO1 0x100a06f0
/*inline*/ void LegoAnimNodeData::GetRotation(
LegoU32 p_numRotationKeys,
LegoU16 p_numRotationKeys,
LegoRotationKey* p_rotationKeys,
LegoFloat p_time,
Matrix4& p_matrix,
LegoU32& p_old_index
)
{
// TODO
LegoU32 i, n;
n = FindKeys(p_time, p_numRotationKeys & USHRT_MAX, p_rotationKeys, sizeof(*p_rotationKeys), i, p_old_index);
switch (n) {
case 0:
return;
case 1:
if (p_rotationKeys[i].TestBit1()) {
p_matrix.FromQuaternion(Mx4DPointFloat(
p_rotationKeys[i].GetX(),
p_rotationKeys[i].GetY(),
p_rotationKeys[i].GetZ(),
p_rotationKeys[i].GetAngle()
));
}
break;
case 2:
Mx4DPointFloat a;
UnknownMx4DPointFloat b;
if (p_rotationKeys[i].TestBit1() || p_rotationKeys[i + 1].TestBit1()) {
a[0] = p_rotationKeys[i].GetX();
a[1] = p_rotationKeys[i].GetY();
a[2] = p_rotationKeys[i].GetZ();
a[3] = p_rotationKeys[i].GetAngle();
if (p_rotationKeys[i + 1].TestBit3()) {
p_matrix.FromQuaternion(a);
return;
}
Mx4DPointFloat c;
if (p_rotationKeys[i + 1].TestBit2()) {
c[0] = -p_rotationKeys[i + 1].GetX();
c[1] = -p_rotationKeys[i + 1].GetY();
c[2] = -p_rotationKeys[i + 1].GetZ();
c[3] = -p_rotationKeys[i + 1].GetAngle();
}
else {
c[0] = p_rotationKeys[i + 1].GetX();
c[1] = p_rotationKeys[i + 1].GetY();
c[2] = p_rotationKeys[i + 1].GetZ();
c[3] = p_rotationKeys[i + 1].GetAngle();
}
b.Unknown1(a);
b.Unknown2(c);
b.Unknown_100040a0(
p_matrix,
(p_time - p_rotationKeys[i].GetTime()) / (p_rotationKeys[i + 1].GetTime() - p_rotationKeys[i].GetTime())
);
}
}
}
inline void LegoAnimNodeData::GetScale(
LegoU32 p_numScaleKeys,
LegoU16 p_numScaleKeys,
LegoScaleKey* p_scaleKeys,
LegoFloat p_time,
Matrix4& p_matrix,

View File

@@ -10,7 +10,9 @@
class LegoAnimKey {
public:
enum Flags {
c_bit1 = 0x01
c_bit1 = 0x01,
c_bit2 = 0x02,
c_bit3 = 0x04
};
LegoAnimKey();
@@ -18,6 +20,8 @@ public:
LegoFloat GetTime() { return m_time; }
void SetTime(LegoFloat p_time) { m_time = p_time; }
LegoU32 TestBit1() { return m_flags & c_bit1; }
LegoU32 TestBit2() { return m_flags & c_bit2; }
LegoU32 TestBit3() { return m_flags & c_bit3; }
protected:
LegoU8 m_flags; // 0x00
@@ -47,6 +51,14 @@ class LegoRotationKey : public LegoAnimKey {
public:
LegoRotationKey();
LegoResult Read(LegoStorage* p_storage);
LegoFloat GetAngle() { return m_angle; }
void SetAngle(LegoFloat p_angle) { m_angle = p_angle; }
LegoFloat GetX() { return m_x; }
void SetX(LegoFloat p_x) { m_x = p_x; }
LegoFloat GetY() { return m_y; }
void SetY(LegoFloat p_y) { m_y = p_y; }
LegoFloat GetZ() { return m_z; }
void SetZ(LegoFloat p_z) { m_z = p_z; }
protected:
LegoFloat m_angle; // 0x08
@@ -121,21 +133,21 @@ public:
LegoBool FUN_100a0990(LegoTime p_time) { return FUN_100a0990((LegoFloat) p_time); }
inline static void GetTranslation(
LegoU32 p_numTranslationKeys,
LegoU16 p_numTranslationKeys,
LegoTranslationKey* p_translationKeys,
LegoFloat p_time,
Matrix4& p_matrix,
LegoU32& p_old_index
);
/*inline*/ static void GetRotation(
LegoU32 p_numRotationKeys,
LegoU16 p_numRotationKeys,
LegoRotationKey* p_rotationKeys,
LegoFloat p_time,
Matrix4& p_matrix,
LegoU32& p_old_index
);
inline static void GetScale(
LegoU32 p_numScaleKeys,
LegoU16 p_numScaleKeys,
LegoScaleKey* p_scaleKeys,
LegoFloat p_time,
Matrix4& p_matrix,