From e179abd8d9cf9d6c75d41b2dadb4de23737c4b7e Mon Sep 17 00:00:00 2001 From: linkse100241 Date: Sun, 16 Nov 2025 16:48:17 +0100 Subject: [PATCH] tests.cpp update --- src/tests.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/src/tests.cpp b/src/tests.cpp index 8b13789..4a62360 100644 --- a/src/tests.cpp +++ b/src/tests.cpp @@ -1 +1,41 @@ +#include +#include +#include +#include +#include "gamematrix.h" +// Matrix-Vektor Multiplikation (4x4 Matrix auf 4D Vektor anwenden) +std::array matVecMul(const std::array, 4>& mat, const std::array& vec) { + std::array result = {0, 0, 0, 0}; + for (size_t i = 0; i < 4; ++i) { + for (size_t j = 0; j < 4; ++j) { + result[i] += mat[i][j] * vec[j]; + } + } + return result; +} + +void test_rotateZ() { + std::array v = {1, 0, 0, 1}; // Der Vektor (1, 0, 0) wird zu (1, 0, 0, 1) + + // Rotationsmatrix um 90° um die Z-Achse + auto R = gameMatrix::rot3D(90, 'Z'); + + // Vektor mit der Matrix multiplizieren + std::array result = matVecMul(R, v); + + // Erwartetes Ergebnis + std::array expected_result = {0, 1, 0, 1}; + + // Vergleich der Ergebnisse + for (size_t i = 0; i < 4; ++i) { + assert(std::abs(result[i] - expected_result[i]) < 1e-6); + } + + std::cout << "Test erfolgreich! Rotation um Z-Achse funktioniert." << std::endl; +} + +int main() { + test_rotateZ(); + return 0; +}