Compare commits

...

20 Commits

Author SHA1 Message Date
8eda60d498 Merge remote-tracking branch 'origin/main'
# Conflicts:
#	CMakeLists.txt
2025-11-17 15:14:36 +01:00
69dfbdf139 Funktionsfähig gemacht 2025-11-17 15:13:47 +01:00
16e918b180 includes 2025-11-17 14:58:28 +01:00
48903fdf01 hinzugefügt cmake:current 2025-11-17 14:58:17 +01:00
6e2119ab01 Merge branch 'project_tests' 2025-11-17 14:29:53 +01:00
ff5ec85747 Merge branch 'developer' 2025-11-17 14:28:19 +01:00
4bc2574c03 Merge branch 'project_leader' 2025-11-17 14:26:09 +01:00
7a34810145 gamematrix.h included 2025-11-17 14:20:13 +01:00
5b467f42ae tests.cpp commited 2025-11-17 14:17:38 +01:00
00bb22347f Gamematrix erstellt 2 2025-11-17 14:12:14 +01:00
c3dc997071 Gamematrix erstellt 2025-11-17 14:10:13 +01:00
8023f4e866 CMAKE list is f***ed 2025-11-03 15:31:53 +01:00
a8b2545b6c marco test files 2025-11-03 15:29:22 +01:00
a561b26425 CMake angepasst 2025-11-03 15:24:49 +01:00
96a19a6312 Design.txt Änderungen 2025-11-03 15:21:44 +01:00
0c71e3d2c7 Docs Design 2025-11-03 15:10:58 +01:00
aa7f72820b Test Dokument erstellt 2025-11-03 15:08:56 +01:00
5ff1281385 Docs Design + Gamematrix 2025-11-03 15:04:36 +01:00
a1e712dcf7 Gamematrix.cpp erstellt 2025-11-03 14:31:45 +01:00
93759ebef1 Gamematrix erstellt 2025-11-03 14:30:03 +01:00
9 changed files with 396 additions and 62 deletions

View File

@ -18,6 +18,7 @@ endif()
set(SRC_FILES set(SRC_FILES
${CMAKE_CURRENT_LIST_DIR}/src/main.cpp ${CMAKE_CURRENT_LIST_DIR}/src/main.cpp
${CMAKE_CURRENT_LIST_DIR}/src/gamecube.cpp ${CMAKE_CURRENT_LIST_DIR}/src/gamecube.cpp
src/gamematrix.cpp
) )
##Tom: prev: ${CMAKE_CURRENT_LIST_DIR}/linux -> now /include ##Tom: prev: ${CMAKE_CURRENT_LIST_DIR}/linux -> now /include
@ -36,7 +37,7 @@ target_include_directories(${EXECUTABLE_NAME} PRIVATE
) )
target_link_libraries(${EXECUTABLE_NAME} PRIVATE target_link_libraries(${EXECUTABLE_NAME} PRIVATE
${CMAKE_CURRENT_LIST_DIR}/${OS_NAME}/libgamematrix.a # ${CMAKE_CURRENT_LIST_DIR}/${OS_NAME}/libgamematrix.a
${CMAKE_CURRENT_LIST_DIR}/${OS_NAME}/libraylib.a ${CMAKE_CURRENT_LIST_DIR}/${OS_NAME}/libraylib.a
) )
if (WIN32) if (WIN32)

74
docs/design.txt Normal file
View File

@ -0,0 +1,74 @@
========================================================
Projekt: gamematrix (C++ Library)
Rolle: Architekt
Datei: design.txt
Datum: 03-November
Team: Thomas&Co
========================================================
# ----------------------------
# 1. Projektstruktur / Namespace
# ----------------------------
Namespace: Matrix3D
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.
========================================================

137
docs/tests.cpp Normal file
View File

