diff --git a/src/melee/cm/camera.c b/src/melee/cm/camera.c index 786a460b26..5ba9290622 100644 --- a/src/melee/cm/camera.c +++ b/src/melee/cm/camera.c @@ -23,6 +23,9 @@ /* 4D7E30 */ extern float cm_804D7E30; /* 4D7E60 */ extern float cm_804D7E60; /* 4D7E6C */ extern float cm_804D7E6C; +/* 4D6458 */ extern CameraBox* cm_804D6458; +/* 4D6460 */ extern CameraBox* cm_804D6460; +/* 4D6468 */ extern CameraBox* cm_804D6468; CameraBox* Camera_80029020(void) { @@ -406,3 +409,138 @@ bool Camera_8003118C(Vec3* arg0, float arg1) } return false; } + +void Camera_80028F5C(CameraBox* subject, s32 arg1) +{ + if (subject != NULL) { + subject->x8 = arg1; + subject->x10.z = 0.0f; + subject->x10.y = 0.0f; + subject->x10.x = 0.0f; + subject->x1C = subject->x10; + // subject->x1C.y = subject->x10.y; + // subject->x1C.z = subject->x10.z; + subject->x28 = 0.0f; + // subject->xC_b0 = subject->xC_b0 & ~0x80; + subject->xC_b0 = subject->xC_b0 & ~0x80; + subject->xC_b0 = subject->xC_b0 & ~0x40; + subject->xC_b0 = subject->xC_b0 & ~0x20; + subject->xD_fill[0] = 0; + subject->x2C.x = -1.0f; + subject->x2C.y = 1.0f; + subject->x34.x = 1.0f; + subject->x34.y = -1.0f; + subject->x34.z = 1.0f; + subject->x40 = subject->x2C; + subject->x48 = subject->x34; + // // subject->bounds.left = (f32) subject->default_bounds.left; + // // subject->bounds.right = (f32) subject->default_bounds.right; + // // subject->bounds.top = (f32) subject->default_bounds.top; + // // subject->bounds.bottom = (f32) subject->default_bounds.bottom; + // // subject->default_size = subject->size; + // *(u32*) &subject->default_size = *(u32*) &subject->size; + subject->x54.x = 0.0f; + subject->x54.y = 0.0f; + subject->x54.z = 0.0f; + subject->x60.x = 0.0f; + subject->x60.y = 0.0f; + subject->x60.z = 0.0f; + } +} + +void Camera_80028F5C(CameraBox*, s32); /* static */ +static s8 cm_803BCBB0[0x20] = "couldn't get CmSubject struct.\n"; + +CameraBox* Camera_80029044(int arg0) +{ + CameraBox* subject = cm_804D6458; + + // subject = cm_804D6458; + if ((CameraBox*) cm_804D6458 == NULL) { + OSReport("couldn't get CmSubject struct.\n", arg0); + loop_2: + goto loop_2; + } + cm_804D6458 = subject->prev; + subject->next = NULL; + if ((CameraBox*) cm_804D6460 != NULL) { + cm_804D6468->next = subject; + } else { + cm_804D6460 = subject; + } + subject->prev = cm_804D6468; + cm_804D6468 = subject; + Camera_80028F5C(subject, arg0); + return subject; +} + +void Camera_800290D4(CameraBox* subject) +{ + if (subject->next != 0) { + subject->next->prev = subject->prev; + } else { + cm_804D6468 = subject->prev; + } + + if (subject->prev != 0) { + subject->prev->next = subject->next; + } else { + cm_804D6460 = subject->next; + } + + subject->prev = cm_804D6458; + cm_804D6458 = subject; +} + +static CameraUnkGlobals cm_803BCCA0; + +void Camera_80029AAC(CameraBounds* bounds, CameraMovement* movement, f32 arg8) +{ + f32 temp_f0; + f32 temp_f3; + f32 var_f1; + f32 var_f2; + f32 var_f3; + f32 var_f5; + + if (bounds->subjects != 0) { + temp_f3 = bounds->x_max - bounds->x_min; + temp_f0 = bounds->y_max - bounds->y_min; + if (temp_f3 > temp_f0) { + var_f5 = temp_f3; + } else { + var_f5 = temp_f0; + } + } else { + var_f5 = 99999.0f; + } + if (var_f5 > cm_803BCCA0.x38) { + var_f2 = cm_803BCCA0.x30; + } else if (var_f5 < cm_803BCCA0.x34) { + var_f2 = cm_803BCCA0.x2C; + } else { + var_f2 = ((cm_803BCCA0.x30 - cm_803BCCA0.x2C) * + ((var_f5 - cm_803BCCA0.x34) / + (cm_803BCCA0.x38 - cm_803BCCA0.x34))) + + cm_803BCCA0.x2C; + } + if (cm_80452C68.unk_2bc > 0.0001f) { + var_f3 = 1.0f / cm_80452C68.unk_2bc; + } else { + var_f3 = 1000.0f; + } + var_f1 = var_f3 * (var_f2 * arg8); + if (var_f1 > 1.0f) { + var_f1 = 1.0f; + } else if (var_f1 < 0.0001f) { + var_f1 = 0.0001f; + } + movement->interest.x = + (f32) (((movement->target_interest.x - movement->interest.x) * + var_f1) + + movement->interest.x); + movement->interest.y = + (f32) (((movement->target_interest.y - movement->interest.y) * + var_f1) + + movement->interest.y); +} diff --git a/src/melee/cm/forward.h b/src/melee/cm/forward.h index 2597ace4a3..c314a8032b 100644 --- a/src/melee/cm/forward.h +++ b/src/melee/cm/forward.h @@ -7,5 +7,6 @@ typedef struct Camera Camera; typedef struct CameraBounds CameraBounds; typedef struct CameraBox CameraBox; typedef struct CameraMovement CameraMovement; +typedef struct CameraUnkGlobals CameraUnkGlobals; #endif diff --git a/src/melee/cm/types.h b/src/melee/cm/types.h index 26e3b21f1d..08cc96b6c4 100644 --- a/src/melee/cm/types.h +++ b/src/melee/cm/types.h @@ -8,7 +8,8 @@ #include struct CameraBox { - u32 data_filler[2]; + CameraBox* next; + CameraBox* prev; bool x8; /* +C:0 */ u8 xC_b0 : 1; u8 xD_fill[0x10 - 0xD]; @@ -19,6 +20,8 @@ struct CameraBox { Vec3 x34; Vec2 x40; Vec3 x48; + Vec3 x54; + Vec3 x60; }; struct CameraMovement { @@ -35,7 +38,7 @@ struct CameraBounds { float y_min; float x_max; float y_max; - float subjects; + int subjects; float z_pos; }; @@ -59,4 +62,12 @@ struct Camera { uint last_mode; }; +struct CameraUnkGlobals { + float x0[11]; + float x2C; + float x30; + float x34; + float x38; +}; + #endif diff --git a/src/melee/db/db_2253.c b/src/melee/db/db_2253.c index ca9a68f3d3..5077650b80 100644 --- a/src/melee/db/db_2253.c +++ b/src/melee/db/db_2253.c @@ -1,8 +1,13 @@ #include "db_2253.h" #include +#include +#include +#include /* 4D6B50 */ static IntVec2 lbl_804D6B50; +/* 453004 */ extern UNK_T cm_80453004; +/* 4D6B5C */ extern s8 lbl_804D6B5C; /// #db_80225374 @@ -104,21 +109,119 @@ void fn_80226E00(void) /// #fn_802277E8 /// #fn_80227904 - +void fn_80227904(HSD_GObj* camera, s8 port) +{ + f32 var_f1; + f32 var_f2; + f32 var_f2_2; + f32 var_f3; + u32 temp_r4; + + var_f2 = HSD_PadMasterStatus[port].nml_subStickX; + if (var_f2 < 0.0f) { + var_f1 = -var_f2; + } else { + var_f1 = var_f2; + } + if (var_f1 < 0.2f) { + var_f2 = 0.0f; + } + var_f3 = HSD_PadMasterStatus[port].nml_subStickY; + if (var_f3 < 0.0f) { + var_f2_2 = -var_f3; + } else { + var_f2_2 = var_f3; + } + if (var_f2_2 < 0.2f) { + var_f3 = 0.0f; + } + temp_r4 = HSD_PadMasterStatus[port].button; + + if (temp_r4 & 1) { + fn_80227CAC(camera, var_f3); + } else if (temp_r4 & 2) { + fn_80227FE0(camera, -var_f2, -var_f3); + } else { + fn_80227B64(camera, var_f2, var_f3); + } + lbl_804D6B5C = 0x3C; +} /// #fn_802279E8 /// #fn_80227B64 - +void fn_80227B64(HSD_GObj* camera, f32 cstick_x, f32 cstick_y) +{ + if ((cstick_x != 0.0f) || (cstick_y != 0.0f)) { + fn_802279E8(camera, (Vec3*) &cm_80453004 + 0x6, + (Vec3*) &cm_80453004 + 0x5, cstick_x, cstick_y); + } +} /// #fn_80227BA8 /// #fn_80227CAC +void fn_80227CAC(HSD_GObj* camera, f32 cstick_y) +{ + Vec3 sp14; + UNK_T sp10; + s32 temp_cr0_eq; + void* temp_r31; + + temp_cr0_eq = cstick_y == 0.0f; + if ((temp_cr0_eq != 0) && (temp_cr0_eq != 0)) { + temp_r31 = camera->hsd_obj; + HSD_CObjGetEyeVector((HSD_CObj*) temp_r31, &sp14); + PSVECScale(&sp14, &sp14, + HSD_CObjGetEyeDistance((HSD_CObj*) temp_r31) * + -((0.05f * cstick_y) - 1.0f)); + PSVECSubtract((Vec3*) &cm_80453004 + 0x5, &sp14, + (Vec3*) &cm_80453004 + 0x6); + } +} /// #fn_80227D38 /// #fn_80227EB0 /// #fn_80227FE0 - +void fn_80227FE0(HSD_GObj* camera, f32 cstick_x, f32 cstick_y) +{ + Vec3 sp24; + Vec3 sp18; + UNK_T sp20; + Vec3* temp_r3; + Vec3* temp_r3_2; + Vec3* temp_r3_3; + Vec3* temp_r3_4; + f32 temp_f31; + f32 temp_f31_2; + void* temp_r30; + + if ((cstick_x != 0.0f) || (cstick_y != 0.0f)) { + temp_r30 = camera->hsd_obj; + temp_f31 = HSD_CObjGetEyeDistance((HSD_CObj*) temp_r30); + temp_f31_2 = + 0.03f * + (2.0f * + (temp_f31 * tanf(0.017453292f * + HSD_CObjGetFov((HSD_CObj*) temp_r30) * 0.5f))); + if (cstick_x != 0.0f) { + HSD_CObjGetLeftVector((HSD_CObj*) temp_r30, &sp18); + PSVECScale(&sp18, &sp18, temp_f31_2 * cstick_x); + temp_r3 = (Vec3*) &cm_80453004 + 0x5; + PSVECAdd(temp_r3, &sp18, temp_r3); + temp_r3_2 = (Vec3*) &cm_80453004 + 0x6; + PSVECAdd(temp_r3_2, &sp18, temp_r3_2); + } + if (cstick_y != 0.0f) { + HSD_CObjGetUpVector((HSD_CObj*) temp_r30, &sp24); + PSVECScale(&sp24, &sp24, -temp_f31_2 * cstick_y); + temp_r3_3 = (Vec3*) &cm_80453004 + 0x5; + PSVECAdd(temp_r3_3, &sp24, temp_r3_3); + temp_r3_4 = (Vec3*) &cm_80453004 + 0x6; + PSVECAdd(temp_r3_4, &sp24, temp_r3_4); + } + } +} /// #fn_80228124 /// #fn_80228318 diff --git a/src/melee/db/db_2253.h b/src/melee/db/db_2253.h index f0138cb94e..f510dfba28 100644 --- a/src/melee/db/db_2253.h +++ b/src/melee/db/db_2253.h @@ -5,6 +5,9 @@ #include "ft/forward.h" #include "it/forward.h" +#include +#include + /* 225374 */ void db_80225374(void); /* 2254B8 */ UNK_RET db_802254B8(UNK_PARAMS); /* 22558C */ UNK_RET fn_8022558C(UNK_PARAMS); @@ -53,14 +56,18 @@ /* 227188 */ UNK_RET fn_80227188(UNK_PARAMS); /* 227484 */ UNK_RET fn_80227484(UNK_PARAMS); /* 2277E8 */ UNK_RET fn_802277E8(UNK_PARAMS); -/* 227904 */ UNK_RET fn_80227904(UNK_PARAMS); -/* 2279E8 */ UNK_RET fn_802279E8(UNK_PARAMS); -/* 227B64 */ UNK_RET fn_80227B64(UNK_PARAMS); +/* 227904 */ void fn_80227904(HSD_GObj* camera, s8 port); +/* 2279E8 */ void fn_802279E8(HSD_GObj* camera, Vec3* camera_pos, + Vec3* camera_interest, float cstick_x, + float cstick_y); +/* 227B64 */ void fn_80227B64(HSD_GObj* camera, float cstick_x, + float cstick_y); /* 227BA8 */ UNK_RET fn_80227BA8(UNK_PARAMS); -/* 227CAC */ UNK_RET fn_80227CAC(UNK_PARAMS); +/* 227CAC */ void fn_80227CAC(HSD_GObj* camera, float cstick_y); /* 227D38 */ UNK_RET fn_80227D38(UNK_PARAMS); /* 227EB0 */ UNK_RET fn_80227EB0(UNK_PARAMS); -/* 227FE0 */ UNK_RET fn_80227FE0(UNK_PARAMS); +/* 227FE0 */ void fn_80227FE0(HSD_GObj* camera, float cstick_x, + float cstick_y); /* 228124 */ UNK_RET fn_80228124(UNK_PARAMS); /* 228318 */ UNK_RET fn_80228318(UNK_PARAMS); /* 2283F0 */ UNK_RET fn_802283F0(UNK_PARAMS);