more camera.c functions, clean up, etc

This commit is contained in:
zestydevy 2023-05-02 19:54:23 -05:00
parent 8bc2694e24
commit 3cf7517632
9 changed files with 514 additions and 592 deletions

751
ctx.c

File diff suppressed because it is too large Load Diff

View File

@ -6,11 +6,14 @@
#define MAX_PLAYERS 4
#define OS_K0_TO_PHYSICAL(x) (u32)(((char *)(x)-0x80000000))
#define OS_PHYSICAL_TO_K0(x) (void *)(((u32)(x)+0x80000000))
typedef struct {
f32 x;
f32 y;
f32 z;
} vec3f;
} HuVec3F;
typedef struct objectt {
/*0x00*/ struct objectt *prev;
@ -19,9 +22,9 @@ typedef struct objectt {
/*0x09*/ s8 unk9;
/*0x0A*/ u16 unkA;
/*0x0C*/ vec3f coords;
/*0x0C*/ HuVec3F coords;
// Three vec3f groups (Scale?, Rotation?, Position?)
// Three HuVec3F groups (Scale?, Rotation?, Position?)
f32 unk18; // Rotation?
f32 unk1C;
f32 unk20;
@ -53,7 +56,7 @@ struct objectIndirectt {
void *unk14;
// Three vec3f groups (Scale?, Rotation?, Position?)
// Three HuVec3F groups (Scale?, Rotation?, Position?)
f32 unk18;
f32 unk1C;
f32 unk20;

View File

@ -1,85 +1,251 @@
#include "common.h"
#include "common_structs.h"
#include <PR/gbi.h>
typedef struct unk_struct {
f32 unk0;
f32 unk4;
f32 unk8;
f32 unkC;
f32 unk10;
f32 unk14;
f32 unk18;
f32 unk1C;
f32 unk20;
f32 unk24;
f32 unk28;
f32 unk2C;
f32 unk30;
char unk_34[0x1C];
f32 unk_50;
char unk_44[0x1DC];
} unk_struct;
#define ASPECT_RATIO (4.0f / 3.0f)
#define SCREEN_WIDTH 320.0f
#define SCREEN_HEIGHT 240.0f
#define SCREEN_WIDTH_CENTER SCREEN_WIDTH / 2.0f
#define SCREEN_HEIGHT_CENTER SCREEN_HEIGHT / 2.0f
extern unk_struct* D_800A0550_A1150;
typedef f32 Matrix4f[4][4];
void guLookAt(Mtx *m,
float xEye, float yEye, float zEye,
float xAt, float yAt, float zAt,
float xUp, float yUp, float zUp );
f32 func_8008E3F0_8EFF0(f32);
f32 func_8008EF20_8FB20(f32);
typedef struct
{
f32 x;
f32 y;
f32 z;
f32 w;
} HuVec4F;
typedef struct
{
Mtx perspMtx;
Mtx lookAtMtx;
} HuCamMtxs;
typedef struct {
/* 0x000 */ u16 perspNorm;
/* 0x002 */ char pad2[2];
/* 0x004 */ f32 unk4;
/* 0x008 */ f32 unk8;
/* 0x00C */ f32 unkC;
/* 0x010 */ HuVec3F pos;
/* 0x01C */ HuVec3F at;
/* 0x028 */ HuVec3F up;
/* 0x034 */ HuVec3F screenScale;
/* 0x040 */ HuVec3F screenPos;
/* 0x04C */ s32 unk4C;
/* 0x050 */ f32 fov;
/* 0x054 */ f32 near;
/* 0x058 */ f32 far;
/* 0x05C */ f32 unk5C;
/* 0x060 */ Vp viewports[3];
/* 0x090 */ f32 screenLeft;
/* 0x094 */ f32 screenTop;
/* 0x098 */ f32 screenRight;
/* 0x09C */ f32 screenBottom;
/* 0x0A0 */ s32 unkA0;
/* 0x0A4 */ s32 unkA4;
/* 0x0A8 */ s32 unkA8;
/* 0x0AC */ s32 unkAC;
/* 0x0B0 */ HuCamMtxs mtxs[3];
} HuCamera;
extern HuCamera* gCameraList;
typedef f32 HuMtx4F[4][4];
f32 HuMathCos(f32);
f32 HuMathSin(f32);
void guLookAtF(f32 mf[4][4], f32 xEye, f32 yEye, f32 zEye, f32 xAt, f32 yAt, f32 zAt, f32 xUp, f32 yUp, f32 zUp);
INCLUDE_ASM(s32, "camera", Hu3DCamInit);
INCLUDE_ASM(s32, "camera", func_800123F4_12FF4);
extern u8 D_800D2008;
extern s16 D_800D418E;
INCLUDE_ASM(s32, "camera", func_80012408_13008);
INCLUDE_ASM(s32, "camera", func_8001247C_1307C);
INCLUDE_ASM(s32, "camera", func_800124BC_130BC);
INCLUDE_ASM(s32, "camera", func_80012508_13108);
INCLUDE_ASM(s32, "camera", func_80012564_13164);
INCLUDE_ASM(s32, "camera", func_80012640_13240);
INCLUDE_ASM(s32, "camera", func_800127C4_133C4);
INCLUDE_ASM(s32, "camera", func_80012888_13488);
INCLUDE_ASM(s32, "camera", func_800128BC_134BC);
INCLUDE_ASM(s32, "camera", func_800128EC_134EC);
void func_8001291C_1351C(s16 index, vec3f *arg1, vec3f *arg2) { //Convert3Dto2D
Matrix4f sp28;
f32 temp_f20;
f32 temp_f22;
f32 temp_f24;
f32 temp_f28;
f32 temp_f2;
f32 temp_f30;
unk_struct *temp_s0;
temp_s0 = &D_800A0550_A1150[index];
guLookAtF(sp28, temp_s0->unk10, temp_s0->unk14, temp_s0->unk18, temp_s0->unk1C, temp_s0->unk20, temp_s0->unk24, temp_s0->unk28, temp_s0->unk2C, temp_s0->unk30);
temp_f30 = arg1->x;
temp_f28 = arg1->y;
temp_f2 = arg1->z;
temp_f30 -= temp_s0->unk10;
temp_f28 -= temp_s0->unk14;
temp_f2 -= temp_s0->unk18;
temp_f24 = ((temp_f30 * sp28[0][0]) + (temp_f28 * sp28[1][0])) + (temp_f2 * sp28[2][0]);
temp_f22 = ((temp_f30 * sp28[0][1]) + (temp_f28 * sp28[1][1])) + (temp_f2 * sp28[2][1]);
temp_f20 = ((temp_f30 * sp28[0][2]) + (temp_f28 * sp28[1][2])) + (temp_f2 * sp28[2][2]);
temp_f30 = func_8008EF20_8FB20(temp_s0->unk_50 / 2.0f) / func_8008E3F0_8EFF0(temp_s0->unk_50 / 2.0f) * temp_f20 * (4.0f / 3.0f);
temp_f28 = (func_8008EF20_8FB20(temp_s0->unk_50 / 2.0f) / func_8008E3F0_8EFF0(temp_s0->unk_50 / 2.0f)) * temp_f20;
arg2->x = (temp_f24 * (160.0f / (-temp_f30))) + 160.0f;
arg2->y = ((temp_f22 * (120.0f / temp_f28)) + 120.0f);
void func_800123F4_12FF4(void)
{
D_800D418E = D_800D2008;
}
INCLUDE_ASM(s32, "camera", func_80012B14_13714);
void Hu3DCamSetPositionOrientation(s16 camIndex, HuVec3F * pos, HuVec3F * at, HuVec3F * up)
{
HuCamera * camera = &gCameraList[camIndex];
camera->pos = *pos;
camera->at = *at;
camera->up = *up;
}
void Hu3DCamSetPerspective(s16 camIndex, f32 fov, f32 near, f32 far)
{
HuCamera * camera = &gCameraList[camIndex];
camera->fov = fov;
camera->near = near;
camera->far = far;
camera->perspNorm = 1;
}
void func_800124BC_130BC(s16 camIndex, HuVec4F * arg1)
{
HuCamera * camera = &gCameraList[camIndex];
camera->screenLeft = arg1->x;
camera->screenTop = arg1->y;
camera->screenRight = arg1->z;
camera->screenBottom = arg1->w;
}
void func_80012508_13108(s16 camIndex, HuVec3F * arg1, HuVec3F * arg2)
{
HuCamera * camera = &gCameraList[camIndex];
camera->screenScale = *arg1;
camera->screenPos = *arg2;
}
void Hu3DCamUpdateMtx(s16 camIndex)
{
HuCamera * camera;
HuCamMtxs * mtxs;
camera = &gCameraList[camIndex];
mtxs = &camera->mtxs[D_800D418E];
guPerspective(&mtxs->perspMtx, &camera->perspNorm, camera->fov, (SCREEN_WIDTH / SCREEN_HEIGHT), camera->near, camera->far, 1.0f);
guLookAt(&mtxs->lookAtMtx, camera->pos.x, camera->pos.y, camera->pos.z, camera->at.x, camera->at.y, camera->at.z, camera->up.x, camera->up.y, camera->up.z);
}
void func_80012640_13240(s16 camIndex, Gfx ** dispList)
{
HuCamMtxs * camMtx;
HuCamera * camera;
camera = &gCameraList[camIndex];
camMtx = &camera->mtxs[D_800D418E];
camera->viewports[D_800D418E].vp.vscale[0] = (s16) camera->screenScale.x;
camera->viewports[D_800D418E].vp.vscale[1] = (s16) camera->screenScale.y;
camera->viewports[D_800D418E].vp.vscale[2] = (s16) camera->screenScale.z;
camera->viewports[D_800D418E].vp.vtrans[0] = (s16) camera->screenPos.x;
camera->viewports[D_800D418E].vp.vtrans[1] = (s16) camera->screenPos.y;
camera->viewports[D_800D418E].vp.vtrans[2] = (s16) camera->screenPos.z;
gSPViewport((*dispList)++, &camera->viewports[D_800D418E].vp);
gSPPerspNormalize((*dispList)++, camera->perspNorm);
gSPMatrix((*dispList)++, osVirtualToPhysical(&camMtx->perspMtx), G_MTX_PROJECTION | G_MTX_LOAD);
gSPMatrix((*dispList)++, OS_PHYSICAL_TO_K0(&camMtx->lookAtMtx), G_MTX_LOAD);
}
void func_800127C4_133C4(s16 camIndex, Gfx ** dispList) {
HuCamera * camera = &gCameraList[camIndex];
gDPSetScissor((*dispList)++, G_SC_NON_INTERLACE, camera->screenLeft, camera->screenTop, camera->screenRight, camera->screenBottom);
}
void func_80012888_13488(s16 camIndex, s32 arg1, s32 arg2)
{
HuCamera * camera = &gCameraList[camIndex];
camera->unkA0 = arg1;
camera->unkA4 = arg2;
}
void func_800128BC_134BC(s16 camIndex, s32 arg1)
{
gCameraList[camIndex].unkA8 = arg1;
}
void func_800128EC_134EC(s16 camIndex, s32 arg1)
{
gCameraList[camIndex].unkAC = arg1;
}
void Hu3DCam3DToScreen(s16 camIndex, HuVec3F * worldPos, HuVec3F * outPos)
{
f32 x;
f32 y;
f32 z;
f32 projectedX;
f32 projectedY;
f32 projectedZ;
HuCamera * camera;
HuMtx4F viewMtx;
camera = &gCameraList[camIndex];
guLookAtF(
viewMtx,
camera->pos.x,
camera->pos.y,
camera->pos.z,
camera->at.x,
camera->at.y,
camera->at.z,
camera->up.x,
camera->up.y,
camera->up.z
);
x = worldPos->x;
y = worldPos->y;
z = worldPos->z;
x -= camera->pos.x;
y -= camera->pos.y;
z -= camera->pos.z;
projectedX = ((x * viewMtx[0][0]) + (y * viewMtx[1][0])) + (z * viewMtx[2][0]);
projectedY = ((x * viewMtx[0][1]) + (y * viewMtx[1][1])) + (z * viewMtx[2][1]);
projectedZ = ((x * viewMtx[0][2]) + (y * viewMtx[1][2])) + (z * viewMtx[2][2]);
x = HuMathSin(camera->fov / 2.0f) / HuMathCos(camera->fov / 2.0f) * projectedZ * ASPECT_RATIO;
y = (HuMathSin(camera->fov / 2.0f) / HuMathCos(camera->fov / 2.0f)) * projectedZ;
outPos->x = (projectedX * (SCREEN_WIDTH_CENTER / (-x))) + SCREEN_WIDTH_CENTER;
outPos->y = ((projectedY * (SCREEN_HEIGHT_CENTER / y)) + SCREEN_HEIGHT_CENTER);
}
void func_80012B14_13714(s16 camIndex, HuVec3F * worldPos, HuVec3F * outPos)
{
f32 x;
f32 y;
f32 z;
f32 projectedX;
f32 projectedY;
f32 projectedZ;
HuCamera * camera;
HuMtx4F viewMtx;
f32 f2;
f32 f4;
camera = &gCameraList[camIndex];
guLookAtF(
viewMtx,
camera->pos.x,
camera->pos.y,
camera->pos.z,
camera->at.x,
camera->at.y,
camera->at.z,
camera->up.x,
camera->up.y,
camera->up.z
);
x = worldPos->x;
y = worldPos->y;
z = worldPos->z;
x -= camera->pos.x;
y -= camera->pos.y;
z -= camera->pos.z;
projectedX = ((x * viewMtx[0][0]) + (y * viewMtx[1][0])) + (z * viewMtx[2][0]);
projectedY = ((x * viewMtx[0][1]) + (y * viewMtx[1][1])) + (z * viewMtx[2][1]);
projectedZ = ((x * viewMtx[0][2]) + (y * viewMtx[1][2])) + (z * viewMtx[2][2]);
x = HuMathSin(camera->fov / 2.0f) / HuMathCos(camera->fov / 2.0f) * projectedZ * (camera->screenScale.x / camera->screenScale.y);
y = (HuMathSin(camera->fov / 2.0f) / HuMathCos(camera->fov / 2.0f)) * projectedZ;
f2 = camera->screenPos.x / 4.0f;
outPos->x = (projectedX * (f2 / (-x))) + f2;
f4 = camera->screenPos.y / 4.0f;
outPos->y = ((projectedY * (f4 / y)) + f4);
}
INCLUDE_ASM(s32, "camera", func_80012D0C_1390C);

View File

@ -44,18 +44,18 @@ extern f32 D_800CE1C8;
extern struct process *D_800D0448;
extern u8 D_800D09A8;
extern vec3f D_800D138C;
extern HuVec3F D_800D138C;
extern struct process *D_800D170C;
extern u8 D_800D1710;
extern s16 D_800D1F36;
extern u16 D_800D4082;
extern vec3f D_800D54F8[];
extern HuVec3F D_800D54F8[];
extern u16 D_800D6A56;
extern vec3f D_800D6ABC;
extern vec3f D_800D6AE0[];
extern HuVec3F D_800D6ABC;
extern HuVec3F D_800D6AE0[];
extern u16 D_800A190C_A250C;
extern u16 D_800A190E_A250E;

View File

@ -22,7 +22,6 @@ void func_800098FC_A4FC(void)
s16 i;
s32 temp_v0_3;
s32 temp_v0_5;
s32 temp_v0_7;
u16 var_a2;
s8 temp_v0_2;
s8 temp_v0_4;

View File

@ -67,8 +67,8 @@ void func_80105C64_3D8D54(s32 arg0, s32 arg1, unkStruct01* arg2) {
func_800EB708(arg0, arg1, arg2);
temp_f20 = func_800D76D0(arg2) + 15.0f;
arg2->unk_00 = func_8008EF20_8FB20(temp_f20);
arg2->unk_08 = func_8008E3F0_8EFF0(temp_f20);
arg2->unk_00 = HuMathSin(temp_f20);
arg2->unk_08 = HuMathCos(temp_f20);
}
INCLUDE_ASM(s32, "overlays/board_gate_guy/3D8AC0", func_80105CC0_3D8DB0);

View File

@ -14,7 +14,7 @@ typedef struct unkStruct01 {
} unkStruct01;
typedef struct unkStruct02 {
vec3f unk_00;
HuVec3F unk_00;
char unk_0C[4];
} unkStruct02;
@ -36,7 +36,7 @@ unkStruct02* unk_8C;
typedef struct unkStruct04 {
char unk_00[0x0C];
vec3f unk_0C;
HuVec3F unk_0C;
} unkStruct04;
typedef struct unkStruct05 {
@ -90,8 +90,8 @@ void func_800E9D9C(void);
void func_800E9F4C(s32, s8*, s8*);
void func_800EA760(void);
void func_800ECD0C(s32, s8, s8);
f32 func_8008E3F0_8EFF0(f32);
f32 func_8008EF20_8FB20(f32);
f32 HuMathCos(f32);
f32 HuMathSin(f32);
f32 func_800D76D0(void*);
void func_800EB708(s32, s32, unkStruct01*);
void * HuMemMemoryAlloc(struct heap_node * heap, s32 size);
@ -111,7 +111,7 @@ void func_8001C8E4_1D4E4(s16, s32);
void* func_800D8010(s32, s32);
void func_800D8944(void*);
void func_800D8F0C(void*);
void func_80089A20_8A620(vec3f*, s32);
void func_80089A20_8A620(HuVec3F*, s32);
void func_800D8E88(void);
s16 func_800F3750(void);
void* func_800F375C(s32);

View File

@ -22,6 +22,10 @@ HuWipeFadeIn = 0x80061FE8;
HuWipeFadeOut = 0x80062050;
HuWipeStatGet = 0x800620BC;
Hu3DCamInit = 0x80012220;
Hu3DCamSetPositionOrientation = 0x80012408;
Hu3DCamSetPerspective = 0x8001247C;
Hu3DCamUpdateMtx = 0x80012564;
Hu3DCam3DToScreen = 0x8001291C;
Hu3DAnimInit = 0x8001FE20;
HuObjInit = 0x80047160;
@ -98,6 +102,9 @@ HuPrcFreeMem = 0x8004F26C;
HuGetPadInserted = 0x8000985C;
HuMathCos = 0x8008E3F0;
HuMathSin = 0x8008EF20;
setjmp = 0x80066500;
longjmp = 0x80066564;
@ -366,6 +373,8 @@ sqrt = 0x800880D0;
ldiv = 0x80086C40;
lldiv = 0x80086CC4;
gCameraList = 0x800A0550;
gHuMemIsDirty = 0x800A08A0;
gArchiveRomAddr = 0x800ABFC0;
@ -376,6 +385,7 @@ gArchiveDirCountCopy = 0x800ABFD0;
gArchiveTblAddrCopy = 0x800ABFD4;
gArchive = 0x800ABFE0;
gLastMallocBlock = 0x800D03F4;
gFreeFunc = 0x800D135C;
gLastFreedBlock = 0x800D1238;
@ -435,6 +445,9 @@ _Ldtob = 0x80083FA0;
_Ldunscale = 0x800843EC;
_Genld = 0x80084484;
guPerspectiveF = 0x8007AE60;
guPerspective = 0x8007B010;
guNormalize = 0x80082B00;
gCurrentPlayerIndex = 0x800CD067;
guLookAtF = 0x80088210;
guLookAtF = 0x80088210;
guLookAt = 0x80079800;

View File

@ -13470,7 +13470,7 @@ Symbol table '.symtab' contains 34600 entries:
13466: 8010e3f0 0 NOTYPE GLOBAL DEFAULT 118 func_8010E3F0_4D7DA0
13467: 8010d1d8 0 NOTYPE GLOBAL DEFAULT 30 func_8010D1D8_1CBAB8
13468: 8010c328 0 NOTYPE GLOBAL DEFAULT 47 func_8010C328_239398
13469: 8008e3f0 0 NOTYPE GLOBAL DEFAULT 3 func_8008E3F0_8EFF0
13469: 8008e3f0 0 NOTYPE GLOBAL DEFAULT 3 HuMathCos
13470: 8010ca78 0 NOTYPE GLOBAL DEFAULT 20 L8010CA78_176748
13471: 800e4ba4 0 NOTYPE GLOBAL DEFAULT ABS func_800E4BA4
13472: 8010beb0 0 NOTYPE GLOBAL DEFAULT 127 func_8010BEB0_508110