-
Notifications
You must be signed in to change notification settings - Fork 610
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
Closed
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3c28341
create matrix.h
Dragorn421 c0c879b
split into matrix.h + matrix_stack.h
Dragorn421 d1e3b4b
Merge branch 'main' into h_matrix
Dragorn421 c34bc60
fix include guard...
Dragorn421 d35d40d
fix retail bss
Dragorn421 8f40621
sys_matrix.h, skin_matrx.h, and bss
Dragorn421 131e4f1
Merge branch 'main' into h_matrix
Dragorn421 3301332
revert makefile -Werror=implicit-function-declaration
Dragorn421 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
#ifndef MATRIX_H | ||
#define MATRIX_H | ||
|
||
#include "ultra64.h" | ||
#include "z64math.h" | ||
|
||
struct GraphicsContext; | ||
|
||
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 | ||
|
||
void MtxConv_F2L(Mtx* m1, MtxF* m2); | ||
void MtxConv_L2F(MtxF* m1, Mtx* m2); | ||
|
||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#ifndef MATRIX_STACK_H | ||
#define MATRIX_STACK_H | ||
|
||
#include "ultra64.h" | ||
#include "z64math.h" | ||
|
||
struct GameState; | ||
struct GraphicsContext; | ||
|
||
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 | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
#include "global.h" | ||
#include "terminal.h" | ||
#include "matrix.h" | ||
|
||
// clang-format off | ||
MtxF sMtxFClear = { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd think it makes more sense for sys_matrix and skin_matrix to be separate headers. They are different systems that aren't really compatible with each other, being that one manipulates the matrix stack and the other does not.
Take for example eff_ss_kirakira, which opts to use solely skinmatrix operations instead of the matrix stack. It should probably just be able to include the specific matrix system it wants to use on its own
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do we gain from two separate headers?
I think we should split headers by feature rather than make basically one .h per .c, otherwise we'd end up with separate headers for the same thing (like matrix operations here) or a single header with way too much going on (z_actor.c)
Do note that sys_matrix.c is not only operations on the matrix stack, it also has operations that don't involve the stack:
I would be ok splitting the header between "matrix_stack.h" and "matrix_stackless.h" (?), but those
Matrix_
functions should then still go withSkinMatrix_
functions into "matrix_stackless.h" imoThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I am not suggesting one header per c file, but one header per system. These are completely different systems that dont work with each other. Whereas yes, z_actor.c contains a lot of different systems in it, so not all of it will be in the same header.
We gain the granularity to allow the programmer to pick which system they want to include into their file. I dont think you should have to include a bunch of unnecessary things because you want to work with the concept of "matrices" in general.
--
Sure, we could look into some scenario where the matrix stack operations in sys_matrix belong to a new system, and you would have functions like
MatrixStack_Init
,MatrixStack_Push
,MatrixStack_Pop
... etc. This would just be a huge improvement anyway, and let the user know point blank that they are messing with the stack.In this scenario we could also look into changing the
SkinMatrix_
system to justMatrix_
, along with the other generic matrix operations you mention in sys_matrix.c. This aligns with how things are used anyway-- skin matrix functions clearly started out as helpers for the skin skeleton system, but other devs found it useful outside of that system. It makes sense for us to name it generically to suit that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Though then we will have to resolve overlaps such as
Matrix_MtxFToMtx
andSkinMatrix_MtxFToNewMtx
. it may get messy 😅. But this is kinda my point of them being seperate systems with their own implementations.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also think it should be
sys_matrix.h
andskin_matrix.h
. To it seems like "matrix.h" and "matrix_stack.h" is the same thing, except with much worse names, because the names don't match the subsystems they correspond toThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean it's evidence but not the main reason, if the two files worked better with each other (or other factors like both being named sys_ or z_) then I would consider them more the same system. The main reason is that the code does not treat sys_matrix and skin_matrix as a unified whole.
For example,
Matrix_TranslateRotateZYX
andSkinMatrix_SetTranslateRotateZYX
theoretically do the same thing, but actually are pretty different. Not just matrix stack vs no stack, but also different parameter types and different implementations that share no code and probably have different rounding behavior (though I haven't checked). So I think it would be confusing to mix them too closelyThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Documentation and reverse-engineering I guess? Like I want to give readers the impression of "oh huh, there's two different matrix subsystems and they're often completely different, that's cool/horrifying/good-to-know".
I don't think it's less usable, if you're modding then you should probably just use sys_matrix and forget about skin_matrix entirely
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Think im personally bowing out of this conversation for now, cause I'd just be repeating myself. I've said what I want to say.
Would love to hear more thoughts than just us 3, if anyone else wants to give their opinion.
And lastly I'll say that if we don't come to a conclusion on this now, that we should go back to 1 header until we do decide
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright that's reasonable to me (though I dislike splitting the systems based on the .c. During development I could see a dev adding a matrix function they need to either file, whichever they come across first)
I'll switch to sys_matrix.h + skin_matrix.h
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personally I prefer if the headers were separated by their systems.
In this specific case the systems would be named after their C files, yes. That's because it happens to be organized this way. But this doesn't apply to most systems, like all the different systems present on z_actor.c.
So I agree with you dragorn that we should split headers by system, this just happens to more or less match the corresponding C files. Since there's currently no consensus on how to name the headers I think we should name them after the C files since that's the most obvious way, we can always rename them later.
Since you are concerned about usability then you could add a comment at the top of the header explaining the system a bit and how it differentiates to the other matrix header.
tl;dr: I prefer sys_matrix.h + skin_matrix.h and docs comment on each of them.