77 lines
1.8 KiB
C++
77 lines
1.8 KiB
C++
//Ablage für ChatGPT Sachen, nicht relavant für das Projekt (Nur ein "Cloud"-Zwischenspeicher)
|
|
#include <iostream>
|
|
#include <array>
|
|
#include <string>
|
|
#include <cmath>
|
|
|
|
// Typalias für 4x4-Matrix mit double
|
|
#include "gamematrix.h"
|
|
|
|
|
|
|
|
// Matrixmultiplikation
|
|
|
|
|
|
// Rotationsmatrix um Achse x/y/z
|
|
static std::array<std::array<double,4>,4> rot3D(double angle_deg, char axis);
|
|
|
|
// Verschiebung
|
|
static std::array<std::array<double,4>,4> translate(const std::array<double, 3>& pos);
|
|
|
|
|
|
|
|
|
|
//Matrixmultiplikation-Funktion
|
|
std::array<std::array<double,4>,4> gameMatrix::matmul(
|
|
const std::array<std::array<double,4>,4>& A,
|
|
const std::array<std::array<double,4>,4>& B)
|
|
|
|
{ //Matrix-Mathematik (Matrix C = A*B)
|
|
std::array<std::array<double,4>,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;
|
|
|
|
}
|
|
|
|
// -------------------- Translationsmatrix --------------------
|
|
std::array<std::array<double,4>,4> gameMatrix::translate(const std::array<double,3>& pos) {
|
|
std::array<std::array<double,4>,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()
|
|
{
|
|
|
|
|
|
|
|
// Beispiel: Translation testen
|
|
std::array<double,3> pos;
|
|
std::cout << "Gib die Translation (x y z) ein: ";
|
|
std::cin >> pos[0] >> pos[1] >> pos[2];
|
|
|
|
std::array<std::array<double,4>,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";
|
|
}
|
|
|
|
|
|
} |