Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9ce6f05ba7 | ||
|
|
ad3ae081a9 |
@@ -1,71 +0,0 @@
|
|||||||
========================================================
|
|
||||||
Projekt: gamematrix (C++ Library)
|
|
||||||
Rolle: Architekt
|
|
||||||
Datei: design.txt
|
|
||||||
Datum: ____________________
|
|
||||||
Team: ____________________
|
|
||||||
========================================================
|
|
||||||
|
|
||||||
# ----------------------------
|
|
||||||
# 1. Projektstruktur / Namespace
|
|
||||||
# ----------------------------
|
|
||||||
Namespace: Matrixgame
|
|
||||||
|
|
||||||
Ziel: Saubere Trennung der Bibliothek, Vermeidung von Namenskonflikten.
|
|
||||||
|
|
||||||
Beispiel:
|
|
||||||
namespace Matrix3D {
|
|
||||||
// Funktionen, ggf Klasse(n)
|
|
||||||
}
|
|
||||||
|
|
||||||
# ----------------------------
|
|
||||||
# 2. Datenstrukturen / Klassen
|
|
||||||
# ----------------------------
|
|
||||||
Listen Sie die Klassen oder Structs auf, die verwendet werden:
|
|
||||||
|
|
||||||
| Name | Typ | Beschreibung |
|
|
||||||
|--------|------------------------------------------|--------------|
|
|
||||||
| Gamematrix | class gameMatrix | 3D-Vektor (x, y, z) |
|
|
||||||
|
|
||||||
# ----------------------------
|
|
||||||
# 3. Operatoren / Templates
|
|
||||||
# ----------------------------
|
|
||||||
Welche Operatoren oder Templates sollen definiert werden?
|
|
||||||
|
|
||||||
- Templates für unterschiedliche Datentypen? x Ja ☐ Nein
|
|
||||||
- Operatoren:
|
|
||||||
- Mat4 * Mat4
|
|
||||||
- Mat4 * Vec3
|
|
||||||
|
|
||||||
# ----------------------------
|
|
||||||
# 4. Funktionen / Schnittstellen
|
|
||||||
# ----------------------------
|
|
||||||
Liste der Funktionen mit Eingabe/Ausgabe und kurzer Beschreibung:
|
|
||||||
|
|
||||||
| Funktion | Eingabe | Ausgabe | Kurzbeschreibung |
|
|
||||||
|---------------|------------------------------------|-----------------------|----------------------------------------|
|
|
||||||
| matmul | Mat4 A, Mat4 B | Mat4 | Matrixmultiplikation 4x4 |
|
|
||||||
| translate | Vec3 pos | Mat4 | Verschiebungstransformation |
|
|
||||||
| rot3D | double angle_deg, char axis | Mat4 | Rotation um Achse x/y/z |
|
|
||||||
| identity (optional)| --- | Mat4 | Identitätsmatrix |
|
|
||||||
| _____________ | __________________________________ | ____________________ | ______________________________ |
|
|
||||||
|
|
||||||
# ----------------------------
|
|
||||||
# 5. Designentscheidungen / Hinweise
|
|
||||||
# ----------------------------
|
|
||||||
- Rückgabe der Matrizen per Wert oder Referenz? Wert
|
|
||||||
- Verwendung von std::array oder std::vector? array
|
|
||||||
- Homogene Koordinaten für Translation / Rotation (4x4)? x Ja ☐ Nein
|
|
||||||
- Weitere Designüberlegungen: ___________________________
|
|
||||||
|
|
||||||
# ----------------------------
|
|
||||||
# 6. Deliverables / Milestones
|
|
||||||
# ----------------------------
|
|
||||||
- design.txt fertig und im Branch architect committed
|
|
||||||
- Übergabe an Entwickler für Implementierung
|
|
||||||
|
|
||||||
========================================================
|
|
||||||
Hinweis:
|
|
||||||
- Dieses Dokument dient als Grundlage für die Implementierung.
|
|
||||||
- Alle Designentscheidungen sollen klar nachvollziehbar sein.
|
|
||||||
========================================================
|
|
||||||
@@ -0,0 +1,75 @@
|
|||||||
|
#include <gamematrix.h>
|
||||||
|
|
||||||
|
|
||||||
|
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) {
|
||||||
|
std::array<std::array<double,4>,4> result{};
|
||||||
|
|
||||||
|
for (int i = 0; i < 4; ++i) {
|
||||||
|
for (int j = 0; j < 4; ++j) {
|
||||||
|
double sum = 0.0;
|
||||||
|
for (int k = 0; k < 4; ++k) {
|
||||||
|
sum += A[i][k] * B[k][j];
|
||||||
|
}
|
||||||
|
result[i][j] = sum;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::array<std::array<double,4>,4> gameMatrix::rot3D(double angle_deg, char axis) {
|
||||||
|
double angle = angle_deg * M_PI / 180.0; // Grad → Radiant
|
||||||
|
double c = std::cos(angle);
|
||||||
|
double s = std::sin(angle);
|
||||||
|
std::array<std::array<double,4>,4> R{}; // alles 0 initialisiert
|
||||||
|
|
||||||
|
switch (axis) {
|
||||||
|
case 'x':
|
||||||
|
R = {{
|
||||||
|
{1, 0, 0, 0},
|
||||||
|
{0, c, -s, 0},
|
||||||
|
{0, s, c, 0},
|
||||||
|
{0, 0, 0, 1}
|
||||||
|
}};
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'y':
|
||||||
|
R = {{
|
||||||
|
{ c, 0, s, 0},
|
||||||
|
{ 0, 1, 0, 0},
|
||||||
|
{-s, 0, c, 0},
|
||||||
|
{ 0, 0, 0, 1}
|
||||||
|
}};
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'z':
|
||||||
|
R = {{
|
||||||
|
{c, -s, 0, 0},
|
||||||
|
{s, c, 0, 0},
|
||||||
|
{0, 0, 1, 0},
|
||||||
|
{0, 0, 0, 1}
|
||||||
|
}};
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw std::invalid_argument("Axis must be 'x', 'y' or 'z'");
|
||||||
|
}
|
||||||
|
|
||||||
|
return R;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::array<std::array<double,4>,4> gameMatrix::translate(const std::array<double, 3>& pos) {
|
||||||
|
std::array<std::array<double,4>,4> T{{
|
||||||
|
{1, 0, 0, pos[0]},
|
||||||
|
{0, 1, 0, pos[1]},
|
||||||
|
{0, 0, 1, pos[2]},
|
||||||
|
{0, 0, 0, 1}
|
||||||
|
}};
|
||||||
|
|
||||||
|
return T;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Created by Fabian Weber on 10.11.25.
|
||||||
|
//
|
||||||
+6
-4
@@ -21,15 +21,17 @@ int main()
|
|||||||
camera.fovy = 45.0f;
|
camera.fovy = 45.0f;
|
||||||
camera.projection = CAMERA_PERSPECTIVE;
|
camera.projection = CAMERA_PERSPECTIVE;
|
||||||
|
|
||||||
|
// cubePairs = {};
|
||||||
// Nur 3 Farben für 3 Paare
|
// Nur 3 Farben für 3 Paare
|
||||||
Color colors[] = { RED, GREEN, BLUE };
|
Color colors[] = { RED, GREEN, BLUE, YELLOW, PINK };
|
||||||
|
|
||||||
// 6 Karten-Positionen im 3x2 Raster
|
// 6 Karten-Positionen im 3x2 Raster
|
||||||
std::vector<Vec3> positions = {{-2, 0, -2}, {0, 0, -2}, {2, 0, -2},{-2, 0, 0}, {0, 0, 0}, {2, 0, 0}};
|
std::vector<Vec3> positions = {{-2, 0, -2}, {0, 0, -2}, {2, 0, -2},{-2, 0, 0}, {0, 0, 0},
|
||||||
|
{2, 0, 0},{2,0,-4},{0,0,-4},{-2,0,-4},{-4,0,-2}};
|
||||||
|
|
||||||
// Farben doppelt in einen Pool legen und mischen
|
// Farben doppelt in einen Pool legen und mischen
|
||||||
std::vector<Color> colorPool;
|
std::vector<Color> colorPool;
|
||||||
for (int i = 0; i < 3; i++)
|
for (int i = 0; i <5; i++)
|
||||||
{
|
{
|
||||||
colorPool.push_back(colors[i]);
|
colorPool.push_back(colors[i]);
|
||||||
colorPool.push_back(colors[i]);
|
colorPool.push_back(colors[i]);
|
||||||
@@ -44,7 +46,7 @@ int main()
|
|||||||
|
|
||||||
// Karten/Würfel erstellen
|
// Karten/Würfel erstellen
|
||||||
std::vector<gamecube> cubes;
|
std::vector<gamecube> cubes;
|
||||||
for (int i = 0; i < 6; i++)
|
for (int i = 0; i < 10; i++)
|
||||||
cubes.emplace_back(positions[i], colorPool[i]);
|
cubes.emplace_back(positions[i], colorPool[i]);
|
||||||
|
|
||||||
gamecube* first = nullptr;
|
gamecube* first = nullptr;
|
||||||
|
|||||||
Reference in New Issue
Block a user