matrix debug string stuff

This commit is contained in:
wgroeneveld 2020-07-09 20:44:25 +02:00
parent 0965f80e99
commit fa4aa10d14
2 changed files with 27 additions and 1 deletions

View File

@ -9,6 +9,8 @@
#include <libgba-sprite-engine/math.h> #include <libgba-sprite-engine/math.h>
#include <libgba-sprite-engine/vectorfx.h> #include <libgba-sprite-engine/vectorfx.h>
#include <cstdio>
#ifdef CODE_COMPILED_AS_PART_OF_TEST #ifdef CODE_COMPILED_AS_PART_OF_TEST
#include <libgba-sprite-engine/gba/tonc_math_stub.h> #include <libgba-sprite-engine/gba/tonc_math_stub.h>
#else #else
@ -19,6 +21,13 @@ class MatrixFx {
private: private:
FIXED m[MATRIX_DIMENSION]; FIXED m[MATRIX_DIMENSION];
inline std::string mstr(int index) {
char buffer[30];
snprintf(buffer, 30, "%4.3f", rnd(fx2float(m[index])));
std::string strObj4(buffer);
return strObj4;
}
public: public:
inline static MatrixFx zero() { return MatrixFx(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); } inline static MatrixFx zero() { return MatrixFx(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); }
@ -96,6 +105,18 @@ public:
m[14] = m43; m[14] = m43;
m[15] = m44; m[15] = m44;
} }
std::string to_string_m1() {
return "(" + mstr(0) + "," + mstr(1) + "," + mstr(2) + "," + mstr(3) +")";
}
std::string to_string_m2() {
return "(" + mstr(4) + "," + mstr(5) + "," + mstr(6) + "," + mstr(7) +")";
}
std::string to_string_m3() {
return "(" + mstr(8) + "," + mstr(9) + "," + mstr(10) + "," + mstr(11) +")";
}
std::string to_string_m4() {
return "(" + mstr(12) + "," + mstr(13) + "," + mstr(14) + "," + mstr(15) +")";
}
inline static VectorFx transformCoordinates(const VectorFx &vector, const MatrixFx &transformation) { inline static VectorFx transformCoordinates(const VectorFx &vector, const MatrixFx &transformation) {
FIXED x = fxmul(vector.x(), transformation.mAt(0)) + fxmul(vector.y(), transformation.mAt(4)) + fxmul(vector.z(), transformation.mAt(8) + transformation.mAt(12)); FIXED x = fxmul(vector.x(), transformation.mAt(0)) + fxmul(vector.y(), transformation.mAt(4)) + fxmul(vector.z(), transformation.mAt(8) + transformation.mAt(12));

View File

@ -172,12 +172,17 @@ void GBAEngine::render() {
auto worldMatrix = MatrixFx::rotationYawPitchRoll(mesh->roty(), mesh->rotx(), mesh->rotz()) * MatrixFx::translation(mesh->position()); auto worldMatrix = MatrixFx::rotationYawPitchRoll(mesh->roty(), mesh->rotx(), mesh->rotz()) * MatrixFx::translation(mesh->position());
auto transformMatrix = worldMatrix * viewMatrix * projectionMatrix; auto transformMatrix = worldMatrix * viewMatrix * projectionMatrix;
TextStream::instance().setText(transformMatrix.to_string_m1(), 1, 1);
TextStream::instance().setText(transformMatrix.to_string_m2(), 2, 1);
TextStream::instance().setText(transformMatrix.to_string_m3(), 3, 1);
TextStream::instance().setText(transformMatrix.to_string_m4(), 4, 1);
int i = 0; int i = 0;
for(auto& vertex : mesh->vertices()) { for(auto& vertex : mesh->vertices()) {
auto projectedPoint = project(*vertex.get(), transformMatrix).toInt(); auto projectedPoint = project(*vertex.get(), transformMatrix).toInt();
plotPixel(projectedPoint.x(), projectedPoint.y(), 1); plotPixel(projectedPoint.x(), projectedPoint.y(), 1);
TextStream::instance().setText(std::to_string(i) + ":" + projectedPoint.to_string(), i, 1); //TextStream::instance().setText(std::to_string(i) + ":" + projectedPoint.to_string(), i, 1);
i++; i++;
} }
} }