@ -0,0 +1,137 @@
//
// Created by marco on 03.11.2025.
// Changeb by marco on 16.11.2025
#include <iostream>
#include <cmath>
#include "gamematrix.h"
using namespace Matrix3D;
bool nearlyEqual(double a, double b, double eps = 1e-6) {
return std::abs(a - b) < eps;
}
void test_matmul_identity() {
Mat4 A = identity();
Mat4 B = identity();
Mat4 R = matmul(A, B);
std::cout << "Test matmul: Identity * Identity -> Identity: ";
bool ok = true;
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
double expected = (i==j ? 1.0 : 0.0);
if(!nearlyEqual(R[i][j], expected)) ok = false;
}
}
std::cout << (ok ? "OK\n" : "FAIL\n");
}
void test_matmul_example() {
Mat4 A = {{
{{1, 2, 3, 4}},
{{0, 1, 2, 3}},
{{0, 0, 1, 2}},
{{0, 0, 0, 1}}
}};
Mat4 B = {{
{{1, 0, 0, 0}},
{{1, 1, 0, 0}},
{{1, 1, 1, 0}},
{{1, 1, 1, 1}}
}};
Mat4 R = matmul(A, B);
std::cout << "Test matmul: Beispielmatrizen A * B: ";
// Erwartete Matrix mit Handrechnung:
Mat4 Expected = {{
{{1+2+3+4, 2+3+4, 3+4, 4}},
{{0+1+2+3, 1+2+3, 2+3, 3}},
{{0+0+1+2, 0+1+2, 1+2, 2}},
{{1, 1, 1, 1}}
}};
bool ok = true;
for(int i=0;i<4;i++){
for(int j=0;j<4;j++){
if(!nearlyEqual(R[i][j], Expected[i][j])) ok = false;
}
}
std::cout << (ok ? "OK\n" : "FAIL\n");
}
void test_translate() {
Vec3 v{1,2,3};
Mat4 T = translate({5,-2,1});
Vec3 out = T * v;
std::cout << "Test translate (Vec3{1,2,3} + {5,-2,1}): ";
if(nearlyEqual(out.x, 6) && nearlyEqual(out.y, 0) && nearlyEqual(out.z, 4))
std::cout << "OK\n";
else
std::cout << "FAIL (" << out.x << "," << out.y << "," << out.z << ")\n";
}
void test_rotZ_90() {
Vec3 v{1,0,0};
Mat4 Rm = rot3D(90, 'z');
Vec3 out = Rm * v;
std::cout << "Test rot3D Z 90° (1,0,0 -> 0,1,0): ";
if(nearlyEqual(out.x, 0) && nearlyEqual(out.y, 1))
std::cout << "OK\n";
else
std::cout << "FAIL (" << out.x << "," << out.y << "," << out.z << ")\n";
}
void test_rotX_180() {
Vec3 v{0,1,0};
Mat4 Rm = rot3D(180, 'x');
Vec3 out = Rm * v;
std::cout << "Test rot3D X 180° (0,1,0 -> 0,-1,0): ";
if(nearlyEqual(out.y, -1))
std::cout << "OK\n";
else
std::cout << "FAIL (" << out.x << "," << out.y << "," << out.z << ")\n";
}
void test_rotY_270() {
Vec3 v{1,0,0};
Mat4 Rm = rot3D(270, 'y');
Vec3 out = Rm * v;
std::cout << "Test rot3D Y 270° (1,0,0 -> 0,0,-1): ";
if(nearlyEqual(out.x, 0) && nearlyEqual(out.z, -1))
std::cout << "OK\n";
else
std::cout << "FAIL (" << out.x << "," << out.y << "," << out.z << ")\n";
}
int main() {
std::cout << "===== Matrix3D Tests =====\n";
test_matmul_identity();
test_matmul_example();
test_translate();
test_rotZ_90();
test_rotX_180();
test_rotY_270();
std::cout << "==========================\n";
return 0;
}

42
docs/tests.txt Normal file
View File

@ -0,0 +1,42 @@
========================================================
Projekt: gamematrix (C++ Library)
Rolle: Tester
Datei: tests.txt
Datum: ____________________
Team: ____________________
========================================================
# ----------------------------
# 1. Testplan Übersicht
# ----------------------------
Ziel: Überprüfung der Funktionen matmul(), translate(), rot3D().
| Funktion | Testfall | Eingabe | Erwartetes Ergebnis | Bemerkung |
|---------------|---------------------------|------------------------------|-----------------------------------|----------------------------|
| matmul | Identity * Identity | 4x4 Identity Matrizen | Identity | Basisfall |
| matmul | Beispielmatrizen | A=[[...]], B=[[...]] | C=[[...]] | Prüfen mit Handrechnung |
| translate | Verschiebung | Vec3 {1,2,3} | Matrix mit Translation 1,2,3 | Prüfen letzte Spalte |
| rot3D | Rotation Z 90° | angle_deg=90, axis='z' | (1,0,0) -> (0,1,0) | Prüfen Anwendung auf Vektor|
| rot3D | Rotation X 180° | angle_deg=180, axis='x' | (0,1,0) -> (0,-1,0) | Prüfen Anwendung auf Vektor|
| rot3D | Rotation Y 270° | angle_deg=270, axis='y' | (1,0,0) -> (0,0,-1) | Prüfen Anwendung auf Vektor|
# ----------------------------
# 2. Testdaten / Matrizen
# ----------------------------
- Matrizen für matmul: Identity, Beispiel A/B Matrizen
- Vektoren für translate: Vec3 {x, y, z}
- Vektoren für rot3D: Vec3 {1,0,0}, Vec3 {0,1,0}
# ----------------------------
# 3. Abnahmekriterien
# ----------------------------
- Alle Unit-Tests erfolgreich
- Keine Exceptions außer gewollt (z.B. ungültige Achse)
- Testbericht in tests.txt dokumentiert
========================================================
Hinweis:
- Diese Datei wird vom Tester gepflegt.
- Tester dokumentiert Input, Output, erwartetes Ergebnis und Erfolg/Fehler.
========================================================

View File

