14 Commits
8 changed files with 1992 additions and 6 deletions
+64
View File
@@ -0,0 +1,64 @@
========================================================
Projekt: gamematrix (C++ Library)
Rolle: Projektleiter
Datei: requirements.txt
Datum: 10.11.2025
Team: ShehiBr (fuh wit yuh buh)
========================================================
# ----------------------------
# 1. Projektziel
# ----------------------------
Beschreiben Sie hier kurz das Ziel des Projekts:
Ziel: Die Bibliothek gamematrix um grundlegende 3D-Transformationsfunktionen zu erweitern,
die später über pybind11 in Python eingebunden werden können.
# ----------------------------
# 2. Funktionale Anforderungen
# ----------------------------
Listen Sie alle Funktionen auf, die die Bibliothek bereitstellen soll.
Tragen Sie ein: Funktion, Eingabe, Ausgabe, kurze Beschreibung
| Funktion | Eingabe | Ausgabe | Kurzbeschreibung |
|---------------|------------------------------------|-----------------------|----------------------------------------|
| matmul | 4x4 Matrix A, 4x4 Matrix B | 4x4 Matrix | Multipliziert 2 Matrizen |
| translate | 3D Vektor | 4x4 Matrix | Liefert eine Übersetzungs Matrix |
| rot3D | Winkel in °, Rotationsachse (x/y/z)| 4x4 Matrix | Liefert eine Rotationsmatrix |
| identity (optional)| --- | 4x4 Matrix | Liefert eine Einheitsmatrix |
| _____________ | __________________________________ | ____________________ | ______________________________ |
| _____________ | __________________________________ | ____________________ | ______________________________ |
# ----------------------------
# 3. Nicht-funktionale Anforderungen
# ----------------------------
(z. B. Performance, Lesbarkeit, Wartbarkeit, Python-Kompatibilität via pybind11)
- ____________________________________________________________
- ____________________________________________________________
- ____________________________________________________________
# ----------------------------
# 4. Annahmen / Einschränkungen
# ----------------------------
(z. B. alle Matrizen sind 4x4, Winkel in Grad, nur double)
- Alle Matrizen sind 4x4
- Winkel werden in Grad angegeben
- Keine Skalierung, nur Rotation und Translation
# ----------------------------
# 5. Abnahmekriterien
# ----------------------------
Wie soll geprüft werden, dass die Anforderungen erfüllt sind?
(z. B. Unit-Tests, Beispielrotationen, Matrizenmultiplikation)
- Alle Matrixfunktionen liefern korrekte Ergebnisse bei Testeingaben
- Vergleich mit bekannten Referenzwerten (Rotation 90° um x-Achse, etc.)
- Kompilierbarkeit der Bibliothek und Integration in das Spielprojekt
========================================================
Hinweis:
- Diese Datei wird vom Projektleiter erstellt und gepflegt.
- Jede Phase des Projekts soll hier dokumentiert werden.
========================================================
+74
View File
@@ -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.
========================================================
+4 -3
View File
@@ -3,7 +3,7 @@
#include "raylib.h" #include "raylib.h"
#include "rlgl.h" #include "rlgl.h"
struct Vec3 struct Vec3 //anisch unnötig weil rylib schon vec3 hat
{ {
float x, y, z; float x, y, z;
}; };
@@ -22,7 +22,7 @@ public:
Vec3 GetPosition() const; Vec3 GetPosition() const;
float GetRotationY() const; float GetRotationY() const;
Color GetColor() const { return color; } Color GetColor() const { return color; }
//zustände klarer abbikden bzw weniger bools = klarare Logik
private: private:
Vec3 position; Vec3 position;
Color color; Color color;
@@ -31,4 +31,5 @@ private:
bool flippingForward = false; bool flippingForward = false;
bool flippingBackward = false; bool flippingBackward = false;
float rotation = 0.0f; float rotation = 0.0f;
}; };
// braucht bessere trennung von logik & darstellung
+14
View File
@@ -0,0 +1,14 @@
#pragma once
#include <chrono>
class Timer {
public:
void start();
void stop();
long long elapsedMs() const;
private:
std::chrono::time_point<std::chrono::high_resolution_clock> startTime;
std::chrono::time_point<std::chrono::high_resolution_clock> endTime;
bool running = false;
};
+1708
View File
File diff suppressed because it is too large Load Diff
+75
View File
@@ -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.
//
+22
View File
@@ -0,0 +1,22 @@
#include "gametimer.h"
void Timer::start() {
running = true;
startTime = std::chrono::high_resolution_clock::now();
}
void Timer::stop() {
running = false;
endTime = std::chrono::high_resolution_clock::now();
}
long long Timer::elapsedMs() const {
if (running) {
return std::chrono::duration_cast<std::chrono::milliseconds>(
std::chrono::high_resolution_clock::now() - startTime
).count();
}
return std::chrono::duration_cast<std::chrono::milliseconds>(
endTime - startTime
).count();
}
+31 -3
View File
@@ -1,4 +1,5 @@
#include "../../prog_3/includes/gamecube.h" #include "gamecube.h"
#include "gametimer.h"
#include <algorithm> #include <algorithm>
#include <ctime> #include <ctime>
@@ -14,6 +15,9 @@ int main()
InitWindow(800, 600, "3D Memory Game with Matrix3D Library"); InitWindow(800, 600, "3D Memory Game with Matrix3D Library");
SetTargetFPS(60); SetTargetFPS(60);
Timer timer;
timer.start();
Camera3D camera{}; Camera3D camera{};
camera.position = {6.0f, 6.0f, 6.0f}; camera.position = {6.0f, 6.0f, 6.0f};
camera.target = {0.0f, 0.0f, 0.0f}; camera.target = {0.0f, 0.0f, 0.0f};
@@ -108,9 +112,15 @@ int main()
} }
// Gewinnprüfung // Gewinnprüfung
if (!gameWon) // Gewinnprüfung
gameWon = std::all_of(cubes.begin(), cubes.end(), [](const gamecube &c){ return c.IsMatched(); }); if (!gameWon) {
gameWon = std::all_of(cubes.begin(), cubes.end(),
[](const gamecube &c){ return c.IsMatched(); });
if (gameWon)
timer.stop();
}
// <--- NEU
// ----------------------------------------------------------- // -----------------------------------------------------------
// Zeichnen // Zeichnen
// ----------------------------------------------------------- // -----------------------------------------------------------
@@ -128,6 +138,24 @@ int main()
else else
DrawText("Flip 2 cubes - find matching pairs!", 10, 10, 20, DARKGRAY); DrawText("Flip 2 cubes - find matching pairs!", 10, 10, 20, DARKGRAY);
if (gameWon)
DrawText("Congrats! You found all pairs!", 150, 260, 30, DARKBLUE);
else
DrawText("Flip 2 cubes - find matching pairs!", 10, 10, 20, DARKGRAY);
if (!gameWon) {
long long elapsed = timer.elapsedMs() / 1000; // Sekunden
std::string timeStr = "Time: " + std::to_string(elapsed) + "s";
DrawText(timeStr.c_str(), 10, 40, 20, DARKGRAY);
} else {
// Optional: Endzeit anzeigen
long long totalTime = timer.elapsedMs() / 1000;
std::string endStr = "Finished in " + std::to_string(totalTime) + " seconds!";
DrawText(endStr.c_str(), 150, 300, 25, DARKBLUE);
}
EndDrawing(); EndDrawing();
} }