Complete?
Sollte fertig sein
This commit is contained in:
parent
9d71e1cfea
commit
3d346a3789
BIN
gamematrix.exe
BIN
gamematrix.exe
Binary file not shown.
@ -6,9 +6,8 @@
|
||||
|
||||
// Typalias für 4x4-Matrix mit double
|
||||
#include "gamematrix.h"
|
||||
// Matrixmultiplikation
|
||||
static std::array<std::array<double,4>,4> matmul(const std::array<std::array<double,4>,4>& A,
|
||||
const std::array<std::array<double,4>,4>& B);
|
||||
|
||||
|
||||
|
||||
// Rotationsmatrix um Achse x/y/z
|
||||
static std::array<std::array<double,4>,4> rot3D(double angle_deg, char axis);
|
||||
|
||||
@ -21,9 +21,7 @@ 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)
|
||||
|
||||
|
||||
//Mathematische Funkion, Rechnung (Matrix C = A*B)
|
||||
{
|
||||
{ //Matrix-Mathematik (Matrix C = A*B)
|
||||
std::array<std::array<double,4>,4> C{};
|
||||
|
||||
for (int i = 0; i < 4; ++i)
|
||||
@ -31,11 +29,46 @@ std::array<std::array<double,4>,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<std::array<double,4>,4> gameMatrix::rot3D(double angle_deg, char axis) {
|
||||
double rad = angle_deg * M_PI / 180.0;
|
||||
|
||||
//Mathematik-Rotation
|
||||
std::array<std::array<double,4>,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<std::array<double,4>,4> A{};
|
||||
std::array<std::array<double,4>,4> B{};
|
||||
|
||||
@ -53,7 +86,7 @@ int main()
|
||||
std::cin >> B[i][j];
|
||||
}
|
||||
|
||||
auto C = gameMatrix::matmul(A, B);
|
||||
std::array<std::array<double,4>,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<std::array<double,4>,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<double,3> pos;
|
||||
std::cout << "\nGib 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";
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -10,12 +10,18 @@ public:
|
||||
// Matrix Multiplikation
|
||||
static std::array<std::array<double,4>,4> matmul(
|
||||
const std::array<std::array<double,4>,4>& A,
|
||||
const std::array<std::array<double,4>,4>& B);
|
||||
const std::array<std::array<double,4>,4>& B
|
||||
);
|
||||
|
||||
// Rotationsmatrix um Achse x/y/z
|
||||
static std::array<std::array<double,4>,4> rot3D(double angle_deg, char axis);
|
||||
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);
|
||||
static std::array<std::array<double,4>,4> translate(
|
||||
const std::array<double,
|
||||
3>& pos);
|
||||
};
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user