Fixed mtx_transpose(), using (3-i).

This commit is contained in:
Thompson Lee 2016-08-12 06:46:23 -04:00
parent fbd3200abe
commit 1e57317575
2 changed files with 57 additions and 5 deletions

View File

@ -3,13 +3,13 @@
void Mtx_Transpose(C3D_Mtx* out) void Mtx_Transpose(C3D_Mtx* out)
{ {
float swap; float swap;
for (int i = 0; i < 4; i++) for (int i = 0; i <= 2; i++)
{ {
for (int j = i+1; j < 4; j++) for (int j = 2-i; j >= 0; j--)
{ {
swap = out->r[j].c[i]; swap = out->r[i].c[j];
out->r[j].c[i] = out->r[i].c[j]; out->r[i].c[j] = out->r[3-j].c[3-i];
out->r[i].c[j] = swap; out->r[3-j].c[3-i] = swap;
} }
} }
} }

View File

@ -840,6 +840,57 @@ void ortho_test()
C3D_RenderTargetDelete(tex); C3D_RenderTargetDelete(tex);
} }
void transpose_test()
{
C3D_Mtx modelView;
std::printf("\n");
Mtx_Identity(&modelView);
Mtx_Translate(&modelView, (rand() % 5) + 5.0f, (rand() % 5) + 5.0f, (rand() % 5) + 5.0f, true);
std::printf("Random Translation:\n");
for (int i = 0; i < 16; i++)
{
std::printf("%.2f ", modelView.m[i]);
if (i % 4 == 3)
std::printf("\n");
}
Mtx_Transpose(&modelView);
std::printf("Random Translation Transposed:\n");
for (int i = 0; i < 16; i++)
{
std::printf("%.2f ", modelView.m[i]);
if (i % 4 == 3)
std::printf("\n");
}
Mtx_Transpose(&modelView);
std::printf("Rand-Trans Transposed Transposed:\n");
for (int i = 0; i < 16; i++)
{
std::printf("%.2f ", modelView.m[i]);
if (i % 4 == 3)
std::printf("\n");
}
while(aptMainLoop())
{
gspWaitForVBlank();
hidScanInput();
u32 down = hidKeysDown();
if(down & (KEY_START|KEY_SELECT))
break;
}
}
typedef struct typedef struct
{ {
const char *name; const char *name;
@ -854,6 +905,7 @@ test_t tests[] =
{ "Mtx_Persp", persp_test, }, { "Mtx_Persp", persp_test, },
{ "Mtx_PerspStereo", stereo_test, }, { "Mtx_PerspStereo", stereo_test, },
{ "Mtx_Ortho", ortho_test, }, { "Mtx_Ortho", ortho_test, },
{ "Mtx_Transpose", transpose_test, },
}; };
const size_t num_tests = sizeof(tests)/sizeof(tests[0]); const size_t num_tests = sizeof(tests)/sizeof(tests[0]);