diff --git a/TestingGround_ChatGPT_Kris.exe b/TestingGround_ChatGPT_Kris.exe index c3fb2f9..e4f075a 100644 Binary files a/TestingGround_ChatGPT_Kris.exe and b/TestingGround_ChatGPT_Kris.exe differ diff --git a/gamematrix.exe b/gamematrix.exe index 7cd93ef..a5095e9 100644 Binary files a/gamematrix.exe and b/gamematrix.exe differ diff --git a/includes/TestingGround_ChatGPT_Kris.cpp b/includes/TestingGround_ChatGPT_Kris.cpp index daa6c3d..9559168 100644 --- a/includes/TestingGround_ChatGPT_Kris.cpp +++ b/includes/TestingGround_ChatGPT_Kris.cpp @@ -9,6 +9,9 @@ +// Matrixmultiplikation + + // Rotationsmatrix um Achse x/y/z static std::array,4> rot3D(double angle_deg, char axis); @@ -16,11 +19,14 @@ static std::array,4> rot3D(double angle_deg, char axis); static std::array,4> translate(const std::array& pos); -//Mathematische Funkion, Rechnung (Matrix C = A*B) + + +//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) @@ -28,37 +34,44 @@ std::array,4> gameMatrix::matmul( for (int k = 0; k < 4; ++k) C[i][j] += A[i][k] * B[k][j]; + return C; + } +// -------------------- Translationsmatrix -------------------- +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() { - 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]; - } - auto C = gameMatrix::matmul(A, B); + // Beispiel: Translation testen + std::array pos; + std::cout << "Gib die Translation (x y z) ein: "; + std::cin >> pos[0] >> pos[1] >> pos[2]; - std::cout << "\nErgebnis der Matrixmultiplikation (C = A * B):\n"; + 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 << C[i][j] << "\t"; + std::cout << T[i][j] << "\t"; std::cout << "\n"; } - return 0; -} + +} \ No newline at end of file diff --git a/includes/gamematrix.cpp b/includes/gamematrix.cpp index 7190894..7fef98b 100644 --- a/includes/gamematrix.cpp +++ b/includes/gamematrix.cpp @@ -64,6 +64,20 @@ std::array,4> gameMatrix::rot3D(double angle_deg, char axis 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() diff --git a/includes/gamematrix.h b/includes/gamematrix.h index 2a486ea..d074dc0 100644 --- a/includes/gamematrix.h +++ b/includes/gamematrix.h @@ -19,9 +19,9 @@ public: char axis ); - // Verschiebung + // Translation static std::array,4> translate( - const std::array& pos); + const std::array& pos + ); };