Compare commits
No commits in common. "8eda60d4981f797641ee7f3dfa857b61065fa7dc" and "6e2119ab017889f0732617abe917bb4f91acd0fe" have entirely different histories.
8eda60d498
...
6e2119ab01
@ -19,6 +19,7 @@ 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
|
src/gamematrix.cpp
|
||||||
|
docs/tests.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
##Tom: prev: ${CMAKE_CURRENT_LIST_DIR}/linux -> now /include
|
##Tom: prev: ${CMAKE_CURRENT_LIST_DIR}/linux -> now /include
|
||||||
|
|||||||
@ -2,9 +2,6 @@
|
|||||||
#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,7 +3,6 @@
|
|||||||
#include <array>
|
#include <array>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include "gamecube.h"
|
|
||||||
|
|
||||||
class gameMatrix
|
class gameMatrix
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,13 +1,10 @@
|
|||||||
#include "gamematrix.h"
|
#include "gamematrix.h"
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
// Entfernt: namespace Matrix3D { ... } <-- GEÄNDERT
|
namespace Matrix3D {
|
||||||
|
|
||||||
// Implementierungen jetzt als Klassenmethoden von gameMatrix <-- GEÄNDERT
|
Mat4 identity() {
|
||||||
|
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;
|
||||||
@ -16,12 +13,8 @@ static std::array<std::array<double,4>,4> identity() { // <-- NEU
|
|||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------- matmul --------------------
|
Mat4 matmul(const Mat4& A, const Mat4& B) {
|
||||||
std::array<std::array<double,4>,4> gameMatrix::matmul( // <-- GEÄNDERT
|
Mat4 R{};
|
||||||
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;
|
||||||
@ -34,22 +27,16 @@ std::array<std::array<double,4>,4> gameMatrix::matmul( // <-- GEÄNDERT
|
|||||||
return R;
|
return R;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------- translate --------------------
|
Mat4 translate(const Vec3& pos) {
|
||||||
std::array<std::array<double,4>,4> gameMatrix::translate( // <-- GEÄNDERT
|
Mat4 t = identity();
|
||||||
const std::array<double,3>& pos)
|
t[0][3] = pos.x;
|
||||||
{
|
t[1][3] = pos.y;
|
||||||
auto t = identity(); // <-- NEU: nutzt die Hilfsmethode
|
t[2][3] = pos.z;
|
||||||
t[0][3] = pos[0];
|
|
||||||
t[1][3] = pos[1];
|
|
||||||
t[2][3] = pos[2];
|
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
// -------------------- rot3D --------------------
|
Mat4 rot3D(double angle_deg, char axis) {
|
||||||
std::array<std::array<double,4>,4> gameMatrix::rot3D( // <-- GEÄNDERT
|
Mat4 r = identity();
|
||||||
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);
|
||||||
@ -73,3 +60,17 @@ std::array<std::array<double,4>,4> gameMatrix::rot3D( // <-- GEÄNDERT
|
|||||||
}
|
}
|
||||||
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