functions matmul, rot3D, translate
This commit is contained in:
parent
ed1bf4a9b1
commit
ad3ae081a9
77
src/gamematrix.cpp
Normal file
77
src/gamematrix.cpp
Normal file
@ -0,0 +1,77 @@
|
||||
#include <gamematrix.h>
|
||||
|
||||
|
||||
static 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;
|
||||
}
|
||||
|
||||
|
||||
static 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;
|
||||
}
|
||||
|
||||
static 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.
|
||||
//
|
||||
Loading…
x
Reference in New Issue
Block a user