Compare commits
5
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fba740c35c | ||
|
|
7666d43cfc | ||
|
|
28041fcf9f | ||
|
|
ad3ae081a9 | ||
|
|
f613b5a97f |
No files matched your search
@@ -0,0 +1,74 @@
|
||||
========================================================
|
||||
Projekt: gamematrix (C++ Library)
|
||||
Rolle: Architekt
|
||||
Datei: design.txt
|
||||
Datum: ____________________
|
||||
Team: ____________________
|
||||
========================================================
|
||||
|
||||
# ----------------------------
|
||||
# 1. Projektstruktur / Namespace
|
||||
# ----------------------------
|
||||
Namespace: _______________________________________________
|
||||
|
||||
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 |
|
||||
|--------|------------------------------------------|--------------|
|
||||
| Vec3 | struct Vec3 | 3D-Vektor (x, y, z) |
|
||||
| Mat4 | std::array<std::array<double,4>,4> | 4x4-Matrix (homogen) |
|
||||
| ______ | ________ | ___________________ |
|
||||
| ______ | ________ | ___________________ |
|
||||
|
||||
# ----------------------------
|
||||
# 3. Operatoren / Templates
|
||||
# ----------------------------
|
||||
Welche Operatoren oder Templates sollen definiert werden?
|
||||
|
||||
- Templates für unterschiedliche Datentypen? ☐ 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? ___________
|
||||
- Verwendung von std::array oder std::vector? ___________
|
||||
- Homogene Koordinaten für Translation / Rotation (4x4)? ☐ 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.
|
||||
//
|
||||
Reference in new issue
Block a user