Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create matrix.h and matrix_stack.h #1975

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 2 additions & 51 deletions include/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -1072,21 +1072,7 @@ void Skin_Init(PlayState* play, Skin* skin, SkeletonHeader* skeletonHeader, Anim
void Skin_Free(PlayState* play, Skin* skin);
s32 Skin_ApplyAnimTransformations(Skin* skin, MtxF* limbMatrices, Actor* actor, s32 setTranslation);

void SkinMatrix_Vec3fMtxFMultXYZW(MtxF* mf, Vec3f* src, Vec3f* xyzDest, f32* wDest);
void SkinMatrix_Vec3fMtxFMultXYZ(MtxF* mf, Vec3f* src, Vec3f* dest);
void SkinMatrix_MtxFMtxFMult(MtxF* mfA, MtxF* mfB, MtxF* dest);
void SkinMatrix_GetClear(MtxF** mfp);
void SkinMatrix_MtxFCopy(MtxF* src, MtxF* dest);
s32 SkinMatrix_Invert(MtxF* src, MtxF* dest);
void SkinMatrix_SetScale(MtxF* mf, f32 x, f32 y, f32 z);
void SkinMatrix_SetRotateZYX(MtxF* mf, s16 x, s16 y, s16 z);
void SkinMatrix_SetTranslate(MtxF* mf, f32 x, f32 y, f32 z);
void SkinMatrix_SetTranslateRotateYXZScale(MtxF* dest, f32 scaleX, f32 scaleY, f32 scaleZ, s16 rotX, s16 rotY, s16 rotZ,
f32 translateX, f32 translateY, f32 translateZ);
void SkinMatrix_SetTranslateRotateZYX(MtxF* dest, s16 rotX, s16 rotY, s16 rotZ, f32 translateX, f32 translateY,
f32 translateZ);
Mtx* SkinMatrix_MtxFToNewMtx(GraphicsContext* gfxCtx, MtxF* src);
void SkinMatrix_SetRotateAxis(MtxF* mf, s16 angle, f32 axisX, f32 axisY, f32 axisZ);

void Sram_InitNewSave(void);
void Sram_InitDebugSave(void);
void Sram_OpenSave(SramContext* sramCtx);
Expand Down Expand Up @@ -1264,42 +1250,7 @@ void* SysCfb_GetFbEnd(void);

void Math3D_DrawSphere(PlayState* play, Sphere16* sph);
void Math3D_DrawCylinder(PlayState* play, Cylinder16* cyl);
void Matrix_Init(GameState* gameState);
void Matrix_Push(void);
void Matrix_Pop(void);
void Matrix_Get(MtxF* dest);
void Matrix_Put(MtxF* src);
void Matrix_Mult(MtxF* mf, u8 mode);
void Matrix_Translate(f32 x, f32 y, f32 z, u8 mode);
void Matrix_Scale(f32 x, f32 y, f32 z, u8 mode);
void Matrix_RotateX(f32 x, u8 mode);
void Matrix_RotateY(f32 y, u8 mode);
void Matrix_RotateZ(f32 z, u8 mode);
void Matrix_RotateZYX(s16 x, s16 y, s16 z, u8 mode);
void Matrix_TranslateRotateZYX(Vec3f* translation, Vec3s* rotation);
void Matrix_SetTranslateRotateYXZ(f32 translateX, f32 translateY, f32 translateZ, Vec3s* rot);
Mtx* Matrix_MtxFToMtx(MtxF* src, Mtx* dest);
#if OOT_DEBUG
Mtx* Matrix_ToMtx(Mtx* dest, const char* file, int line);
Mtx* Matrix_NewMtx(GraphicsContext* gfxCtx, const char* file, int line);
#else
Mtx* Matrix_ToMtx(Mtx* dest);
Mtx* Matrix_NewMtx(GraphicsContext* gfxCtx);
#endif
void Matrix_MultVec3f(Vec3f* src, Vec3f* dest);
void Matrix_MtxFCopy(MtxF* dest, MtxF* src);
void Matrix_MtxToMtxF(Mtx* src, MtxF* dest);
void Matrix_MultVec3fExt(Vec3f* src, Vec3f* dest, MtxF* mf);
void Matrix_Transpose(MtxF* mf);
void Matrix_ReplaceRotation(MtxF* mf);
void Matrix_MtxFToYXZRotS(MtxF* mf, Vec3s* rotDest, s32 flag);
void Matrix_MtxFToZYXRotS(MtxF* mf, Vec3s* rotDest, s32 flag);
void Matrix_RotateAxis(f32 angle, Vec3f* axis, u8 mode);
#if OOT_DEBUG
MtxF* Matrix_CheckFloats(MtxF* mf, const char* file, int line);
#endif
void Matrix_SetTranslateScaleMtx2(Mtx* mtx, f32 scaleX, f32 scaleY, f32 scaleZ, f32 translateX, f32 translateY,
f32 translateZ);

u64* SysUcode_GetUCodeBoot(void);
size_t SysUcode_GetUCodeBootSize(void);
u64* SysUcode_GetUCode(void);
Expand Down
6 changes: 0 additions & 6 deletions include/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,6 @@ extern struct GraphicsContext* __gfxCtx;
(void)0

#define GRAPH_ALLOC(gfxCtx, size) Graph_Alloc(gfxCtx, size)
#define MATRIX_TO_MTX(gfxCtx, file, line) Matrix_ToMtx(gfxCtx, file, line)
#define MATRIX_NEW(gfxCtx, file, line) Matrix_NewMtx(gfxCtx, file, line)
#define MATRIX_CHECK_FLOATS(mtx, file, line) Matrix_CheckFloats(mtx, file, line)
#define DMA_REQUEST_SYNC(ram, vrom, size, file, line) DmaMgr_RequestSyncDebug(ram, vrom, size, file, line)
#define DMA_REQUEST_ASYNC(req, ram, vrom, size, unk5, queue, msg, file, line) DmaMgr_RequestAsyncDebug(req, ram, vrom, size, unk5, queue, msg, file, line)
#define GAME_STATE_ALLOC(gameState, size, file, line) GameState_Alloc(gameState, size, file, line)
Expand Down Expand Up @@ -216,9 +213,6 @@ extern struct GraphicsContext* __gfxCtx;
(void)0

#define GRAPH_ALLOC(gfxCtx, size) ((void*)((gfxCtx)->polyOpa.d = (Gfx*)((u8*)(gfxCtx)->polyOpa.d - ALIGN16(size))))
#define MATRIX_TO_MTX(gfxCtx, file, line) Matrix_ToMtx(gfxCtx)
#define MATRIX_NEW(gfxCtx, file, line) Matrix_NewMtx(gfxCtx)
#define MATRIX_CHECK_FLOATS(mtx, file, line) (mtx)
#define DMA_REQUEST_SYNC(ram, vrom, size, file, line) DmaMgr_RequestSync(ram, vrom, size)
#define DMA_REQUEST_ASYNC(req, ram, vrom, size, unk5, queue, msg, file, line) DmaMgr_RequestAsync(req, ram, vrom, size, unk5, queue, msg)
#define GAME_STATE_ALLOC(gameState, size, file, line) THA_AllocTailAlign16(&(gameState)->tha, size)
Expand Down
25 changes: 25 additions & 0 deletions include/skin_matrix.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef MATRIX_H
#define MATRIX_H
Comment on lines +1 to +2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

include guard name doesn't match


#include "ultra64.h"
#include "z64math.h"

struct GraphicsContext;

void SkinMatrix_Vec3fMtxFMultXYZW(MtxF* mf, Vec3f* src, Vec3f* xyzDest, f32* wDest);
void SkinMatrix_Vec3fMtxFMultXYZ(MtxF* mf, Vec3f* src, Vec3f* dest);
void SkinMatrix_MtxFMtxFMult(MtxF* mfA, MtxF* mfB, MtxF* dest);
void SkinMatrix_GetClear(MtxF** mfp);
void SkinMatrix_MtxFCopy(MtxF* src, MtxF* dest);
s32 SkinMatrix_Invert(MtxF* src, MtxF* dest);
void SkinMatrix_SetScale(MtxF* mf, f32 x, f32 y, f32 z);
void SkinMatrix_SetRotateZYX(MtxF* mf, s16 x, s16 y, s16 z);
void SkinMatrix_SetTranslate(MtxF* mf, f32 x, f32 y, f32 z);
void SkinMatrix_SetTranslateRotateYXZScale(MtxF* dest, f32 scaleX, f32 scaleY, f32 scaleZ, s16 rotX, s16 rotY, s16 rotZ,
f32 translateX, f32 translateY, f32 translateZ);
void SkinMatrix_SetTranslateRotateZYX(MtxF* dest, s16 rotX, s16 rotY, s16 rotZ, f32 translateX, f32 translateY,
f32 translateZ);
Mtx* SkinMatrix_MtxFToNewMtx(struct GraphicsContext* gfxCtx, MtxF* src);
void SkinMatrix_SetRotateAxis(MtxF* mf, s16 angle, f32 axisX, f32 axisY, f32 axisZ);

#endif
79 changes: 79 additions & 0 deletions include/sys_matrix.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#ifndef MATRIX_STACK_H
#define MATRIX_STACK_H
Comment on lines +1 to +2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto


#include "ultra64.h"
#include "z64math.h"

struct GameState;
struct GraphicsContext;

// Matrix stack operations

typedef enum {
/* 0 */ MTXMODE_NEW, // generates a new matrix
/* 1 */ MTXMODE_APPLY // applies transformation to the current matrix
} MatrixMode;

void Matrix_Init(struct GameState* gameState);
void Matrix_Push(void);
void Matrix_Pop(void);
void Matrix_Get(MtxF* dest);
void Matrix_Put(MtxF* src);
void Matrix_Mult(MtxF* mf, u8 mode);
void Matrix_Translate(f32 x, f32 y, f32 z, u8 mode);
void Matrix_Scale(f32 x, f32 y, f32 z, u8 mode);
void Matrix_RotateX(f32 x, u8 mode);
void Matrix_RotateY(f32 y, u8 mode);
void Matrix_RotateZ(f32 z, u8 mode);
void Matrix_RotateZYX(s16 x, s16 y, s16 z, u8 mode);
void Matrix_TranslateRotateZYX(Vec3f* translation, Vec3s* rotation);
void Matrix_SetTranslateRotateYXZ(f32 translateX, f32 translateY, f32 translateZ, Vec3s* rot);
void Matrix_MultVec3f(Vec3f* src, Vec3f* dest);
void Matrix_ReplaceRotation(MtxF* mf);
void Matrix_RotateAxis(f32 angle, Vec3f* axis, u8 mode);

#if OOT_DEBUG

Mtx* Matrix_ToMtx(Mtx* dest, const char* file, int line);
#define MATRIX_TO_MTX(gfxCtx, file, line) Matrix_ToMtx(gfxCtx, file, line)

Mtx* Matrix_NewMtx(struct GraphicsContext* gfxCtx, const char* file, int line);
#define MATRIX_NEW(gfxCtx, file, line) Matrix_NewMtx(gfxCtx, file, line)

#else

Mtx* Matrix_ToMtx(Mtx* dest);
#define MATRIX_TO_MTX(gfxCtx, file, line) Matrix_ToMtx(gfxCtx)

Mtx* Matrix_NewMtx(struct GraphicsContext* gfxCtx);
#define MATRIX_NEW(gfxCtx, file, line) Matrix_NewMtx(gfxCtx)

#endif

// Operations not involving the matrix stack

extern Mtx gMtxClear;
extern MtxF gMtxFClear;

Mtx* Matrix_MtxFToMtx(MtxF* src, Mtx* dest);
void Matrix_MtxFCopy(MtxF* dest, MtxF* src);
void Matrix_MtxToMtxF(Mtx* src, MtxF* dest);
void Matrix_MultVec3fExt(Vec3f* src, Vec3f* dest, MtxF* mf);
void Matrix_Transpose(MtxF* mf);
void Matrix_MtxFToYXZRotS(MtxF* mf, Vec3s* rotDest, s32 flag);
void Matrix_MtxFToZYXRotS(MtxF* mf, Vec3s* rotDest, s32 flag);
void Matrix_SetTranslateScaleMtx2(Mtx* mtx, f32 scaleX, f32 scaleY, f32 scaleZ, f32 translateX, f32 translateY,
f32 translateZ);

#if OOT_DEBUG

MtxF* Matrix_CheckFloats(MtxF* mf, const char* file, int line);
#define MATRIX_CHECK_FLOATS(mtx, file, line) Matrix_CheckFloats(mtx, file, line)

#else

#define MATRIX_CHECK_FLOATS(mtx, file, line) (mtx)

#endif

#endif
2 changes: 0 additions & 2 deletions include/variables.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,6 @@ extern u8 gBossMarkState;

extern s32 gScreenWidth;
extern s32 gScreenHeight;
extern Mtx gMtxClear;
extern MtxF gMtxFClear;
#if OOT_DEBUG
extern u32 gIsCtrlr2Valid;
#endif
Expand Down
7 changes: 2 additions & 5 deletions include/z64.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@
#include "sys_math.h"
#include "sys_math3d.h"
#include "fp_math.h"
#include "sys_matrix.h"
#include "skin_matrix.h"

#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 240
Expand Down Expand Up @@ -400,11 +402,6 @@ typedef struct DebugDispObject {
/* 0x28 */ struct DebugDispObject* next;
} DebugDispObject; // size = 0x2C

typedef enum {
/* 0 */ MTXMODE_NEW, // generates a new matrix
/* 1 */ MTXMODE_APPLY // applies transformation to the current matrix
} MatrixMode;

typedef struct StackEntry {
/* 0x00 */ struct StackEntry* next;
/* 0x04 */ struct StackEntry* prev;
Expand Down
6 changes: 6 additions & 0 deletions src/code/main.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// 1) The block number for gAppNmiBufferPtr must be <= 193
#pragma increment_block_number 130

#include "global.h"
#include "terminal.h"

Expand All @@ -7,6 +10,9 @@ s32 gScreenWidth = SCREEN_WIDTH;
s32 gScreenHeight = SCREEN_HEIGHT;
u32 gSystemHeapSize = 0;

// 2) The block number for gIrqMgr must be <= 241 and > gPadMgr's
#pragma increment_block_number 40

PreNmiBuff* gAppNmiBufferPtr;
Scheduler gScheduler;
PadMgr gPadMgr;
Expand Down
1 change: 1 addition & 0 deletions src/code/sys_matrix.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "global.h"
#include "sys_matrix.h"

// clang-format off
Mtx gMtxClear = gdSPDefMtx(
Expand Down
2 changes: 1 addition & 1 deletion src/code/z_camera.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

// For retail BSS ordering, the block number of D_8015BD7C
// must be between 88 and 123 inclusive.
#pragma increment_block_number 26
#pragma increment_block_number 7

s16 Camera_RequestSettingImpl(Camera* camera, s16 requestedSetting, s16 flags);
s32 Camera_RequestModeImpl(Camera* camera, s16 requestedMode, u8 forceModeChange);
Expand Down
4 changes: 3 additions & 1 deletion src/code/z_demo.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@ void* sUnusedEntranceCsList[] = {
gDekuTreeIntroCs, gJabuJabuIntroCs, gDcOpeningCs, gMinuetCs, gIceCavernSerenadeCs, gTowerBarrierCs,
};

#pragma increment_block_number 248
// Because the other bss variables are already declared (in header files), this directive only affects the block number
// of sReturnToCamId and sQuakeIndex. For matching, their block numbers should come after gCamAtPointAppliedFrame's.
#pragma increment_block_number 210

// Stores the frame the relevant cam data was last applied on
u16 gCamAtSplinePointsAppliedFrame;
Expand Down
6 changes: 4 additions & 2 deletions src/code/z_kankyo.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include "ultra64/ultratypes.h"

#include "global.h"
#include "ultra64.h"
#include "terminal.h"
Expand All @@ -10,7 +12,7 @@
// For retail BSS ordering, the block number of sLensFlareUnused must be lower
// than the extern variables declared in the header (e.g. gLightningStrike)
// while the block number of sNGameOverLightNode must be higher.
#pragma increment_block_number 70
#pragma increment_block_number 160

typedef enum {
/* 0x00 */ LIGHTNING_BOLT_START,
Expand Down Expand Up @@ -218,7 +220,7 @@ s16 sSunDepthTestY;
// These variables could be moved farther down in the file to reduce the amount
// of block number padding here, but currently this causes BSS ordering issues
// for debug.
#pragma increment_block_number 227
#pragma increment_block_number 100

LightNode* sNGameOverLightNode;
LightInfo sNGameOverLightInfo;
Expand Down
3 changes: 3 additions & 0 deletions src/code/z_player_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,9 @@ Gfx gCullFrontDList[] = {
gsSPEndDisplayList(),
};

// The block number for sCurBodyPartPos must be <= 251
#pragma increment_block_number 100

Vec3f* sCurBodyPartPos;
s32 sDListsLodOffset;
Vec3f sGetItemRefPos;
Expand Down
1 change: 1 addition & 0 deletions src/code/z_skin_matrix.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "global.h"
#include "terminal.h"
#include "skin_matrix.h"

// clang-format off
MtxF sMtxFClear = {
Expand Down
2 changes: 1 addition & 1 deletion src/overlays/actors/ovl_Fishing/z_fishing.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "terminal.h"

// For retail BSS ordering, the block number of sStreamSfxProjectedPos must be 0.
#pragma increment_block_number 182
#pragma increment_block_number 180

#define FLAGS ACTOR_FLAG_4

Expand Down