Funktionsfähig gemacht
This commit is contained in:
parent
16e918b180
commit
69dfbdf139
@ -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
|
||||||
{
|
{
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
#include <array>
|
#include <array>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include "gamecube.h"
|
||||||
|
|
||||||
class gameMatrix
|
class gameMatrix
|
||||||
{
|
{
|
||||||
|
|||||||
@ -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; }
|
||||||
@ -1,20 +1,27 @@
|
|||||||
#include "gamematrix.h"
|
#include "gamematrix.h"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
namespace Matrix3D {
|
// Entfernt: namespace Matrix3D { ... } <-- GEÄNDERT
|
||||||
|
|
||||||
Mat4 identity() {
|
// Implementierungen jetzt als Klassenmethoden von gameMatrix <-- GEÄNDERT
|
||||||
Mat4 m{};
|
|
||||||
|
// 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 i = 0; i < 4; i++) {
|
||||||
for(int j = 0; j < 4; j++) {
|
for(int j = 0; j < 4; j++) {
|
||||||
m[i][j] = (i == j) ? 1.0 : 0.0;
|
m[i][j] = (i == j) ? 1.0 : 0.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
Mat4 matmul(const Mat4& A, const Mat4& B) {
|
// -------------------- matmul --------------------
|
||||||
Mat4 R{};
|
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 i = 0; i < 4; i++) {
|
||||||
for(int j = 0; j < 4; j++) {
|
for(int j = 0; j < 4; j++) {
|
||||||
double sum = 0.0;
|
double sum = 0.0;
|
||||||
@ -25,18 +32,24 @@ namespace Matrix3D {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return R;
|
return R;
|
||||||
}
|
}
|
||||||
|
|
||||||
Mat4 translate(const Vec3& pos) {
|
// -------------------- translate --------------------
|
||||||
Mat4 t = identity();
|
std::array<std::array<double,4>,4> gameMatrix::translate( // <-- GEÄNDERT
|
||||||
t[0][3] = pos.x;
|
const std::array<double,3>& pos)
|
||||||
t[1][3] = pos.y;
|
{
|
||||||
t[2][3] = pos.z;
|
auto t = identity(); // <-- NEU: nutzt die Hilfsmethode
|
||||||
|
t[0][3] = pos[0];
|
||||||
|
t[1][3] = pos[1];
|
||||||
|
t[2][3] = pos[2];
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
Mat4 rot3D(double angle_deg, char axis) {
|
// -------------------- rot3D --------------------
|
||||||
Mat4 r = identity();
|
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 rad = angle_deg * M_PI / 180.0;
|
||||||
double c = std::cos(rad);
|
double c = std::cos(rad);
|
||||||
@ -59,18 +72,4 @@ namespace Matrix3D {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
}
|
|
||||||
|
|
||||||
Vec3 operator*(const Mat4& M, const Vec3& v) {
|
|
||||||
Vec3 out;
|
|
||||||
out.x = M[0][0]*v.x + M[0][1]*v.y + M[0][2]*v.z + M[0][3];
|
|
||||||
out.y = M[1][0]*v.x + M[1][1]*v.y + M[1][2]*v.z + M[1][3];
|
|
||||||
out.z = M[2][0]*v.x + M[2][1]*v.y + M[2][2]*v.z + M[2][3];
|
|
||||||
return out;
|
|
||||||
}
|
|
||||||
|
|
||||||
Mat4 operator*(const Mat4& A, const Mat4& B) {
|
|
||||||
return matmul(A, B);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user