From 03afd57a54e316f299652d71fa4c061989f99361 Mon Sep 17 00:00:00 2001 From: mariob92 <21146795-mariob92@users.noreply.gitlab.com> Date: Thu, 19 Sep 2024 16:52:55 +0200 Subject: [PATCH] - document coord related functions (mostly unused by the game) - renamed code_B7B20.c to coords.c - removed the exception for asm/core1/code_1E820.s from .gitignore file (should not be in the work tree) --- .gitignore | 1 - decompressed.pal.yaml | 2 +- decompressed.us.v10.yaml | 2 +- include/core2/coords.h | 9 ++++ src/core2/code_34790.c | 3 +- src/core2/code_B7B20.c | 79 ----------------------------------- src/core2/coords.c | 90 ++++++++++++++++++++++++++++++++++++++++ src/core2/mapModel.c | 3 +- 8 files changed, 105 insertions(+), 84 deletions(-) create mode 100644 include/core2/coords.h delete mode 100644 src/core2/code_B7B20.c create mode 100644 src/core2/coords.c diff --git a/.gitignore b/.gitignore index a939a88a..8eec04ef 100644 --- a/.gitignore +++ b/.gitignore @@ -11,7 +11,6 @@ asm/*/*.s asm/core1/os !asm/ultra !asm/core1/ultra -!asm/core1/code_1E820.s build/* build/ diff --git a/decompressed.pal.yaml b/decompressed.pal.yaml index 887e2727..7cee9080 100644 --- a/decompressed.pal.yaml +++ b/decompressed.pal.yaml @@ -823,7 +823,7 @@ segments: # - [0x100C5C0, c, code_B6C60] #DONE # - [0x100C640, c, code_B6CE0] #DONE # - [0x100C800, c, code_B6EA0] #DONE - # - [0x100D480, c, code_B7B20] #DONE + # - [0x100D480, c, coords] #DONE # - [0x100D8A0, c, code_B7F40] #DONE # - [0x100D980, c, code_B8020] #DONE # - [0x100D9D0, c, code_B8070] #DONE diff --git a/decompressed.us.v10.yaml b/decompressed.us.v10.yaml index 4d9a22d3..095ef309 100644 --- a/decompressed.us.v10.yaml +++ b/decompressed.us.v10.yaml @@ -823,7 +823,7 @@ segments: - [0x100C5C0, c, code_B6C60] #DONE - [0x100C640, c, code_B6CE0] #DONE - [0x100C800, c, code_B6EA0] #DONE - - [0x100D480, c, code_B7B20] #DONE + - [0x100D480, c, coords] #DONE - [0x100D8A0, c, code_B7F40] #DONE - [0x100D980, c, code_B8020] #DONE - [0x100D9D0, c, code_B8070] #DONE diff --git a/include/core2/coords.h b/include/core2/coords.h new file mode 100644 index 00000000..524ca0f3 --- /dev/null +++ b/include/core2/coords.h @@ -0,0 +1,9 @@ +#include +#include "bool.h" + +void coords_copy(s32 min_out[3], s32 max_out[3], s32 min_in[3], s32 max_in[3]); +s32 coords_func_8033EAF8(s32 min[3], s32 max[3], f32 position[3], f32 direction[3]); +bool coords_isPointInside(s32 min[3], s32 max[3], s32 point[3]); +bool coords_isPointInsideWithOffset(s32 min[3], s32 max[3], s32 point[3], s32 offset); +void coords_scale(s32 min[3], s32 max[3], s32 ratio); +void coords_translate(s32 min[3], s32 max[3], f32 translation[3]); diff --git a/src/core2/code_34790.c b/src/core2/code_34790.c index 4a8e7b09..7821d774 100644 --- a/src/core2/code_34790.c +++ b/src/core2/code_34790.c @@ -3,6 +3,7 @@ #include "variables.h" #include "core2/nc/camera.h" #include +#include "core2/coords.h" extern Actor *func_80328230(enum actor_e, f32[3], f32[3]); extern void func_802BEA4C(f32[3], f32[3], f32, f32[3]); @@ -124,7 +125,7 @@ void func_802BBA84(void) { viewport_getPosition_vec3f(vp_position); viewport_getRotation_vec3f(vp_rotation); viewport_getLookVector(sp48); - D_8037D8CC = (f32) func_8033EAF8(min, max, vp_position, sp48); + D_8037D8CC = (f32) coords_func_8033EAF8(min, max, vp_position, sp48); D_8037D8CC += 100.0f; if (D_8037D8CC < 1000.0f) { D_8037D8CC = 1000.0f; diff --git a/src/core2/code_B7B20.c b/src/core2/code_B7B20.c deleted file mode 100644 index 9ad2a674..00000000 --- a/src/core2/code_B7B20.c +++ /dev/null @@ -1,79 +0,0 @@ -#include -#include "functions.h" -#include "variables.h" - - -void func_8033EAB0(s32 arg0[3], s32 arg1[3], s32 arg2[3], s32 arg3[3]) { - s32 i; - for(i = 0; i < 3; i++){ - arg0[i] = arg2[i]; - arg1[i] = arg3[i]; - } -} - -s32 func_8033EAF8(s32 min_coord[3], s32 max_coord[3], f32 position[3], f32 arg3[3]) { - f32 dCorner[3]; - f32 dot_product; - f32 max; - s32 ix; - s32 iy; - s32 iz; - - max = 0.0f; - for(ix = 0; ix < 2; ix++){ - for(iy = 0; iy < 2; iy++){ - for(iz = 0; iz < 2; iz++){ - dCorner[0] = ((ix) ? min_coord[0] : max_coord[0]) - position[0]; - dCorner[1] = ((iy) ? min_coord[1] : max_coord[1]) - position[1]; - dCorner[2] = ((iz) ? min_coord[2] : max_coord[2]) - position[2]; - dot_product = (arg3[0] * dCorner[0]) + (arg3[1] * dCorner[1]) + (arg3[2] * dCorner[2]); - if (max < dot_product) { - max = dot_product; - } - } - } - } - return (s32) max; -} - -bool func_8033EC10(s32 arg0[3], s32 arg1[3], s32 arg2[3]) { - s32 i; - for(i = 0; i < 3; i++){ - if (arg0[i] >= arg2[i]) { - return FALSE; - } - if (arg2[i] >= arg1[i]) { - return FALSE; - } - } - return TRUE; -} - -bool func_8033EC70(s32 arg0[3], s32 arg1[3], s32 arg2[3], s32 arg3) { - s32 i; - for(i = 0; i < 3; i++){ - if (arg0[i] >= (arg2[i] + arg3)) { - return FALSE; - } - if ((arg2[i] - arg3) >= arg1[i]) { - return FALSE; - } - } - return TRUE; -} - -void func_8033ECD8(s32 arg0[3], s32 arg1[3], s32 arg2) { - s32 i; - for(i = 0; i < 3; i++){ - arg0[i] = (arg0[i] >= 0) ? arg0[i]/ arg2 : arg0[i]/ arg2 - 1; - arg1[i] = (arg1[i] >= 0) ? arg1[i]/ arg2 : arg1[i]/ arg2 - 1; - } -} - -void func_8033EDF0(s32 arg0[3], s32 arg1[3], f32 arg2[3]) { - s32 i; - for(i = 0; i < 3; i++){ - arg0[i] += arg2[i]; - arg1[i] += arg2[i]; - } -} diff --git a/src/core2/coords.c b/src/core2/coords.c new file mode 100644 index 00000000..7a633186 --- /dev/null +++ b/src/core2/coords.c @@ -0,0 +1,90 @@ +#include +#include "bool.h" + +void coords_copy(s32 min_out[3], s32 max_out[3], s32 min_in[3], s32 max_in[3]) { + int i; + + for (i = 0; i < 3; i++) { + min_out[i] = min_in[i]; + max_out[i] = max_in[i]; + } +} + +s32 coords_func_8033EAF8(s32 min[3], s32 max[3], f32 position[3], f32 direction[3]) { + f32 corner[3]; + f32 dot_product; + f32 result; + s32 ix; + s32 iy; + s32 iz; + + result = 0.0f; + + for(ix = 0; ix < 2; ix++) { + for (iy = 0; iy < 2; iy++) { + for (iz = 0; iz < 2; iz++) { + corner[0] = (ix ? min[0] : max[0]) - position[0]; + corner[1] = (iy ? min[1] : max[1]) - position[1]; + corner[2] = (iz ? min[2] : max[2]) - position[2]; + + dot_product = (direction[0] * corner[0]) + (direction[1] * corner[1]) + (direction[2] * corner[2]); + + if (result < dot_product) { + result = dot_product; + } + } + } + } + + return (s32) result; +} + +bool coords_isPointInside(s32 min[3], s32 max[3], s32 point[3]) { + int i; + + for (i = 0; i < 3; i++) { + if (min[i] >= point[i]) { + return FALSE; + } + + if (point[i] >= max[i]) { + return FALSE; + } + } + + return TRUE; +} + +bool coords_isPointInsideWithOffset(s32 min[3], s32 max[3], s32 point[3], s32 offset) { + int i; + + for (i = 0; i < 3; i++) { + if (min[i] >= (point[i] + offset)) { + return FALSE; + } + + if ((point[i] - offset) >= max[i]) { + return FALSE; + } + } + + return TRUE; +} + +void coords_scale(s32 min[3], s32 max[3], s32 ratio) { + int i; + + for (i = 0; i < 3; i++) { + min[i] = (min[i] >= 0) ? min[i] / ratio : min[i] / ratio - 1; + max[i] = (max[i] >= 0) ? max[i] / ratio : max[i] / ratio - 1; + } +} + +void coords_translate(s32 min[3], s32 max[3], f32 translation[3]) { + int i; + + for (i = 0; i < 3; i++) { + min[i] += translation[i]; + max[i] += translation[i]; + } +} diff --git a/src/core2/mapModel.c b/src/core2/mapModel.c index 870aefc1..cd16b567 100644 --- a/src/core2/mapModel.c +++ b/src/core2/mapModel.c @@ -3,6 +3,7 @@ #include "variables.h" #include "core2/modelRender.h" +#include "core2/coords.h" extern UNK_TYPE(s32) func_802E8E88(BKCollisionList *, BKVertexList *, f32[3], f32[3], f32, f32[3], s32, s32); extern UNK_TYPE(s32) func_802E92AC(BKCollisionList *, BKVertexList *, f32[3], f32, f32[3], s32); @@ -400,7 +401,7 @@ struct5Bs *func_803097A0(void){ void mapModel_getCubeBounds(s32 min[3], s32 max[3]) { vtxList_getBounds_s32(model_getVtxList(mapModel.model_bin_opa), min, max); - func_8033ECD8(min, max, 1000); + coords_scale(min, max, 1000); min[0] = min[0] + mapModel.description->unk6[0]; min[1] = min[1] + mapModel.description->unk6[1]; min[2] = min[2] + mapModel.description->unk6[2];