@ -2,6 +2,9 @@
#include "gamematrix.h" #include "gamematrix.h"
#include "raylib.h" #include "raylib.h"
#include <rlgl.h> #include <rlgl.h>
#include <array>
using Mat4 = std::array<std::array<double, 4>, 4>;
struct Vec3 struct Vec3
{ {

View File

@ -3,6 +3,7 @@
#include <array> #include <array>
#include <stdexcept> #include <stdexcept>
#include <cmath> #include <cmath>
#include "gamecube.h"
class gameMatrix class gameMatrix
{ {

View File

@ -1,10 +1,10 @@
#include "gamecube.h" #include "gamecube.h"
gamecube::gamecube(const Vec3 &pos, Color col) gamecube::gamecube(const Vec3 &pos, Color col)
: position(pos), color(col) {} : position(pos), color(col) {}
void gamecube::Update(float flipSpeed) void gamecube::Update(float flipSpeed)
{ {
//Tom: Added vars for clarity; replaced old 180.0f, 0.0f //Tom: Added vars for clarity; replaced old 180.0f, 0.0f
const float MaxRotationAngle = 180.0f; const float MaxRotationAngle = 180.0f;
const float NoRotationAngle = 0.0f; const float NoRotationAngle = 0.0f;
@ -29,17 +29,17 @@ void gamecube::Update(float flipSpeed)
flipped = false; flipped = false;
} }
} }
} }
void gamecube::FlipForward() { flippingForward = true; } void gamecube::FlipForward() { flippingForward = true; }
void gamecube::FlipBackward() { flippingBackward = true; } void gamecube::FlipBackward() { flippingBackward = true; }
bool gamecube::IsFlipped() const { return flipped; } bool gamecube::IsFlipped() const { return flipped; }
bool gamecube::IsMatched() const { return matched; } bool gamecube::IsMatched() const { return matched; }
void gamecube::SetMatched(bool m) { matched = m; } void gamecube::SetMatched(bool m) { matched = m; }
void gamecube::Draw() const void gamecube::Draw() const
{ {
rlPushMatrix(); rlPushMatrix();
// Matrizen für Rotation und Translation erzeugen // Matrizen für Rotation und Translation erzeugen
@ -64,7 +64,7 @@ void gamecube::Draw() const
DrawCubeWires({0,0,0}, 1,1,1, BLACK); DrawCubeWires({0,0,0}, 1,1,1, BLACK);
rlPopMatrix(); rlPopMatrix();
} }
Vec3 gamecube::GetPosition() const { return position; } Vec3 gamecube::GetPosition() const { return position; }
float gamecube::GetRotationY() const { return rotation; } float gamecube::GetRotationY() const { return rotation; }

75
src/gamematrix.cpp Normal file
View File

@ -0,0 +1,75 @@
#include "gamematrix.h"
#include <cmath>
// Entfernt: namespace Matrix3D { ... } <-- GEÄNDERT
// Implementierungen jetzt als Klassenmethoden von gameMatrix <-- GEÄNDERT
// Optional: identity() als Hilfsmethode hinzugefügt
static std::array<std::array<double,4>,4> identity() { // <-- NEU
std::array<std::array<double,4>,4> m{};
for(int i = 0; i < 4; i++) {
for(int j = 0; j < 4; j++) {
m[i][j] = (i == j) ? 1.0 : 0.0;
}
}
return m;
}
// -------------------- matmul --------------------
std::array<std::array<double,4>,4> gameMatrix::matmul( // <-- GEÄNDERT
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> R{};
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];
}
R[i][j] = sum;
}
}
return R;
}
// -------------------- translate --------------------
std::array<std::array<double,4>,4> gameMatrix::translate( // <-- GEÄNDERT
const std::array<double,3>& pos)
{
auto t = identity(); // <-- NEU: nutzt die Hilfsmethode
t[0][3] = pos[0];
t[1][3] = pos[1];
t[2][3] = pos[2];
return t;
}
// -------------------- rot3D --------------------
std::array<std::array<double,4>,4> gameMatrix::rot3D( // <-- GEÄNDERT
double angle_deg, char axis)
{
auto r = identity(); // <-- NEU: nutzt die Hilfsmethode
double rad = angle_deg * M_PI / 180.0;
double c = std::cos(rad);
double s = std::sin(rad);
switch(axis) {
case 'x': case 'X':
r[1][1] = c; r[1][2] = -s;
r[2][1] = s; r[2][2] = c;
break;
case 'y': case 'Y':
r[0][0] = c; r[0][2] = s;
r[2][0] = -s; r[2][2] = c;
break;
case 'z': case 'Z':
r[0][0] = c; r[0][1] = -s;
r[1][0] = s; r[1][1] = c;
break;
}
return r;
}

View File

@ -1,4 +1,5 @@
#include "gamecube.h" #include "gamecube.h"
#include "gamematrix.h"
#include <algorithm> #include <algorithm>
#include <ctime> #include <ctime>