Better overall Mtx_Transpose() test case.

This commit is contained in:
Thompson Lee 2016-08-12 07:03:31 -04:00
parent 5ee2e08af9
commit 183b80eb86

View File

@ -7,6 +7,7 @@
#include <unistd.h>
#include <3ds.h>
#include <citro3d.h>
#include <float.h>
#include "vshader_shbin.h"
@ -842,17 +843,20 @@ void ortho_test()
void transpose_test()
{
C3D_Mtx modelView;
std::printf("\n");
consoleClear();
C3D_Mtx modelView, check;
Mtx_Identity(&modelView);
Mtx_Translate(&modelView, (rand() % 5) + 5.0f, (rand() % 5) + 5.0f, (rand() % 5) + 5.0f, true);
Mtx_Translate(&modelView, ((float)(rand() % 100)) + 5.0f, ((float)(rand() % 100)) + 5.0f, ((float)(rand() % 100)) + 5.0f, true);
Mtx_RotateX(&modelView, (float)(rand() % 180) * (acos(-1)/180.0f), true);
Mtx_RotateY(&modelView, (float)(rand() % 180) * (acos(-1)/180.0f), true);
Mtx_RotateZ(&modelView, (float)(rand() % 180) * (acos(-1)/180.0f), true);
Mtx_Copy(&check, &modelView);
std::printf("Random Translation:\n");
for (int i = 0; i < 16; i++)
{
std::printf("%.2f ", modelView.m[i]);
std::printf("%2.2f ", modelView.m[i]);
if (i % 4 == 3)
std::printf("\n");
}
@ -862,7 +866,7 @@ void transpose_test()
std::printf("Random Translation Transposed:\n");
for (int i = 0; i < 16; i++)
{
std::printf("%.2f ", modelView.m[i]);
std::printf("%2.2f ", modelView.m[i]);
if (i % 4 == 3)
std::printf("\n");
}
@ -872,12 +876,56 @@ void transpose_test()
std::printf("Rand-Trans Transposed Transposed:\n");
for (int i = 0; i < 16; i++)
{
std::printf("%.2f ", modelView.m[i]);
std::printf("%2.2f ", modelView.m[i]);
if (i % 4 == 3)
std::printf("\n");
}
bool transposeFailCheck = false;
for (int i = 0; i < 16; i++)
{
if (modelView.m[i] != check.m[i])
{
transposeFailCheck = true;
break;
}
}
bool transInvFailCheck = false;
Mtx_Inverse(&modelView);
Mtx_Transpose(&modelView);
Mtx_Transpose(&check);
Mtx_Inverse(&check);
for (int i = 0; i < 16; i++)
{
if (fabsf(modelView.m[i] - check.m[i]) > 0.001f)
{
std::printf("%f != %f\n", modelView.m[i], check.m[i]);
transInvFailCheck = true;
break;
}
}
std::printf("Transposed Inverse of RandMatrix:\n");
for (int i = 0; i < 16; i++)
{
std::printf("%2.2f ", modelView.m[i]);
if (i % 4 == 3)
std::printf("\n");
}
std::printf("Inverse Transposed of RandMatrix:\n");
for (int i = 0; i < 16; i++)
{
std::printf("%2.2f ", check.m[i]);
if (i % 4 == 3)
std::printf("\n");
}
std::printf("\n");
std::printf("Transpose(Transpose(A)) = A? %s\n", (transposeFailCheck ? "False" : "True"));
std::printf("Inv(Trans(A))=Trans(Inv(A))? %s\n", (transInvFailCheck ? "False" : "True"));
while(aptMainLoop())
{
gspWaitForVBlank();