From 183b80eb8641aceab52f10931d271fe3f26f4ffa Mon Sep 17 00:00:00 2001 From: Thompson Lee Date: Fri, 12 Aug 2016 07:03:31 -0400 Subject: [PATCH] Better overall Mtx_Transpose() test case. --- test/3ds/source/main.cpp | 64 +++++++++++++++++++++++++++++++++++----- 1 file changed, 56 insertions(+), 8 deletions(-) diff --git a/test/3ds/source/main.cpp b/test/3ds/source/main.cpp index 30746ab..018509a 100644 --- a/test/3ds/source/main.cpp +++ b/test/3ds/source/main.cpp @@ -7,6 +7,7 @@ #include #include <3ds.h> #include +#include #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();