diff --git a/gamematrix.exe b/gamematrix.exe index 3f0c54d..7cd93ef 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 dff3419..daa6c3d 100644 --- a/includes/TestingGround_ChatGPT_Kris.cpp +++ b/includes/TestingGround_ChatGPT_Kris.cpp @@ -6,9 +6,8 @@ // Typalias für 4x4-Matrix mit double #include "gamematrix.h" -// Matrixmultiplikation -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); diff --git a/includes/gamematrix.cpp b/includes/gamematrix.cpp index 71cc936..7190894 100644 --- a/includes/gamematrix.cpp +++ b/includes/gamematrix.cpp @@ -21,9 +21,7 @@ std::array,4> gameMatrix::matmul( const std::array,4>& A, const std::array,4>& B) - -//Mathematische Funkion, Rechnung (Matrix C = A*B) -{ +{ //Matrix-Mathematik (Matrix C = A*B) std::array,4> C{}; for (int i = 0; i < 4; ++i) @@ -31,11 +29,46 @@ std::array,4> gameMatrix::matmul( 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; +} + + + int main() { + // Part Matrix std::array,4> A{}; std::array,4> B{}; @@ -53,7 +86,7 @@ int main() std::cin >> B[i][j]; } - auto C = gameMatrix::matmul(A, B); + std::array,4> C = gameMatrix::matmul(A, B); std::cout << "\nErgebnis der Matrixmultiplikation (C = A * B):\n"; for (int i = 0; i < 4; ++i) { @@ -61,6 +94,39 @@ int main() 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/includes/gamematrix.h b/includes/gamematrix.h index 7d23453..2a486ea 100644 --- a/includes/gamematrix.h +++ b/includes/gamematrix.h @@ -10,12 +10,18 @@ public: // Matrix Multiplikation static std::array,4> matmul( const std::array,4>& A, - const std::array,4>& B); + const std::array,4>& B + ); // Rotationsmatrix um Achse x/y/z - static std::array,4> rot3D(double angle_deg, char axis); + static std::array,4> rot3D( + double angle_deg, + char axis + ); // Verschiebung - static std::array,4> translate(const std::array& pos); + static std::array,4> translate( + const std::array& pos); };