From 7a27cda3a14b220c3fc27004607b5b0aef5680cc Mon Sep 17 00:00:00 2001 From: Prakxo Date: Thu, 20 Apr 2023 06:34:17 +0000 Subject: [PATCH] link m_olib --- config/rel_slices.yml | 3 +++ include/libc/math.h | 2 ++ include/libu64/u64types.h | 4 ---- include/m_olib.h | 10 ++++++++++ rel/m_olib.c | 27 +++++++++++++++++++++++++++ tools/ppcdis | 2 +- 6 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 rel/m_olib.c diff --git a/config/rel_slices.yml b/config/rel_slices.yml index 066ff86b..ea1e810f 100644 --- a/config/rel_slices.yml +++ b/config/rel_slices.yml @@ -12,6 +12,9 @@ m_room_type/mRmTp_FtrItemNo2FtrIdx.c: # .rodata: [0x80643310, 0x80643318] sys_stacks.c: .bss: [0x812F5670, 0x812F9670] +m_olib.c: + .text: [0x803D88E8, 0x803D8A34] + .rodata: [0x80642A00, 0x80642A10] THA_GA.c: .text: [0x80404AE0, 0x80404B40] TwoHeadArena.c: diff --git a/include/libc/math.h b/include/libc/math.h index cacd313e..1ab5b46a 100644 --- a/include/libc/math.h +++ b/include/libc/math.h @@ -5,6 +5,8 @@ #define SQRT_OF_2_F 1.41421356237309504880f +#define M_PI 3.14159265358979323846f + s16 sins(u16); f32 fatan2(f32, f32); diff --git a/include/libu64/u64types.h b/include/libu64/u64types.h index 24ed70cd..9cfe459c 100644 --- a/include/libu64/u64types.h +++ b/include/libu64/u64types.h @@ -3,10 +3,6 @@ #include "types.h" -typedef struct xyz_s { - f32 x, y, z; -} xyz_t; - typedef struct { u32 r:8; u32 g:8; diff --git a/include/m_olib.h b/include/m_olib.h index 58492c3f..961df972 100644 --- a/include/m_olib.h +++ b/include/m_olib.h @@ -3,10 +3,20 @@ #include "types.h" #include "libu64/u64types.h" +#include "m_lib.h" +#include "libc/math.h" + +//gotta put these somewhere else +#define TRUNCF_BINANG(f) (s16)(s32)(f) +#define CAM_DEG_TO_BINANG(degrees) (s16)TRUNCF_BINANG((degrees) * 182.04167f + .5f) +#define RAD_TO_DEG(radians) ((radians) * (180.0f / M_PI)) typedef struct rect_s { int top, bottom; int l, r; } rect; +void radianxy_by_2pos(xyz_t* dest, xyz_t* sub, xyz_t* min); +s_xyz sanglexy_by_2pos(xyz_t* sub, xyz_t* min); + #endif diff --git a/rel/m_olib.c b/rel/m_olib.c new file mode 100644 index 00000000..9c40466d --- /dev/null +++ b/rel/m_olib.c @@ -0,0 +1,27 @@ +#include "m_olib.h" +void radianxy_by_2pos(xyz_t* dest, xyz_t* sub, xyz_t* min){ + + xyz_t ret; + + ret.x = fatan2(min->z - sub->z, min->y - sub->y); + ret.y = fatan2(min->x - sub->x, min->z - sub->z); + ret.z = 0.0f; + + *dest = ret; +} + +s_xyz sanglexy_by_2pos(xyz_t* sub, xyz_t* min) { + + s_xyz sangle; + xyz_t conv; + xyz_t angle; + + radianxy_by_2pos(&angle, sub,min); + conv = angle; + sangle.x = CAM_DEG_TO_BINANG(RAD_TO_DEG(conv.x)); + sangle.y = CAM_DEG_TO_BINANG(RAD_TO_DEG(conv.y)); + sangle.z = 0; + + + return sangle; +} \ No newline at end of file diff --git a/tools/ppcdis b/tools/ppcdis index 83260829..eca3f301 160000 --- a/tools/ppcdis +++ b/tools/ppcdis @@ -1 +1 @@ -Subproject commit 83260829c50f37dd9fe54889cf8971c8fe14c54e +Subproject commit eca3f3015a86bf0c78d1e415aeff2dda1851194f