From 368576471ac6af81075fc80ffed631c0fb401c8e Mon Sep 17 00:00:00 2001 From: linkse100241 Date: Mon, 3 Nov 2025 12:36:07 +0100 Subject: [PATCH 1/5] Create tests.cpp --- src/tests.cpp | 1 + 1 file changed, 1 insertion(+) create mode 100644 src/tests.cpp diff --git a/src/tests.cpp b/src/tests.cpp new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/src/tests.cpp @@ -0,0 +1 @@ + From 5dfa867449b3872269171b9d83dabdd06ef50325 Mon Sep 17 00:00:00 2001 From: linkse100241 Date: Mon, 3 Nov 2025 12:40:11 +0100 Subject: [PATCH 2/5] Create tests.txt --- docs/tests.txt | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 docs/tests.txt diff --git a/docs/tests.txt b/docs/tests.txt new file mode 100644 index 0000000..8b566c3 --- /dev/null +++ b/docs/tests.txt @@ -0,0 +1,44 @@ +@@ -1,43 +0,0 @@ +======================================================== +Projekt: gamematrix (C++ Library) +Rolle: Tester +Datei: tests.txt +Datum: 4.10.2025 +Team: prog3b_652 +======================================================== + +# ---------------------------- +# 1. Testplan Übersicht +# ---------------------------- +Ziel: Überprüfung der Funktionen matmul(), translate(), rot3D(). + +| Funktion | Testfall | Eingabe | Erwartetes Ergebnis | Bemerkung | +|---------------|---------------------------|------------------------------|-----------------------------------|----------------------------| +| matmul | Identity * Identity | 4x4 Identity Matrizen | Identity | Basisfall | +| matmul | Beispielmatrizen | A=[[...]], B=[[...]] | C=[[...]] | Prüfen mit Handrechnung | +| translate | Verschiebung | Vec3 {1,2,3} | Matrix mit Translation 1,2,3 | Prüfen letzte Spalte | +| rot3D | Rotation Z 90° | angle_deg=90, axis='z' | (1,0,0) -> (0,1,0) | Prüfen Anwendung auf Vektor| +| rot3D | Rotation X 180° | angle_deg=180, axis='x' | (0,1,0) -> (0,-1,0) | Prüfen Anwendung auf Vektor| +| rot3D | Rotation Y 270° | angle_deg=270, axis='y' | (1,0,0) -> (0,0,-1) | Prüfen Anwendung auf Vektor| + + +# ---------------------------- +# 2. Testdaten / Matrizen +# ---------------------------- +- Matrizen für matmul: Identity, Beispiel A/B Matrizen +- Vektoren für translate: Vec3 {x, y, z} +- Vektoren für rot3D: Vec3 {1,0,0}, Vec3 {0,1,0} + +# ---------------------------- +# 3. Abnahmekriterien +# ---------------------------- +- Alle Unit-Tests erfolgreich +- Keine Exceptions außer gewollt (z. B. ungültige Achse) +- Testbericht in tests.txt dokumentiert + +======================================================== +Hinweis: +- Diese Datei wird vom Tester gepflegt. +- Tester dokumentiert Input, Output, erwartetes Ergebnis und Erfolg/Fehler. +======================================================== + From 72168eaa790f9de1f76f1b0030a84e474206b734 Mon Sep 17 00:00:00 2001 From: linkse100241 Date: Sun, 16 Nov 2025 16:46:56 +0100 Subject: [PATCH 3/5] test.cpp aktualisiert --- includes/gamematrix.cpp | 150 ++++++++++++++++++++++++++++++++++++++++ src/gamematrix.h | 19 +++++ 2 files changed, 169 insertions(+) create mode 100644 includes/gamematrix.cpp create mode 100644 src/gamematrix.h diff --git a/includes/gamematrix.cpp b/includes/gamematrix.cpp new file mode 100644 index 0000000..7fef98b --- /dev/null +++ b/includes/gamematrix.cpp @@ -0,0 +1,150 @@ +// +// Created by kris- on 03.11.2025. +// +#include +#include "gamematrix.h" + +// Matrixmultiplikation + + +// Rotationsmatrix um Achse x/y/z +static std::array,4> rot3D(double angle_deg, char axis); + +// Verschiebung +static std::array,4> translate(const std::array& pos); + + + + +//Matrixmultiplikation-Funktion +std::array,4> gameMatrix::matmul( + const std::array,4>& A, + const std::array,4>& B) + +{ //Matrix-Mathematik (Matrix C = A*B) + std::array,4> C{}; + + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 4; ++j) + for (int k = 0; k < 4; ++k) + C[i][j] += A[i][k] * B[k][j]; + + + return C; + +} + +//Rotation 3D +std::array,4> gameMatrix::rot3D(double angle_deg, char axis) { + double rad = angle_deg * M_PI / 180.0; + + //Mathematik-Rotation + std::array,4> R{}; + + for (int i = 0; i < 4; ++i) + R[i][i] = 1.0; + + if (axis == 'x' || axis == 'X') { + R[1][1] = cos(rad); + R[1][2] = -sin(rad); + R[2][1] = sin(rad); + R[2][2] = cos(rad); + } else if (axis == 'y' || axis == 'Y') { + R[0][0] = cos(rad); + R[0][2] = sin(rad); + R[2][0] = -sin(rad); + R[2][2] = cos(rad); + } else if (axis == 'z' || axis == 'Z') { + R[0][0] = cos(rad); + R[0][1] = -sin(rad); + R[1][0] = sin(rad); + R[1][1] = cos(rad); + } + + return R; +} + +//Translation +std::array,4> gameMatrix::translate(const std::array& pos) { + std::array,4> T{}; + for (int i = 0; i < 4; ++i) + T[i][i] = 1.0; // Identitätsmatrix + + T[0][3] = pos[0]; // x-Verschiebung + T[1][3] = pos[1]; // y-Verschiebung + T[2][3] = pos[2]; // z-Verschiebung + + return T; +} + + + + +int main() +{ + // Part Matrix + std::array,4> A{}; + std::array,4> B{}; + + std::cout << "Gib die Werte für Matrix A (4x4) ein:\n"; + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 4; ++j) { + std::cout << "A[" << i << "][" << j << "] = "; + std::cin >> A[i][j]; + } + + std::cout << "\nGib die Werte für Matrix B (4x4) ein:\n"; + for (int i = 0; i < 4; ++i) + for (int j = 0; j < 4; ++j) { + std::cout << "B[" << i << "][" << j << "] = "; + std::cin >> B[i][j]; + } + + std::array,4> C = gameMatrix::matmul(A, B); + + std::cout << "\nErgebnis der Matrixmultiplikation (C = A * B):\n"; + for (int i = 0; i < 4; ++i) { + for (int j = 0; j < 4; ++j) + std::cout << C[i][j] << "\t"; + std::cout << "\n"; + } + //Ende Matrix + + + // Rotation + double angle; + char axis; + std::cout << "\nGib einen Rotationswinkel in Grad ein: "; + std::cin >> angle; + std::cout << "Gib die Rotationsachse (x/y/z) ein: "; + std::cin >> axis; + + std::array,4> R = gameMatrix::rot3D(angle, axis); + + std::cout << "\nRotationsmatrix R:\n"; + for (int i = 0; i < 4; ++i) { + for (int j = 0; j < 4; ++j) + std::cout << R[i][j] << "\t"; + std::cout << "\n"; + } + + // Translation + std::array pos; + std::cout << "\nGib die Translation (x y z) ein: "; + std::cin >> pos[0] >> pos[1] >> pos[2]; + + std::array,4> T = gameMatrix::translate(pos); + + std::cout << "\nTranslationsmatrix T:\n"; + for (int i = 0; i < 4; ++i) { + for (int j = 0; j < 4; ++j) + std::cout << T[i][j] << "\t"; + std::cout << "\n"; + } + + return 0; +} + + + + diff --git a/src/gamematrix.h b/src/gamematrix.h new file mode 100644 index 0000000..7a644d6 --- /dev/null +++ b/src/gamematrix.h @@ -0,0 +1,19 @@ +#pragma once +#include +#include +#include +#include + +class gameMatrix +{ +public: + // Matrix Multiplikation + static std::array,4> matmul(const std::array,4>& A, + const std::array,4>& B); + + // Rotationsmatrix um Achse x/y/z + static std::array,4> rot3D(double angle_deg, char axis); + + // Verschiebung + static std::array,4> translate(const std::array& pos); +}; From e179abd8d9cf9d6c75d41b2dadb4de23737c4b7e Mon Sep 17 00:00:00 2001 From: linkse100241 Date: Sun, 16 Nov 2025 16:48:17 +0100 Subject: [PATCH 4/5] 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; +} From 544c4503cd23bb47cb51e062740207b460488fc3 Mon Sep 17 00:00:00 2001 From: linkse100241 Date: Mon, 17 Nov 2025 12:09:33 +0100 Subject: [PATCH 5/5] gamematrix.cpp remove from include in branch tester --- includes/gamematrix.cpp | 150 ---------------------------------------- 1 file changed, 150 deletions(-) delete mode 100644 includes/gamematrix.cpp diff --git a/includes/gamematrix.cpp b/includes/gamematrix.cpp deleted file mode 100644 index 7fef98b..0000000 --- a/includes/gamematrix.cpp +++ /dev/null @@ -1,150 +0,0 @@ -// -// Created by kris- on 03.11.2025. -// -#include -#include "gamematrix.h" - -// Matrixmultiplikation - - -// Rotationsmatrix um Achse x/y/z -static std::array,4> rot3D(double angle_deg, char axis); - -// Verschiebung -static std::array,4> translate(const std::array& pos); - - - - -//Matrixmultiplikation-Funktion -std::array,4> gameMatrix::matmul( - const std::array,4>& A, - const std::array,4>& B) - -{ //Matrix-Mathematik (Matrix C = A*B) - std::array,4> C{}; - - for (int i = 0; i < 4; ++i) - for (int j = 0; j < 4; ++j) - for (int k = 0; k < 4; ++k) - C[i][j] += A[i][k] * B[k][j]; - - - return C; - -} - -//Rotation 3D -std::array,4> gameMatrix::rot3D(double angle_deg, char axis) { - double rad = angle_deg * M_PI / 180.0; - - //Mathematik-Rotation - std::array,4> R{}; - - for (int i = 0; i < 4; ++i) - R[i][i] = 1.0; - - if (axis == 'x' || axis == 'X') { - R[1][1] = cos(rad); - R[1][2] = -sin(rad); - R[2][1] = sin(rad); - R[2][2] = cos(rad); - } else if (axis == 'y' || axis == 'Y') { - R[0][0] = cos(rad); - R[0][2] = sin(rad); - R[2][0] = -sin(rad); - R[2][2] = cos(rad); - } else if (axis == 'z' || axis == 'Z') { - R[0][0] = cos(rad); - R[0][1] = -sin(rad); - R[1][0] = sin(rad); - R[1][1] = cos(rad); - } - - return R; -} - -//Translation -std::array,4> gameMatrix::translate(const std::array& pos) { - std::array,4> T{}; - for (int i = 0; i < 4; ++i) - T[i][i] = 1.0; // Identitätsmatrix - - T[0][3] = pos[0]; // x-Verschiebung - T[1][3] = pos[1]; // y-Verschiebung - T[2][3] = pos[2]; // z-Verschiebung - - return T; -} - - - - -int main() -{ - // Part Matrix - std::array,4> A{}; - std::array,4> B{}; - - std::cout << "Gib die Werte für Matrix A (4x4) ein:\n"; - for (int i = 0; i < 4; ++i) - for (int j = 0; j < 4; ++j) { - std::cout << "A[" << i << "][" << j << "] = "; - std::cin >> A[i][j]; - } - - std::cout << "\nGib die Werte für Matrix B (4x4) ein:\n"; - for (int i = 0; i < 4; ++i) - for (int j = 0; j < 4; ++j) { - std::cout << "B[" << i << "][" << j << "] = "; - std::cin >> B[i][j]; - } - - std::array,4> C = gameMatrix::matmul(A, B); - - std::cout << "\nErgebnis der Matrixmultiplikation (C = A * B):\n"; - for (int i = 0; i < 4; ++i) { - for (int j = 0; j < 4; ++j) - std::cout << C[i][j] << "\t"; - std::cout << "\n"; - } - //Ende Matrix - - - // Rotation - double angle; - char axis; - std::cout << "\nGib einen Rotationswinkel in Grad ein: "; - std::cin >> angle; - std::cout << "Gib die Rotationsachse (x/y/z) ein: "; - std::cin >> axis; - - std::array,4> R = gameMatrix::rot3D(angle, axis); - - std::cout << "\nRotationsmatrix R:\n"; - for (int i = 0; i < 4; ++i) { - for (int j = 0; j < 4; ++j) - std::cout << R[i][j] << "\t"; - std::cout << "\n"; - } - - // Translation - std::array pos; - std::cout << "\nGib die Translation (x y z) ein: "; - std::cin >> pos[0] >> pos[1] >> pos[2]; - - std::array,4> T = gameMatrix::translate(pos); - - std::cout << "\nTranslationsmatrix T:\n"; - for (int i = 0; i < 4; ++i) { - for (int j = 0; j < 4; ++j) - std::cout << T[i][j] << "\t"; - std::cout << "\n"; - } - - return 0; -} - - - -