From a096aef11559d73e6cf9959d72cbd78b72ee7f38 Mon Sep 17 00:00:00 2001 From: daft7 Date: Sat, 15 Feb 2025 22:25:40 -0600 Subject: [PATCH 01/21] Add template function xUtil_select to xutil.h. --- src/SB/Core/x/xutil.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/SB/Core/x/xutil.h b/src/SB/Core/x/xutil.h index 7f61cce7d..2b6311124 100644 --- a/src/SB/Core/x/xutil.h +++ b/src/SB/Core/x/xutil.h @@ -11,4 +11,7 @@ U32 xUtil_crc_update(U32 crc_accum, char* data, S32 datasize); S32 xUtil_yesno(F32 wt_yes); void xUtil_wtadjust(F32* wts, S32 cnt, F32 arbref); +template +T* xUtil_select(T** arg0, S32 arg1, const F32* arg3); + #endif From ad9d0b3a5f84eda26d93280260cf75c28012a0e5 Mon Sep 17 00:00:00 2001 From: daft7 Date: Sat, 15 Feb 2025 22:37:53 -0600 Subject: [PATCH 02/21] Filled in zNPCCommon struct with information from m2c decompiler. --- src/SB/Game/zNPCSpawner.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/SB/Game/zNPCSpawner.h b/src/SB/Game/zNPCSpawner.h index 231131d8c..3e0306d1a 100644 --- a/src/SB/Game/zNPCSpawner.h +++ b/src/SB/Game/zNPCSpawner.h @@ -50,7 +50,10 @@ enum en_SM_NPC_STATUS SM_NPC_FORCE = 0x7fffffff }; -struct zNPCCommon; +struct zNPCCommon { + /* 0x000 */ char pad0[0x1B8]; + /* 0x1B8 */ void *unk1B8; /* inferred */ +}; /* size >= 0x1BC */ struct SMDepot { From 4a06066646fa86d8a719f8c7079baaeae2b184c2 Mon Sep 17 00:00:00 2001 From: daft7 Date: Sat, 15 Feb 2025 22:39:51 -0600 Subject: [PATCH 03/21] Edited pendlist and actvlist types to pointers. --- src/SB/Game/zNPCSpawner.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SB/Game/zNPCSpawner.h b/src/SB/Game/zNPCSpawner.h index 3e0306d1a..dfc083504 100644 --- a/src/SB/Game/zNPCSpawner.h +++ b/src/SB/Game/zNPCSpawner.h @@ -86,8 +86,8 @@ struct zNPCSpawner : RyzMemData S32 cnt_spawn; SMSPStatus sppool[16]; SMNPCStatus npcpool[16]; - st_XORDEREDARRAY pendlist; - st_XORDEREDARRAY actvlist; + st_XORDEREDARRAY* pendlist; + st_XORDEREDARRAY* actvlist; //0x1A4 S32 cnt_cleanup; void Subscribe(zNPCCommon* owner); From 4c836515c5b890d95be7a4f7cb89237199afbffe Mon Sep 17 00:00:00 2001 From: daft7 Date: Sat, 15 Feb 2025 22:42:20 -0600 Subject: [PATCH 04/21] Modified existing functions to smooth additions. --- src/SB/Game/zNPCSpawner.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/SB/Game/zNPCSpawner.cpp b/src/SB/Game/zNPCSpawner.cpp index d818be777..1f7f79b83 100644 --- a/src/SB/Game/zNPCSpawner.cpp +++ b/src/SB/Game/zNPCSpawner.cpp @@ -70,8 +70,8 @@ void zNPCSpawner::Subscribe(zNPCCommon* owner) this->tym_delay = _805_Spawner; this->max_spawn = -1; this->wavestat = SM_STAT_BEGIN; - XOrdInit(&this->pendlist, 0x10, 0); - XOrdInit(&this->actvlist, 0x10, 0); + XOrdInit(this->pendlist, 0x10, 0); + XOrdInit(this->actvlist, 0x10, 0); } void zNPCSpawner::SetWaveMode(en_SM_WAVE_MODE mode, F32 delay, S32 lifemax) @@ -164,7 +164,7 @@ void zNPCSpawner::SetNPCStatus(zNPCCommon* npc, en_SM_NPC_STATUS status) SMNPCStatus* zNPCSpawner::ToastedBeastie(zNPCCommon* npc) { SMNPCStatus* ret = this->StatForNPC(npc); - XOrdRemove(&this->actvlist, ret, -1); + XOrdRemove(this->actvlist, ret, -1); zEntEvent((xBase*)this->npc_owner, eEventDuploNPCKilled); return ret; } From 2e09055e0b67cfceedcd3923d7a63fa0873a5f8f Mon Sep 17 00:00:00 2001 From: daft7 Date: Sat, 15 Feb 2025 22:45:20 -0600 Subject: [PATCH 05/21] Added partial matches for FillPending, ReFillPending, NextPendingNPC, and StatforNPC. Also have outline for ClearActive in comments. --- src/SB/Game/zNPCSpawner.cpp | 91 +++++++++++++++++++++++++++++++++++++ src/SB/Game/zNPCSpawner.h | 4 ++ 2 files changed, 95 insertions(+) diff --git a/src/SB/Game/zNPCSpawner.cpp b/src/SB/Game/zNPCSpawner.cpp index 1f7f79b83..716849667 100644 --- a/src/SB/Game/zNPCSpawner.cpp +++ b/src/SB/Game/zNPCSpawner.cpp @@ -177,3 +177,94 @@ U8 zMovePoint::IsOn() { return this->on; } + + +st_XORDEREDARRAY* zNPCSpawner::FillPending() +{ + ClearPending(); + ReFillPending(); + return this->actvlist; +} + +st_XORDEREDARRAY* zNPCSpawner::ReFillPending() +{ + s32 var_r28; + zNPCCommon *temp_r29; + zNPCSpawner *var_r30; + + var_r28 = 0; + var_r30 = this; + do { + temp_r29 = var_r30->npc_owner; + if (((zNPCCommon*)var_r30->npc_owner != NULL) && ((s32) temp_r29->pad0[4] == 1)) + { + XOrdAppend(this->pendlist, (void*) temp_r29); + temp_r29->pad0[4] = 2; + } + var_r28 += 1; + var_r30 += 0xC; + } while (var_r28 < 0x10); + return this->actvlist; +} + + +// void zNPCSpawner::ClearActive() +// { +// s32 var_r6; +// s32 var_r7; +// void *temp_r5; + +// var_r7 = 0; +// var_r6 = 0; +// loop_4: +// if (var_r7 < (s32) this->cnt_cleanup) { +// temp_r5 = *(this->pendlist->list + var_r6); +// if (temp_r5 != NULL) { +// (u32) temp_r5[1] = 1; +// } +// var_r6 += 4; +// var_r7 += 1; +// goto loop_4; +// } +// XOrdReset__FP16st_XORDEREDARRAY(&this->unk1B0); +// } + +SMNPCStatus* zNPCSpawner::NextPendingNPC( s32 arg0 ) +{ + S32 temp_r4; + const F32* temp_ptr = NULL; + + temp_r4 = (S32) this->actvlist; + if (temp_r4 < 1) { + return NULL; + } + return xUtil_select((SMNPCStatus **) this->pendlist, temp_r4, temp_ptr); +} + +/* zNPCSpawner::StatForNPC (zNPCCommon *) */ +SMNPCStatus* zNPCSpawner::StatForNPC(zNPCCommon *npc) { + s32 var_ctr; + SMNPCStatus *var_r6; + zNPCCommon *temp_r0; + zNPCCommon *temp_r0_2; + zNPCCommon *temp_r0_3; + zNPCCommon *temp_r0_4; + zNPCCommon *temp_r0_5; + zNPCCommon *temp_r0_6; + zNPCCommon *temp_r0_7; + zNPCCommon *temp_r0_8; + + var_r6 = NULL; + var_ctr = 2; + + for (var_ctr = 0; var_ctr < 16; var_ctr++) + { + temp_r0 = this->npcpool[var_ctr].npc; + if ((temp_r0 != NULL) && (temp_r0 == npc)) + { + var_r6 = &this->npcpool[var_ctr]; + } + } + + return var_r6; +} diff --git a/src/SB/Game/zNPCSpawner.h b/src/SB/Game/zNPCSpawner.h index dfc083504..339b51d82 100644 --- a/src/SB/Game/zNPCSpawner.h +++ b/src/SB/Game/zNPCSpawner.h @@ -5,6 +5,7 @@ #include "xRMemData.h" #include "xordarray.h" +#include "xutil.h" enum en_SM_NOTICES { @@ -106,6 +107,9 @@ struct zNPCSpawner : RyzMemData // NextPendingNPC. void ClearActive(); void ClearPending(); + SMNPCStatus* NextPendingNPC( s32 arg0 ); + st_XORDEREDARRAY* FillPending(); + st_XORDEREDARRAY* ReFillPending(); void SetNPCStatus(zNPCCommon* npc, en_SM_NPC_STATUS status); From 8396a3d971b2a0f199c22d95cde738afccb79cab Mon Sep 17 00:00:00 2001 From: daft7 Date: Sun, 16 Feb 2025 14:11:04 -0600 Subject: [PATCH 06/21] zNPCCommon definition removed, now included from zNPCTypeCommon. Moved en_SM_NOTICES to zNPCTypeCommon to avoid recursive include. --- src/SB/Game/zNPCSpawner.h | 19 +------------------ src/SB/Game/zNPCTypeCommon.h | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/src/SB/Game/zNPCSpawner.h b/src/SB/Game/zNPCSpawner.h index 339b51d82..c309d09ed 100644 --- a/src/SB/Game/zNPCSpawner.h +++ b/src/SB/Game/zNPCSpawner.h @@ -7,19 +7,7 @@ #include "xordarray.h" #include "xutil.h" -enum en_SM_NOTICES -{ - SM_NOTE_NPCDIED, - SM_NOTE_NPCSTANDBY, - SM_NOTE_NPCALIVE, - SM_NOTE_DUPPAUSE, - SM_NOTE_DUPRESUME, - SM_NOTE_DUPSETDELAY, - SM_NOTE_DUPDEAD, - SM_NOTE_KILLKIDS, - SM_NOTE_NOMORE, - SM_NOTE_FORCE = 0x7fffffff -}; +#include "zNPCTypeCommon.h" enum en_SM_WAVE_MODE { @@ -51,11 +39,6 @@ enum en_SM_NPC_STATUS SM_NPC_FORCE = 0x7fffffff }; -struct zNPCCommon { - /* 0x000 */ char pad0[0x1B8]; - /* 0x1B8 */ void *unk1B8; /* inferred */ -}; /* size >= 0x1BC */ - struct SMDepot { st_XORDEREDARRAY spawners; diff --git a/src/SB/Game/zNPCTypeCommon.h b/src/SB/Game/zNPCTypeCommon.h index bb1e19f1f..af36bac10 100644 --- a/src/SB/Game/zNPCTypeCommon.h +++ b/src/SB/Game/zNPCTypeCommon.h @@ -10,7 +10,6 @@ #include "xSFX.h" #include "zNPCSndTable.h" -#include "zNPCSpawner.h" #include "zMovePoint.h" #include "zShrapnel.h" @@ -340,6 +339,20 @@ enum en_NPC_MSG_DATA NPC_MDAT_FORCE = 0x7fffffff }; +enum en_SM_NOTICES +{ + SM_NOTE_NPCDIED, + SM_NOTE_NPCSTANDBY, + SM_NOTE_NPCALIVE, + SM_NOTE_DUPPAUSE, + SM_NOTE_DUPRESUME, + SM_NOTE_DUPSETDELAY, + SM_NOTE_DUPDEAD, + SM_NOTE_KILLKIDS, + SM_NOTE_NOMORE, + SM_NOTE_FORCE = 0x7fffffff +}; + struct zNPCLassoInfo { en_LASSO_STATUS stage; From c1660b71fb89a927143ca0e5f55ccf5868006d3f Mon Sep 17 00:00:00 2001 From: daft7 Date: Sun, 16 Feb 2025 14:15:01 -0600 Subject: [PATCH 07/21] zNPCTypeDuplotron now pulls zNPCSpawner definition directly from zNPCSpawner instead of transitively via zNPCTypeCommon. --- src/SB/Game/zNPCTypeDuplotron.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/SB/Game/zNPCTypeDuplotron.h b/src/SB/Game/zNPCTypeDuplotron.h index 6aa351884..d39fb3a5f 100644 --- a/src/SB/Game/zNPCTypeDuplotron.h +++ b/src/SB/Game/zNPCTypeDuplotron.h @@ -1,7 +1,7 @@ #ifndef ZNPCTYPEDUPLOTRON_H #define ZNPCTYPEDUPLOTRON_H -#include "zNPCTypeCommon.h" +#include "zNPCSpawner.h" struct zNPCDuplotron : zNPCCommon { From 1e4b5644bc59c0505631374003132759fd2ddec0 Mon Sep 17 00:00:00 2001 From: daft7 Date: Sun, 16 Feb 2025 14:16:17 -0600 Subject: [PATCH 08/21] Quick patches to data types after using more detailed definition of zNPCCommon. --- src/SB/Game/zNPCSpawner.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SB/Game/zNPCSpawner.cpp b/src/SB/Game/zNPCSpawner.cpp index 716849667..780e60940 100644 --- a/src/SB/Game/zNPCSpawner.cpp +++ b/src/SB/Game/zNPCSpawner.cpp @@ -196,10 +196,10 @@ st_XORDEREDARRAY* zNPCSpawner::ReFillPending() var_r30 = this; do { temp_r29 = var_r30->npc_owner; - if (((zNPCCommon*)var_r30->npc_owner != NULL) && ((s32) temp_r29->pad0[4] == 1)) + if (((zNPCCommon*)var_r30->npc_owner != NULL) && ((s32) temp_r29->flg_vuln == 1)) { XOrdAppend(this->pendlist, (void*) temp_r29); - temp_r29->pad0[4] = 2; + temp_r29->flg_vuln = 2; } var_r28 += 1; var_r30 += 0xC; From 7197929abf1b376101ddad963525abdb1ae62051 Mon Sep 17 00:00:00 2001 From: daft7 Date: Sun, 16 Feb 2025 15:08:56 -0600 Subject: [PATCH 09/21] Revert pendlist and actvllist to not being pointers. --- src/SB/Game/zNPCSpawner.cpp | 12 ++++++------ src/SB/Game/zNPCSpawner.h | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/SB/Game/zNPCSpawner.cpp b/src/SB/Game/zNPCSpawner.cpp index 780e60940..d314d54f2 100644 --- a/src/SB/Game/zNPCSpawner.cpp +++ b/src/SB/Game/zNPCSpawner.cpp @@ -70,8 +70,8 @@ void zNPCSpawner::Subscribe(zNPCCommon* owner) this->tym_delay = _805_Spawner; this->max_spawn = -1; this->wavestat = SM_STAT_BEGIN; - XOrdInit(this->pendlist, 0x10, 0); - XOrdInit(this->actvlist, 0x10, 0); + XOrdInit(&this->pendlist, 0x10, 0); + XOrdInit(&this->actvlist, 0x10, 0); } void zNPCSpawner::SetWaveMode(en_SM_WAVE_MODE mode, F32 delay, S32 lifemax) @@ -164,7 +164,7 @@ void zNPCSpawner::SetNPCStatus(zNPCCommon* npc, en_SM_NPC_STATUS status) SMNPCStatus* zNPCSpawner::ToastedBeastie(zNPCCommon* npc) { SMNPCStatus* ret = this->StatForNPC(npc); - XOrdRemove(this->actvlist, ret, -1); + XOrdRemove(&this->actvlist, ret, -1); zEntEvent((xBase*)this->npc_owner, eEventDuploNPCKilled); return ret; } @@ -183,7 +183,7 @@ st_XORDEREDARRAY* zNPCSpawner::FillPending() { ClearPending(); ReFillPending(); - return this->actvlist; + return &this->actvlist; } st_XORDEREDARRAY* zNPCSpawner::ReFillPending() @@ -198,13 +198,13 @@ st_XORDEREDARRAY* zNPCSpawner::ReFillPending() temp_r29 = var_r30->npc_owner; if (((zNPCCommon*)var_r30->npc_owner != NULL) && ((s32) temp_r29->flg_vuln == 1)) { - XOrdAppend(this->pendlist, (void*) temp_r29); + XOrdAppend(&this->pendlist, (void*) temp_r29); temp_r29->flg_vuln = 2; } var_r28 += 1; var_r30 += 0xC; } while (var_r28 < 0x10); - return this->actvlist; + return &this->actvlist; } diff --git a/src/SB/Game/zNPCSpawner.h b/src/SB/Game/zNPCSpawner.h index c309d09ed..d3d7b8f58 100644 --- a/src/SB/Game/zNPCSpawner.h +++ b/src/SB/Game/zNPCSpawner.h @@ -70,8 +70,8 @@ struct zNPCSpawner : RyzMemData S32 cnt_spawn; SMSPStatus sppool[16]; SMNPCStatus npcpool[16]; - st_XORDEREDARRAY* pendlist; - st_XORDEREDARRAY* actvlist; //0x1A4 + st_XORDEREDARRAY pendlist; + st_XORDEREDARRAY actvlist; //0x1A4 S32 cnt_cleanup; void Subscribe(zNPCCommon* owner); From 3c2b0c56d546fe1e8a153e9f02aceb8a5137c908 Mon Sep 17 00:00:00 2001 From: daft7 Date: Sun, 16 Feb 2025 15:09:41 -0600 Subject: [PATCH 10/21] Implemented suggested fixes to NextPendingNPC. --- src/SB/Game/zNPCSpawner.cpp | 9 +++++---- src/SB/Game/zNPCSpawner.h | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/SB/Game/zNPCSpawner.cpp b/src/SB/Game/zNPCSpawner.cpp index d314d54f2..146bcffdb 100644 --- a/src/SB/Game/zNPCSpawner.cpp +++ b/src/SB/Game/zNPCSpawner.cpp @@ -229,16 +229,17 @@ st_XORDEREDARRAY* zNPCSpawner::ReFillPending() // XOrdReset__FP16st_XORDEREDARRAY(&this->unk1B0); // } -SMNPCStatus* zNPCSpawner::NextPendingNPC( s32 arg0 ) +SMNPCStatus* zNPCSpawner::NextPendingNPC(S32 arg0) { S32 temp_r4; const F32* temp_ptr = NULL; - temp_r4 = (S32) this->actvlist; - if (temp_r4 < 1) { + temp_r4 = this->pendlist.cnt; + if (temp_r4 < 1) + { return NULL; } - return xUtil_select((SMNPCStatus **) this->pendlist, temp_r4, temp_ptr); + return xUtil_select((SMNPCStatus**)this->pendlist.list, temp_r4, temp_ptr); } /* zNPCSpawner::StatForNPC (zNPCCommon *) */ diff --git a/src/SB/Game/zNPCSpawner.h b/src/SB/Game/zNPCSpawner.h index d3d7b8f58..615fa42fa 100644 --- a/src/SB/Game/zNPCSpawner.h +++ b/src/SB/Game/zNPCSpawner.h @@ -90,7 +90,7 @@ struct zNPCSpawner : RyzMemData // NextPendingNPC. void ClearActive(); void ClearPending(); - SMNPCStatus* NextPendingNPC( s32 arg0 ); + SMNPCStatus* NextPendingNPC( S32 arg0 ); st_XORDEREDARRAY* FillPending(); st_XORDEREDARRAY* ReFillPending(); From 8b9b2703fb8ac806caac34ca1685e41d6fc791d4 Mon Sep 17 00:00:00 2001 From: daft7 Date: Sun, 16 Feb 2025 15:10:51 -0600 Subject: [PATCH 11/21] Used Clang to format. --- src/SB/Game/zNPCSpawner.cpp | 38 ++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/SB/Game/zNPCSpawner.cpp b/src/SB/Game/zNPCSpawner.cpp index 146bcffdb..b8c54502a 100644 --- a/src/SB/Game/zNPCSpawner.cpp +++ b/src/SB/Game/zNPCSpawner.cpp @@ -178,27 +178,27 @@ U8 zMovePoint::IsOn() return this->on; } - st_XORDEREDARRAY* zNPCSpawner::FillPending() { ClearPending(); ReFillPending(); - return &this->actvlist; + return &this->actvlist; } st_XORDEREDARRAY* zNPCSpawner::ReFillPending() { s32 var_r28; - zNPCCommon *temp_r29; - zNPCSpawner *var_r30; + zNPCCommon* temp_r29; + zNPCSpawner* var_r30; var_r28 = 0; var_r30 = this; - do { + do + { temp_r29 = var_r30->npc_owner; - if (((zNPCCommon*)var_r30->npc_owner != NULL) && ((s32) temp_r29->flg_vuln == 1)) + if (((zNPCCommon*)var_r30->npc_owner != NULL) && ((s32)temp_r29->flg_vuln == 1)) { - XOrdAppend(&this->pendlist, (void*) temp_r29); + XOrdAppend(&this->pendlist, (void*)temp_r29); temp_r29->flg_vuln = 2; } var_r28 += 1; @@ -207,7 +207,6 @@ st_XORDEREDARRAY* zNPCSpawner::ReFillPending() return &this->actvlist; } - // void zNPCSpawner::ClearActive() // { // s32 var_r6; @@ -243,17 +242,18 @@ SMNPCStatus* zNPCSpawner::NextPendingNPC(S32 arg0) } /* zNPCSpawner::StatForNPC (zNPCCommon *) */ -SMNPCStatus* zNPCSpawner::StatForNPC(zNPCCommon *npc) { +SMNPCStatus* zNPCSpawner::StatForNPC(zNPCCommon* npc) +{ s32 var_ctr; - SMNPCStatus *var_r6; - zNPCCommon *temp_r0; - zNPCCommon *temp_r0_2; - zNPCCommon *temp_r0_3; - zNPCCommon *temp_r0_4; - zNPCCommon *temp_r0_5; - zNPCCommon *temp_r0_6; - zNPCCommon *temp_r0_7; - zNPCCommon *temp_r0_8; + SMNPCStatus* var_r6; + zNPCCommon* temp_r0; + zNPCCommon* temp_r0_2; + zNPCCommon* temp_r0_3; + zNPCCommon* temp_r0_4; + zNPCCommon* temp_r0_5; + zNPCCommon* temp_r0_6; + zNPCCommon* temp_r0_7; + zNPCCommon* temp_r0_8; var_r6 = NULL; var_ctr = 2; @@ -266,6 +266,6 @@ SMNPCStatus* zNPCSpawner::StatForNPC(zNPCCommon *npc) { var_r6 = &this->npcpool[var_ctr]; } } - + return var_r6; } From 1f1bebdf67600ee76ef998dc4045e9427ced3c22 Mon Sep 17 00:00:00 2001 From: daft7 Date: Tue, 18 Feb 2025 23:45:03 -0600 Subject: [PATCH 12/21] Saw xMat3x3Identity was defined in Climate.cpp, added handle to header to import into xMath3. --- src/SB/Core/x/xClimate.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/SB/Core/x/xClimate.h b/src/SB/Core/x/xClimate.h index 868dd93a5..4396c1683 100644 --- a/src/SB/Core/x/xClimate.h +++ b/src/SB/Core/x/xClimate.h @@ -38,4 +38,7 @@ void xClimateSetSnow(F32 stre); void xClimateInitAsset(_tagClimate* climate, xEnvAsset* easset); void xClimateInit(_tagClimate* climate); +void xMat3x3Identity(xMat3x3* matrix); + + #endif From 55faa577665a4b1725c999a5121662efe478b143 Mon Sep 17 00:00:00 2001 From: daft7 Date: Tue, 18 Feb 2025 23:47:14 -0600 Subject: [PATCH 13/21] Moved xMat3x3Copy and xMat3x3Identity to imports from xClimate as they are defined there. --- src/SB/Core/x/xMath3.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SB/Core/x/xMath3.h b/src/SB/Core/x/xMath3.h index 0b9ac55c1..7f14afa83 100644 --- a/src/SB/Core/x/xMath3.h +++ b/src/SB/Core/x/xMath3.h @@ -90,7 +90,7 @@ extern xVec3 g_Onez; // We could also define it as static in each .cpp file, but it's not required. static void xMat3x3RMulVec(xVec3* o, const xMat3x3* m, const xVec3* v); -void xMat3x3Copy(xMat3x3* o, const xMat3x3* m); +//void xMat3x3Copy(xMat3x3* o, const xMat3x3* m); // May come from xClimate void xMat4x3Copy(xMat4x3* o, const xMat4x3* m); void xMat4x3Mul(xMat4x3* o, const xMat4x3* a, const xMat4x3* b); void xMat3x3Euler(xMat3x3* m, F32 yaw, F32 pitch, F32 roll); @@ -125,7 +125,7 @@ void xMat3x3Mul(xMat3x3* o, const xMat3x3* a, const xMat3x3* b); void xMat3x3SMul(xMat3x3*, const xMat3x3*, F32); void xBoxFromLine(xBox& box, const xLine3& line); void xBoxFromRay(xBox& box, const xRay3& ray); -void xMat3x3Identity(xMat3x3* matrix); +//void xMat3x3Identity(xMat3x3* matrix); // May come from xClimate S32 xPointInBox(const xBox* b, const xVec3* p); void xMat3x3LMulVec(xVec3* o, const xMat3x3* m, const xVec3* v); From daa10c692ddcdd8092cf8afca56ca73a8cb0ae3a Mon Sep 17 00:00:00 2001 From: daft7 Date: Tue, 18 Feb 2025 23:52:45 -0600 Subject: [PATCH 14/21] Initial work on xMath3. Handles in header moved to cpp file and many are filled out. --- src/SB/Core/x/xMath3.cpp | 395 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 395 insertions(+) diff --git a/src/SB/Core/x/xMath3.cpp b/src/SB/Core/x/xMath3.cpp index d47a8accd..a855be775 100644 --- a/src/SB/Core/x/xMath3.cpp +++ b/src/SB/Core/x/xMath3.cpp @@ -1,3 +1,398 @@ #include "xMath3.h" #include + +#include "iMath.h" // icos and isin +#include "xClimate.h" // xMat3x3Identity +#include "xMathInlines.h" // xasin, xatan2 +//#include "xVec3Inlines.h" // xVec3Init, imported, realized xClimate has a declaration as well though. + +void xMat4x3Copy(xMat4x3* o, const xMat4x3* m){ + +} + + +/* xMat4x3Mul (xMat4x3 *, xMat4x3 const *, xMat4x3 const *) */ +void xMat4x3Mul(xMat4x3* o, const xMat4x3 *a, const xMat4x3 *b) { + xVec3 sp8; + + xMat4x3Toworld(&sp8, b, (xVec3 *) &a->pad3); + xMat3x3Mul((xMat3x3 *) o, (xMat3x3 *) a, (xMat3x3 *) b); + xVec3Copy((xVec3 *) &o->pad3, &sp8); +} + +/* xMat3x3Euler (xMat3x3 *, float, float, float) */ +void xMat3x3Euler(xMat3x3* m, F32 yaw, F32 pitch, F32 roll) { + F32 temp_f0; + F32 temp_f1; + F32 temp_f27; + F32 temp_f28; + F32 temp_f29; + F32 temp_f30; + F32 temp_f31; + F32 temp_f7; + + temp_f27 = isin(yaw); + temp_f28 = icos(yaw); + temp_f29 = isin(pitch); + temp_f30 = icos(pitch); + temp_f31 = isin(roll); + temp_f1 = icos(roll); + temp_f7 = temp_f27 * temp_f29; + temp_f0 = temp_f28 * temp_f29; + m->right.x = (temp_f28 * temp_f1) + (temp_f31 * temp_f7); + m->right.y = temp_f30 * temp_f31; + m->right.z = (-temp_f27 * temp_f1) + (temp_f31 * temp_f0); + m->up.x = (-temp_f28 * temp_f31) + (temp_f1 * temp_f7); + m->up.y = temp_f30 * temp_f1; + m->up.z = (temp_f27 * temp_f31) + (temp_f1 * temp_f0); + m->at.x = temp_f27 * temp_f30; + m->at.y = -temp_f29; + m->at.z = temp_f28 * temp_f30; + m->flags = 0; +} + +void xRotCopy(xRot* o, const xRot* r){ + +} + +void xMat4x3Toworld(xVec3* o, const xMat4x3* m, const xVec3* v){ + +} + +void xMat3x3Rot(xMat3x3* m, const xVec3* a, F32 t){ + +} + +/* xMat3x3RotC (xMat3x3 *, float, float, float, float) */ +void xMat3x3RotC(xMat3x3* m, F32 _x, F32 _y, F32 _z, F32 t) { + F32 temp_f0; + F32 temp_f0_2; + F32 temp_f1; + F32 temp_f28; + F32 temp_f2; + F32 temp_f3; + F32 temp_f4; + F32 temp_f5; + F32 temp_f6; + F32 temp_f7; + F32 temp_f8; + + if (t == 0.0f) { + xMat3x3Identity(m); + return; + } + temp_f28 = icos(t); + temp_f1 = isin(t); + temp_f5 = -temp_f1; + temp_f2 = 1.0f - temp_f28; + temp_f0 = temp_f2 * _x; + temp_f8 = temp_f2 * _z; + temp_f4 = temp_f2 * _y; + temp_f3 = _y * temp_f0; + temp_f6 = _x * temp_f8; + temp_f0_2 = (temp_f1 * _z) + temp_f3; + m->right.x = (_x * temp_f0) + temp_f28; + temp_f7 = _z * temp_f4; + m->right.y = temp_f0_2; + m->right.z = (temp_f5 * _y) + temp_f6; + m->up.x = (temp_f5 * _z) + temp_f3; + m->up.y = (_y * temp_f4) + temp_f28; + m->up.z = (temp_f1 * _x) + temp_f7; + m->at.x = (temp_f1 * _y) + temp_f6; + m->at.y = (temp_f5 * _x) + temp_f7; + m->at.z = (_z * temp_f8) + temp_f28; + m->flags = 0; +} + +/* xMat3x3RotY (xMat3x3 *, float) */ +void xMat3x3RotY(xMat3x3* m, F32 t) { + F32 temp_f1; + F32 temp_f31; + + temp_f31 = icos(t); + temp_f1 = isin(t); + xVec3Init((xVec3 *) m, temp_f31, 0.0f, -temp_f1); + xVec3Copy(&m->right, &g_Y3); + xVec3Init(&m->up, temp_f1, 0.0f, temp_f31); + m->flags = 0; +} + +void xMat3x3MulRotC(xMat3x3* o, xMat3x3* m, F32 _x, F32 _y, F32 _z, F32 t){ + +} + +void xMat4x3Identity(xMat4x3* m){ + +} + +/* xMat3x3Normalize (xMat3x3 *, xMat3x3 const *) */ +void xMat3x3Normalize(xMat3x3* o, const xMat3x3* m) { + xVec3Normalize((xVec3 *) o, (xVec3 *) m); + xVec3Normalize(&o->right, &m->right); + xVec3Normalize(&o->up, &m->up); +} + +void xMat4x3Tolocal(xVec3* o, const xMat4x3* m, const xVec3* v){ + +} + +/* xMat3x3Tolocal (xVec3 *, xMat3x3 const *, xVec3 const *) */ +void xMat3x3Tolocal(xVec3* o, const xMat3x3* m, const xVec3* v) { + F32 temp_f0; + F32 temp_f0_2; + F32 temp_f1; + F32 temp_f1_2; + F32 temp_f29; + F32 temp_f2; + F32 temp_f30; + F32 temp_f31; + F32 temp_f6; + F32 temp_f7; + F32 temp_f8; + F32 temp_f8_2; + + temp_f1 = m->right.x; + temp_f0 = m->right.y; + temp_f2 = m->up.x; + temp_f1_2 = m->up.y; + temp_f8 = m->at.x; + temp_f0_2 = m->at.y; + temp_f6 = m->right.z; + temp_f7 = m->up.z; + temp_f8_2 = m->at.z; + temp_f31 = (temp_f6 * temp_f6) + ((temp_f1 * temp_f1) + (temp_f0 * temp_f0)); + temp_f30 = (temp_f7 * temp_f7) + ((temp_f2 * temp_f2) + (temp_f1_2 * temp_f1_2)); + temp_f29 = (temp_f8_2 * temp_f8_2) + ((temp_f8 * temp_f8) + (temp_f0_2 * temp_f0_2)); + xMat3x3LMulVec(o, m, v); + o->x /= temp_f31; + o->y /= temp_f30; + o->z /= temp_f29; +} + +/* xMat4x3MoveLocalRight (xMat4x3 *, float) */ +void xMat4x3MoveLocalRight(xMat4x3* m, F32 mag) { + m->pos.x += m->right.x * mag; + m->pos.y += m->right.y * mag; + m->pos.z += m->right.z * mag; +} + +/* xMat4x3MoveLocalAt (xMat4x3 *, float) */ +void xMat4x3MoveLocalAt(xMat4x3* m, F32 mag) { + m->pos.x += m->at.x * mag; + m->pos.y += m->at.y * mag; + m->pos.z += m->at.z * mag; +} + +/* xMat4x3MoveLocalUp (xMat4x3 *, float) */ +void xMat4x3MoveLocalUp(xMat4x3* m, F32 mag) { + m->pos.x += m->up.x * mag; + m->pos.y += m->up.y * mag; + m->pos.z += m->up.z * mag; +} + +/* xMat3x3GetEuler (xMat3x3 const *, xVec3 *) */ +void xMat3x3GetEuler(const xMat3x3* m, xVec3* a) { + F32 temp_f31; + F32 var_f1; + F32 var_f30; + + temp_f31 = -xasin(m->at.y); + if (temp_f31 < 1.5707964f) { + if (temp_f31 > -1.5707964f) { + var_f30 = xatan2(m->at.x, m->at.z); + var_f1 = xatan2(m->right.y, m->up.y); + } else { + var_f30 = -xatan2(-m->up.x, m->up.x); + var_f1 = 0.0f; + } + } else { + var_f1 = 0.0f; + var_f30 = xatan2(-m->up.x, m->right.x); + } + a->x = var_f30; + a->y = temp_f31; + a->z = var_f1; +} + +/* xMat3x3Euler (xMat3x3 *, xVec3 const *) */ +void xMat3x3Euler(xMat3x3* m, const xVec3* ypr) { + xMat3x3Euler(m, ypr->x, ypr->y, ypr->z); +} + +/* xQuatToMat (xQuat const *, xMat3x3 *) */ +void xQuatToMat(const xQuat* q, xMat3x3* m) { + F32 temp_f10; + F32 temp_f11; + F32 temp_f12; + F32 temp_f13; + F32 temp_f1; + F32 temp_f2; + F32 temp_f3; + F32 temp_f3_2; + F32 temp_f4; + F32 temp_f4_2; + F32 temp_f5; + F32 temp_f5_2; + F32 temp_f6; + F32 temp_f7; + F32 temp_f8; + F32 temp_f9; + + temp_f5 = q->v.y; + temp_f1 = q->v.z; + temp_f2 = 2.0f * temp_f5; + temp_f4 = q->v.x; + temp_f7 = 2.0f * temp_f1; + temp_f3 = q->s; + temp_f6 = 2.0f * temp_f4; + temp_f12 = temp_f2 * temp_f5; + temp_f13 = temp_f7 * temp_f1; + temp_f9 = temp_f7 * temp_f3; + temp_f10 = temp_f2 * temp_f4; + temp_f8 = temp_f2 * temp_f3; + temp_f11 = temp_f7 * temp_f4; + m->right.x = (1.0f - temp_f12) - temp_f13; + temp_f4_2 = temp_f6 * temp_f4; + m->right.y = temp_f10 - temp_f9; + temp_f3_2 = temp_f6 * temp_f3; + temp_f5_2 = temp_f7 * temp_f5; + m->right.z = temp_f11 + temp_f8; + m->up.x = temp_f10 + temp_f9; + m->up.y = (1.0f - temp_f13) - temp_f4_2; + m->up.z = temp_f5_2 - temp_f3_2; + m->at.x = temp_f11 - temp_f8; + m->at.y = temp_f5_2 + temp_f3_2; + m->at.z = (1.0f - temp_f4_2) - temp_f12; + m->flags = 0; +} + +void xQuatDiff(xQuat* o, const xQuat* a, const xQuat* b){ + +} + +F32 xQuatGetAngle(const xQuat* q){ + +} + +void xQuatFromMat(xQuat* q, const xMat3x3* m){ + +} + +void xQuatSlerp(xQuat* q, const xQuat* a, const xQuat* b, F32 t){ + +} + +void xQuatConj(xQuat* o, const xQuat* q){ + +} + +void xMat3x3LookAt(xMat3x3* m, const xVec3* pos, const xVec3* at){ + +} + +F32 xMat3x3LookVec(xMat3x3* m, const xVec3* at){ + +} + +void xBoxInitBoundOBB(xBox* o, const xBox* b, const xMat4x3* m){ + +} + +void xMat3x3Scale(xMat3x3* m, const xVec3* s){ + +} + +/* xMat3x3ScaleC (xMat3x3 *, float, float, float) */ +void xMat3x3ScaleC(xMat3x3* m, F32 x, F32 y, F32 z) { + xVec3Init((xVec3 *) m, x, 0.0f, 0.0f); + xVec3Init(&m->up, 0.0f, y, 0.0f); + xVec3Init(&m->at, 0.0f, 0.0f, z); + m->flags = 0; +} + +void xMat3x3RMulRotY(xMat3x3* o, const xMat3x3* m, F32 t){ + +} + +/* xMat3x3Mul (xMat3x3 *, xMat3x3 const *, xMat3x3 const *) */ +void xMat3x3Mul(xMat3x3* o, const xMat3x3* a, const xMat3x3* b) { + xMat3x3 sp8; + F32 temp_f0; + F32 temp_f0_2; + F32 temp_f10; + F32 temp_f10_2; + F32 temp_f12; + F32 temp_f13; + F32 temp_f1; + F32 temp_f25; + F32 temp_f26; + F32 temp_f27; + F32 temp_f29; + F32 temp_f2; + F32 temp_f30; + F32 temp_f3; + F32 temp_f4; + F32 temp_f4_2; + F32 temp_f5; + F32 temp_f9; + U8 var_r0; + xMat3x3 *var_r6; + + var_r0 = 0; + if ((o == a) || (o == b)) { + var_r0 = 1; + } + if (var_r0 != 0) { + var_r6 = &sp8; + } else { + var_r6 = o; + } + temp_f4 = a->right.y; + temp_f3 = b->up.x; + temp_f2 = b->up.y; + temp_f1 = a->up.y; + temp_f10 = b->up.z; + temp_f0 = a->at.y; + temp_f26 = a->right.x; + temp_f27 = b->right.x; + temp_f30 = b->right.y; + temp_f9 = a->up.x; + temp_f12 = b->right.z; + temp_f4_2 = a->at.x; + temp_f25 = a->right.z; + temp_f0_2 = b->at.x; + temp_f29 = b->at.y; + temp_f13 = b->at.z; + temp_f10_2 = a->up.z; + temp_f5 = a->at.z; + var_r6->right.x = (temp_f25 * temp_f0_2) + ((temp_f26 * temp_f27) + (temp_f4 * temp_f3)); + var_r6->flags = 0; + var_r6->right.y = (temp_f25 * temp_f29) + ((temp_f26 * temp_f30) + (temp_f4 * temp_f2)); + var_r6->right.z = (temp_f25 * temp_f13) + ((temp_f26 * temp_f12) + (temp_f4 * temp_f10)); + var_r6->up.x = (temp_f10_2 * temp_f0_2) + ((temp_f9 * temp_f27) + (temp_f1 * temp_f3)); + var_r6->up.y = (temp_f10_2 * temp_f29) + ((temp_f9 * temp_f30) + (temp_f1 * temp_f2)); + var_r6->up.z = (temp_f10_2 * temp_f13) + ((temp_f9 * temp_f12) + (temp_f1 * temp_f10)); + var_r6->at.x = (temp_f5 * temp_f0_2) + ((temp_f4_2 * temp_f27) + (temp_f0 * temp_f3)); + var_r6->at.y = (temp_f5 * temp_f29) + ((temp_f4_2 * temp_f30) + (temp_f0 * temp_f2)); + var_r6->at.z = (temp_f5 * temp_f13) + ((temp_f4_2 * temp_f12) + (temp_f0 * temp_f10)); + // if (var_r0 != 0) { + // xMat3x3Copy__FP7xMat3x3PC7xMat3x3(o, var_r6); + // } +} + +void xMat3x3SMul(xMat3x3*, const xMat3x3*, F32){ + +} + +void xBoxFromLine(xBox& box, const xLine3& line){ + +} + +void xBoxFromRay(xBox& box, const xRay3& ray){ + +} + +void xMat3x3LMulVec(xVec3* o, const xMat3x3* m, const xVec3* v){ + +} From 0398c6aed6a6b0b8a210b4e31cde9ca2360f348d Mon Sep 17 00:00:00 2001 From: daft7 Date: Wed, 19 Feb 2025 00:25:52 -0600 Subject: [PATCH 15/21] While working on xMath3, removed declaration for xMat3x3Copy and xMat3x3Identity because they were already specified in xClimate.cpp. Added declarations for them in xClimate.h and moved an import in zNPCGlyp.cpp. --- src/SB/Core/x/xClimate.h | 2 +- src/SB/Game/zNPCGlyph.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/SB/Core/x/xClimate.h b/src/SB/Core/x/xClimate.h index 4396c1683..c535b30c2 100644 --- a/src/SB/Core/x/xClimate.h +++ b/src/SB/Core/x/xClimate.h @@ -39,6 +39,6 @@ void xClimateInitAsset(_tagClimate* climate, xEnvAsset* easset); void xClimateInit(_tagClimate* climate); void xMat3x3Identity(xMat3x3* matrix); - +void xMat3x3Copy(xMat3x3* m1, const xMat3x3* m2); #endif diff --git a/src/SB/Game/zNPCGlyph.cpp b/src/SB/Game/zNPCGlyph.cpp index 726855a4d..d4967c58e 100644 --- a/src/SB/Game/zNPCGlyph.cpp +++ b/src/SB/Game/zNPCGlyph.cpp @@ -5,6 +5,7 @@ #include "xMath.h" #include "xMathInlines.h" #include "xMath3.h" +#include "xClimate.h" #include "xstransvc.h" #include From f9b391c1519b833258f844ceaf8e020fabffe336 Mon Sep 17 00:00:00 2001 From: daft7 Date: Wed, 19 Feb 2025 20:50:50 -0600 Subject: [PATCH 16/21] Revert to last commit. --- src/SB/Core/x/xClimate.h | 2 +- src/SB/Game/zNPCGlyph.cpp | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/SB/Core/x/xClimate.h b/src/SB/Core/x/xClimate.h index c535b30c2..4396c1683 100644 --- a/src/SB/Core/x/xClimate.h +++ b/src/SB/Core/x/xClimate.h @@ -39,6 +39,6 @@ void xClimateInitAsset(_tagClimate* climate, xEnvAsset* easset); void xClimateInit(_tagClimate* climate); void xMat3x3Identity(xMat3x3* matrix); -void xMat3x3Copy(xMat3x3* m1, const xMat3x3* m2); + #endif diff --git a/src/SB/Game/zNPCGlyph.cpp b/src/SB/Game/zNPCGlyph.cpp index d4967c58e..726855a4d 100644 --- a/src/SB/Game/zNPCGlyph.cpp +++ b/src/SB/Game/zNPCGlyph.cpp @@ -5,7 +5,6 @@ #include "xMath.h" #include "xMathInlines.h" #include "xMath3.h" -#include "xClimate.h" #include "xstransvc.h" #include From deb85ebbf040daf7b5b44020af106bd5a0551639 Mon Sep 17 00:00:00 2001 From: daft7 Date: Wed, 19 Feb 2025 21:02:51 -0600 Subject: [PATCH 17/21] Rolled back from earlier commit (1f1bebdf67600ee76ef998dc4045e9427ced3c22), xMat3x3Identity and xMat3x3Copy will eventually be moved to xMath3 most likely. --- src/SB/Core/x/xClimate.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/SB/Core/x/xClimate.h b/src/SB/Core/x/xClimate.h index 4396c1683..868dd93a5 100644 --- a/src/SB/Core/x/xClimate.h +++ b/src/SB/Core/x/xClimate.h @@ -38,7 +38,4 @@ void xClimateSetSnow(F32 stre); void xClimateInitAsset(_tagClimate* climate, xEnvAsset* easset); void xClimateInit(_tagClimate* climate); -void xMat3x3Identity(xMat3x3* matrix); - - #endif From c63521b72b5c0a08ebb7a7e807fd1aa135a24d7e Mon Sep 17 00:00:00 2001 From: daft7 Date: Wed, 19 Feb 2025 21:06:01 -0600 Subject: [PATCH 18/21] xMat3x3Identity and xMat3x3Copy both present in xClimate but only in cpp. For other uses in game, use from xMath3, hence uncommenting. --- src/SB/Core/x/xMath3.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SB/Core/x/xMath3.h b/src/SB/Core/x/xMath3.h index 7f14afa83..f52fd19c6 100644 --- a/src/SB/Core/x/xMath3.h +++ b/src/SB/Core/x/xMath3.h @@ -90,7 +90,7 @@ extern xVec3 g_Onez; // We could also define it as static in each .cpp file, but it's not required. static void xMat3x3RMulVec(xVec3* o, const xMat3x3* m, const xVec3* v); -//void xMat3x3Copy(xMat3x3* o, const xMat3x3* m); // May come from xClimate +void xMat3x3Copy(xMat3x3* o, const xMat3x3* m); // May come from xClimate void xMat4x3Copy(xMat4x3* o, const xMat4x3* m); void xMat4x3Mul(xMat4x3* o, const xMat4x3* a, const xMat4x3* b); void xMat3x3Euler(xMat3x3* m, F32 yaw, F32 pitch, F32 roll); @@ -125,7 +125,7 @@ void xMat3x3Mul(xMat3x3* o, const xMat3x3* a, const xMat3x3* b); void xMat3x3SMul(xMat3x3*, const xMat3x3*, F32); void xBoxFromLine(xBox& box, const xLine3& line); void xBoxFromRay(xBox& box, const xRay3& ray); -//void xMat3x3Identity(xMat3x3* matrix); // May come from xClimate +void xMat3x3Identity(xMat3x3* matrix); // May come from xClimate S32 xPointInBox(const xBox* b, const xVec3* p); void xMat3x3LMulVec(xVec3* o, const xMat3x3* m, const xVec3* v); From e815093bb934bdbd6668e217849c06f50709588d Mon Sep 17 00:00:00 2001 From: daft7 Date: Wed, 19 Feb 2025 23:49:19 -0600 Subject: [PATCH 19/21] Additional definitions for things used in other xMath3 functions. --- src/SB/Core/x/xMath3.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/SB/Core/x/xMath3.h b/src/SB/Core/x/xMath3.h index f52fd19c6..8c1181268 100644 --- a/src/SB/Core/x/xMath3.h +++ b/src/SB/Core/x/xMath3.h @@ -76,6 +76,8 @@ struct xLine3 struct xRay3; +static S32 nxt2148[4] = { 1, 2, 0, 0 }; // Used by xQuatFromMat + extern xVec3 g_O3; extern xVec3 g_X3; extern xVec3 g_Y3; @@ -129,4 +131,14 @@ void xMat3x3Identity(xMat3x3* matrix); // May come from xClimate S32 xPointInBox(const xBox* b, const xVec3* p); void xMat3x3LMulVec(xVec3* o, const xMat3x3* m, const xVec3* v); +void xQuatMul(xQuat* arg0, const xQuat* arg1, const xQuat* arg2); +void xQuatFlip(xQuat* o1, xQuat* o2); +void xQuatNormalize(xQuat* arg01, xQuat* arg02); + +void xQuatSMul(xQuat* q, const xQuat* a, F32 t); +void xQuatAdd(xQuat* q, const xQuat* a, const xQuat* b); +F32 xQuatDot( const xQuat* a, const xQuat* b ); + +F32 fabs( F32 x ); // Unsure where this should come from. + #endif From 6705b1524c3db7eaef2ca83d81e4e1b30b6eb147 Mon Sep 17 00:00:00 2001 From: daft7 Date: Wed, 19 Feb 2025 23:50:12 -0600 Subject: [PATCH 20/21] Further progress on xMath3 functions, still WIP. --- src/SB/Core/x/xMath3.cpp | 201 +++++++++++++++++++++++++++++++++++++-- 1 file changed, 195 insertions(+), 6 deletions(-) diff --git a/src/SB/Core/x/xMath3.cpp b/src/SB/Core/x/xMath3.cpp index a855be775..879ac25ab 100644 --- a/src/SB/Core/x/xMath3.cpp +++ b/src/SB/Core/x/xMath3.cpp @@ -267,32 +267,221 @@ void xQuatToMat(const xQuat* q, xMat3x3* m) { m->flags = 0; } -void xQuatDiff(xQuat* o, const xQuat* a, const xQuat* b){ - +/* xQuatDiff (xQuat *, xQuat const *, xQuat const *) */ +void xQuatDiff(xQuat* o, const xQuat* a, const xQuat* b) { + xQuatConj(o, a); + xQuatMul(o, o, b); + if (o->s < 0.0f) { + xQuatFlip(o, o); + } } F32 xQuatGetAngle(const xQuat* q){ - + F32 angle; + angle = 5.0; + return angle; } -void xQuatFromMat(xQuat* q, const xMat3x3* m){ +/* xQuatFromMat (xQuat *, xMat3x3 const *) */ +void xQuatFromMat(xQuat* q, const xMat3x3* m) { + F32 temp_f1; + F32 temp_f1_2; + F32 temp_f1_3; + F32 temp_f5; + F32 temp_f6; + S32 temp_r25; + F32 temp_r28; + F32 temp_r30; + F32 temp_r31; + F32 temp_r8; + S32 var_r29; + + temp_f1 = m->at.z + (m->right.x + m->up.y); + if (temp_f1 > 0.0f) { + temp_f1_2 = xsqrt(1.0f + temp_f1); + q->s = 0.5f * temp_f1_2; + temp_f5 = 0.5f / temp_f1_2; + q->v.x = temp_f5 * (m->at.y - m->up.z); + q->v.y = temp_f5 * (m->right.z - m->at.x); + q->v.z = temp_f5 * (m->up.x - m->right.y); + return; + } + var_r29 = 0; + if (m->up.y > m->right.x) { + var_r29 = 1; + } + // if (m->at.z > F32 (*(m + (var_r29 * 0x14)))) { + // var_r29 = 2; + // } + // temp_r31 = var_r29 * 4; + // temp_r25 = nxt2148[var_r29]; + // temp_r30 = temp_r25 * 4; + // temp_r28 = nxt2148[temp_r25]; + // temp_f1_3 = xsqrt(1.0f + ((*(m + (var_r29 * 0x14)) - *(m + (temp_r25 * 0x14))) - *(m + (temp_r28 * 0x14)))); + // if ((F32) fabs(temp_f1_3) < 0.00001f) { + // xQuatCopy(q, &g_IQ); + // return; + // } + // temp_r8 = temp_r28 * 4; + // *(q + temp_r31) = 0.5f * temp_f1_3; + // temp_f6 = 0.5f / temp_f1_3; + // q->unkC = temp_f6 * (*(m + ((temp_r25 + temp_r8) * 4)) - *(m + ((temp_r28 + temp_r30) * 4))); + // *(q + temp_r30) = temp_f6 * (*(m + ((var_r29 + temp_r30) * 4)) + *(m + ((temp_r25 + temp_r31) * 4))); + // *(q + temp_r8) = temp_f6 * (*(m + ((var_r29 + temp_r8) * 4)) + *(m + ((temp_r28 + temp_r31) * 4))); + // if (q->unkC < 0.0f) { + // xQuatFlip(q, q); + // } +} +/* xQuatSlerp (xQuat *, xQuat const *, xQuat const *, float) */ +void xQuatSlerp(xQuat* q, const xQuat* a, const xQuat* b, F32 t) { + xQuat sp28; + xQuat sp18; + F32 sp14; + F32 sp10; + F32 spC; + F32 sp8; + F32 temp_f0; + F32 temp_f1; + F32 temp_f28; + F32 temp_f2; + F32 temp_f3; + F32 temp_f4; + F32 var_f1; + F32 var_f29; + F32 var_f30; + const xQuat* var_r31; + + var_r31 = b; + var_f1 = xQuatDot(a, var_r31); + if (var_f1 < 0.0f) { + var_f1 = -var_f1; + temp_f4 = -var_r31->v.x; + temp_f0 = var_r31->s; + temp_f3 = -var_r31->v.y; + temp_f2 = -var_r31->v.z; + var_r31 = (xQuat *) &sp8; + sp8 = temp_f4; + spC = temp_f3; + sp10 = temp_f2; + sp14 = -temp_f0; + } + //M2C_ERROR(/* unknown instruction: cror eq, gt, eq */); + if (var_f1 == 0.999f) { + var_f30 = t; + var_f29 = 1.0f - t; + } else { + temp_f1 = xacos(var_f1); + temp_f28 = 1.0f / isin(temp_f1); + var_f29 = temp_f28 * isin((1.0f - t) * temp_f1); + var_f30 = temp_f28 * isin(t * temp_f1); + } + xQuatSMul(&sp28, a, var_f29); + xQuatSMul(&sp18, var_r31, var_f30); + xQuatAdd(q, &sp28, &sp18); + xQuatNormalize(q, q); } -void xQuatSlerp(xQuat* q, const xQuat* a, const xQuat* b, F32 t){ +/* xQuatMul (xQuat *, xQuat const *, xQuat const *) */ +void xQuatMul(xQuat *o, const xQuat *a, const xQuat *b) { + F32 temp_f10; + F32 temp_f11; + F32 temp_f4; + F32 temp_f5; + F32 temp_f6; + F32 temp_f7; + F32 temp_f8; + F32 temp_f9; + temp_f4 = b->s; + temp_f11 = a->v.x; + temp_f5 = a->v.y; + temp_f8 = b->v.x; + temp_f7 = a->s; + temp_f9 = a->v.z; + temp_f6 = b->v.y; + temp_f10 = b->v.z; + o->v.x = -((temp_f9 * temp_f6) - ((temp_f5 * temp_f10) + ((temp_f7 * temp_f8) + (temp_f11 * temp_f4)))); + o->v.y = -((temp_f11 * temp_f10) - ((temp_f9 * temp_f8) + ((temp_f7 * temp_f6) + (temp_f5 * temp_f4)))); + o->v.z = -((temp_f5 * temp_f8) - ((temp_f11 * temp_f6) + ((temp_f7 * temp_f10) + (temp_f9 * temp_f4)))); + o->s = -((temp_f9 * temp_f10) - -((temp_f5 * temp_f6) - ((temp_f7 * temp_f4) - (temp_f11 * temp_f8)))); + xQuatNormalize(o, o); } void xQuatConj(xQuat* o, const xQuat* q){ } +/* xQuatSMul (xQuat *, xQuat const *, float) */ +void xQuatSMul(xQuat* q, const xQuat* a, F32 t) { + q->s = a->s * t; + xVec3SMul((xVec3 *) q, (xVec3 *) a, t); +} + +/* xQuatAdd (xQuat *, xQuat const *, xQuat const *) */ +void xQuatAdd(xQuat* q, const xQuat* a, const xQuat* b) { + q->s = a->s + b->s; + xVec3Add((xVec3 *) q, (xVec3 *) a, (xVec3 *) b); +} + void xMat3x3LookAt(xMat3x3* m, const xVec3* pos, const xVec3* at){ } +/* xMat3x3LookVec (xMat3x3 *, xVec3 const *) */ F32 xMat3x3LookVec(xMat3x3* m, const xVec3* at){ - + F32 temp_f2; + F32 temp_f31; + xVec3 *temp_r3; + + temp_f31 = xVec3Normalize(&m->at, at); + temp_r3 = &m->at; + xVec3Inv(temp_r3, temp_r3); + temp_f2 = m->at.y; + if ((F32) fabs(1.0f - temp_f2) < 0.00001f) { + m->right.x = 1.0f; + m->right.y = 0.0f; + m->right.z = 0.0f; + m->up.x = 0.0f; + m->up.y = 0.0f; + m->up.z = 1.0f; + m->at.x = 0.0f; + m->at.y = -1.0f; + m->at.z = 0.0f; + return temp_f31; + } + if ((F32) fabs(1.0f + temp_f2) < 0.00001f) { + m->right.x = -1.0f; + m->right.y = 0.0f; + m->right.z = 0.0f; + m->up.x = 0.0f; + m->up.y = 0.0f; + m->up.z = -1.0f; + m->at.x = 0.0f; + m->at.y = 1.0f; + m->at.z = 0.0f; + return temp_f31; + } + if (((F32) fabs(at->z) < 0.00001f) && ((F32) fabs(at->x) < 0.00001f)) { + m->right.x = 1.0f; + m->right.y = 0.0f; + m->right.z = 0.0f; + m->up.x = 0.0f; + m->up.y = 1.0f; + m->up.z = 0.0f; + m->at.x = 0.0f; + m->at.y = 0.0f; + m->at.y = 1.0f; + return 0.0f; + } + m->right.x = m->at.z; + m->right.y = 0.0f; + m->right.z = -m->at.x; + xVec3Normalize((xVec3 *) m, (xVec3 *) m); + xVec3Cross(&m->up, &m->at, (xVec3 *) m); + xVec3Cross((xVec3 *) m, &m->up, &m->at); + m->flags = 0; + return temp_f31; } void xBoxInitBoundOBB(xBox* o, const xBox* b, const xMat4x3* m){ From 7db98522347f737cf3bab43551af4ac9be393b11 Mon Sep 17 00:00:00 2001 From: daft7 Date: Wed, 19 Feb 2025 23:52:54 -0600 Subject: [PATCH 21/21] Edited comments to be more accurate. --- src/SB/Core/x/xMath3.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/SB/Core/x/xMath3.h b/src/SB/Core/x/xMath3.h index 8c1181268..700ead4f6 100644 --- a/src/SB/Core/x/xMath3.h +++ b/src/SB/Core/x/xMath3.h @@ -92,7 +92,7 @@ extern xVec3 g_Onez; // We could also define it as static in each .cpp file, but it's not required. static void xMat3x3RMulVec(xVec3* o, const xMat3x3* m, const xVec3* v); -void xMat3x3Copy(xMat3x3* o, const xMat3x3* m); // May come from xClimate +void xMat3x3Copy(xMat3x3* o, const xMat3x3* m); // TODO: These functions should be inline void xMat4x3Copy(xMat4x3* o, const xMat4x3* m); void xMat4x3Mul(xMat4x3* o, const xMat4x3* a, const xMat4x3* b); void xMat3x3Euler(xMat3x3* m, F32 yaw, F32 pitch, F32 roll); @@ -127,7 +127,7 @@ void xMat3x3Mul(xMat3x3* o, const xMat3x3* a, const xMat3x3* b); void xMat3x3SMul(xMat3x3*, const xMat3x3*, F32); void xBoxFromLine(xBox& box, const xLine3& line); void xBoxFromRay(xBox& box, const xRay3& ray); -void xMat3x3Identity(xMat3x3* matrix); // May come from xClimate +void xMat3x3Identity(xMat3x3* matrix); // TODO: These functions should be inline S32 xPointInBox(const xBox* b, const xVec3* p); void xMat3x3LMulVec(xVec3* o, const xMat3x3* m, const xVec3* v);