From 495dfbbde7330a2e44c96f9bee029b5dd674665b Mon Sep 17 00:00:00 2001 From: Elijah Thomas Date: Fri, 18 Aug 2023 13:23:11 -0400 Subject: [PATCH] Added egg/math and egg/prim headers --- config/SOUE01/splits.txt | 26 ++++++++++++++++++++++++ configure.py | 7 ++++++- include/lib/egg/math/eggMath.h | 25 +++++++++++++++++++++++ include/lib/egg/math/eggMatrix.h | 26 +++++++++++++++++++++++- include/lib/egg/math/eggQuat.h | 26 ++++++++++++++++++++++++ include/lib/egg/math/eggVector.h | 34 ++++++++++++++++++++++++++++++-- include/lib/egg/prim/eggAssert.h | 23 +++++++++++++++++++++ 7 files changed, 163 insertions(+), 4 deletions(-) create mode 100644 include/lib/egg/math/eggMath.h create mode 100644 include/lib/egg/math/eggQuat.h create mode 100644 include/lib/egg/prim/eggAssert.h diff --git a/config/SOUE01/splits.txt b/config/SOUE01/splits.txt index e1db8c70..9ac489da 100644 --- a/config/SOUE01/splits.txt +++ b/config/SOUE01/splits.txt @@ -145,6 +145,32 @@ lib/egg/core/eggController.cpp: .sdata2 start:0x8057F338 end:0x8057F360 rename:.sdata .bss start:0x80673B40 end:0x80674C00 +lib/egg/math/eggMath.cpp: + .text start:0x8049AB60 end:0x8049AC64 + .sdata2 start:0x8057F360 end:0x8057F368 + +lib/egg/math/eggMatrix.cpp: + .text start:0x8049AC70 end:0x8049B388 + .ctors start:0x804DB990 end:0x804DB994 + .sdata2 start:0x8057F368 end:0x8057F380 + .bss start:0x80674C00 end:0x80674C30 + +lib/egg/math/eggQuat.cpp: + .text start:0x8049B390 end:0x8049BCB4 + .sdata2 start:0x8057F380 end:0x8057F3A8 + +lib/egg/math/eggVector.cpp: + .text start:0x8049BCC0 end:0x8049BF90 + .ctors start:0x804DB994 end:0x804DB998 + .sbss start:0x805767C0 end:0x805767F8 + .sdata2 start:0x8057F3A8 end:0x8057F3B8 + .bss start:0x80674C30 end:0x80674C60 + +lib/egg/prim/eggAssert.cpp: + .text start:0x8049BF90 end:0x8049C5BC + .data start:0x8056EC88 end:0x8056ED00 + .sbss start:0x805767F8 end:0x80576808 + Runtime/__init_cpp_exceptions.cpp: .text start:0x804C71A8 end:0x804C7218 .ctors start:0x804DB640 end:0x804DB644 rename:.ctors$10 diff --git a/configure.py b/configure.py index e481b3aa..bc76fcc7 100644 --- a/configure.py +++ b/configure.py @@ -62,7 +62,12 @@ LIBS = [ ["lib/egg/core/eggXfb.cpp", False], ["lib/egg/core/eggXfbManager.cpp", False], ["lib/egg/core/eggGraphicsFifo.cpp", False], - ["lib/egg/core/eggController.cpp", False], + ["lib/egg/core/eggController.cpp", False], + ["lib/egg/math/eggMath.cpp", False], + ["lib/egg/math/eggMatrix.cpp", False], + ["lib/egg/math/eggQuat.cpp", False], + ["lib/egg/math/eggVector.cpp", False], + ["lib/egg/prim/eggAssert.cpp", False], ], } ] diff --git a/include/lib/egg/math/eggMath.h b/include/lib/egg/math/eggMath.h new file mode 100644 index 00000000..794ee60a --- /dev/null +++ b/include/lib/egg/math/eggMath.h @@ -0,0 +1,25 @@ +#pragma once + +#include + +namespace EGG +{ + +template +class Math { +public: + static T frsqrt(T); + static T sin(T); + static T cos(T); + static T acos(T); + static T atan2(T); +}; + +// f32 impls +// /* 8049ab60 */ Math::frsqrt(f32); +// /* 8049abb0 */ Math::sin(f32); +// /* 8049abe0 */ Math::cos(f32); +// /* 8049ac10 */ Math::acos(f32); +// /* 8049ac40 */ Math::atan2(f32, f32); + +} // namespace EGG diff --git a/include/lib/egg/math/eggMatrix.h b/include/lib/egg/math/eggMatrix.h index 9831cbb4..0a5c9b51 100644 --- a/include/lib/egg/math/eggMatrix.h +++ b/include/lib/egg/math/eggMatrix.h @@ -1,12 +1,36 @@ #pragma once #include +#include +#include namespace EGG { -struct Matrix34f{ +// Maybe inherits +class Matrix34f { +public: f32 mData[3][4]; +public: + Matrix34f() {}; + f32& operator()(int i, int j) {return mData[i][j]; } + /* 8049ac70 */ bool InverseTo(Matrix34f* dest) const; + /* 8049ac80 */ bool InverseTransposeTo(Matrix34f* dest) const; + /* 8049ac90 */ void makeIdentity(); + /* 8049acd0 */ Matrix34f( \ + f32 fxx, f32 fxy, f32 fxz, f32 fxw, \ + f32 fyx, f32 fyy, f32 fyz, f32 fyw, \ + f32 fzx, f32 fzy, f32 fzz, f32 fzw); + /* 8049ad20 */ void makeQT(const Quatf&, const Vector3f&); + /* 8049ade0 */ void makeQ(const Quatf&); // these could be swapped + /* 8049ae90 */ void fromQuat(const Quatf& from); // these could be swapped + /* 8049af40 */ void toQuat(Quatf& dest); + /* 8049b250 */ void slerpTo(const Matrix34f&, Matrix34f&, f32) const; + /* 8049b2d0 */ void setAxisRotation(const Vector3f&, f32); + /* 8049b310 */ void loadPosMtx(u32); + /* 8049b320 */ void multiplyTo(const Matrix34f&, Matrix34f& out); +public: + /* 80674c00 */ static Matrix34f ident; }; } // namespace EGG diff --git a/include/lib/egg/math/eggQuat.h b/include/lib/egg/math/eggQuat.h new file mode 100644 index 00000000..08a2e570 --- /dev/null +++ b/include/lib/egg/math/eggQuat.h @@ -0,0 +1,26 @@ +#pragma once + +#include +#include + +namespace EGG +{ + +class Quatf { +public: + f32 x,y,z,w; +public: + Quatf() {} + // could also be void set(f32, f32, f32, f32); + /* 8049b390 */ Quatf(f32 fx, f32 fy, f32 fz, f32 fw); + /* 8049b3b0 */ void setAxisRotation(const Vector3f&, f32); + /* 8049b450 */ f32 norm(); + /* 8049b480 */ void normalise(); + /* 8049b500 */ void conjugate(); + /* 8049b550 */ Vector3f rotateVector(const Vector3f&); + /* 8049b800 */ void slerpTo(const Quatf&, f32, Quatf& out) const; + /* 8049b800 */ void slerpTo(const Quatf&, f32, f32, Quatf& out) const; + /* 8049bbb0 */ void makeVectorRotation(Vector3f&, Vector3f&); +}; + +} // namespace EGG diff --git a/include/lib/egg/math/eggVector.h b/include/lib/egg/math/eggVector.h index a8348a3a..773ddaca 100644 --- a/include/lib/egg/math/eggVector.h +++ b/include/lib/egg/math/eggVector.h @@ -1,16 +1,46 @@ #pragma once #include - +#include namespace EGG { -struct Vector3f { +class Vector3f { +public: f32 x,y,z; +public: + // may need change + Vector3f(const Vector3f& other) {x = other.x, y = other.y, z = other.z;} + // may need change + f32 squaredLength() { return x*x + y*y + z*z; } + f32 length() { return Math::frsqrt(squaredLength()); } + /* 8049bcc0 */ void normalise(); + /* 8049bd50 */ void setLength(Vector3f& src, f32 length); + /* 8049be10 */ void setLength(f32 length); + +public: + /* 80674c30 */ static Vector3f zero; + /* 80674c3c */ static Vector3f ex; + /* 80674c48 */ static Vector3f ey; + /* 80674c54 */ static Vector3f ez; }; struct Vector2f { f32 x,y; + +public: + /* 805767c0 */ static Vector2f zero; + /* 805767c8 */ static Vector2f ex; + /* 805767d0 */ static Vector2f ey; +}; + +struct Vector3s { + s16 x,y,z; +public: + /* 805767d8 */ static Vector3s zero; + /* 805767e0 */ static Vector3s ex; + /* 805767e8 */ static Vector3s ey; + /* 805767f0 */ static Vector3s ez; }; } // namespace EGG diff --git a/include/lib/egg/prim/eggAssert.h b/include/lib/egg/prim/eggAssert.h new file mode 100644 index 00000000..be9404ca --- /dev/null +++ b/include/lib/egg/prim/eggAssert.h @@ -0,0 +1,23 @@ +#pragma once + +#include + +namespace EGG +{ +// All this is guess +// TODO: Fixup funtions +namespace Assert +{ + +/* 8049bf90 */ void wait(u32 time); +/* 8049c010 */ void assert_printf(); +/* 8049c010 */ void report(); +/* 8049c0a0 */ s32 getPeriodPos(char*); +/* 8049c100 */ char* getMapSymbol(); +/* 8049c150 */ bool isOutsideMEM1(u32 addr); +/* 8049c190 */ void system_halt(); +/* 8049c530 */ void assert(); + +} // namespace Assert + +} // namespace EGG