Support proper scaling and other MATRIX operations

This commit is contained in:
2024-04-23 23:04:17 +02:00
parent b4099a7f97
commit 0d16995895
5 changed files with 133 additions and 32 deletions

View File

@@ -1,6 +1,8 @@
#pragma once
#include "../GPU/Primitives/primitive_poly_types.hpp"
#include "../GPU/gpu_types.hpp"
#include "../../math.hpp"
#include "../../stdio.hpp"
namespace JabyEngine {
namespace GTE {
@@ -50,7 +52,16 @@ namespace JabyEngine {
};
}
static ROTMATRIX rotated(deg_t x = deg_t::zero(), deg_t y = deg_t::zero(), deg_t z = deg_t::zero());
static constexpr ROTMATRIX scaled(gte_float sx = 1.0_gf, gte_float sy = 1.0_gf, gte_float sz = 1.0_gf) {
return ROTMATRIX{.matrix = {
{static_cast<int16_t>(sx), 0, 0},
{0, static_cast<int16_t>(sy), 0},
{0, 0, static_cast<int16_t>(sz)}
}
};
}
static ROTMATRIX rotated(deg_t x = 0.0_deg, deg_t y = 0.0_deg, deg_t z = 0.0_deg);
};
struct TRANSFERVECTOR : public VECTOR {
@@ -75,7 +86,11 @@ namespace JabyEngine {
return MATRIX{.rotation = ROTMATRIX::identity(), .transfer = TRANSFERVECTOR::translated(x, y, z)};
}
static MATRIX rotated(deg_t x = deg_t::zero(), deg_t y = deg_t::zero(), deg_t z = deg_t::zero()) {
static constexpr MATRIX scaled(gte_float sx = 1.0_gf, gte_float sy = 1.0_gf, gte_float sz = 1.0_gf) {
return MATRIX{.rotation = ROTMATRIX::scaled(sx, sy, sz), .transfer = TRANSFERVECTOR::identity()};
}
static MATRIX rotated(deg_t x = 0.0_deg, deg_t y = 0.0_deg, deg_t z = 0.0_deg) {
return MATRIX{.rotation = ROTMATRIX::rotated(x, y, z), .transfer = TRANSFERVECTOR::identity()};
}
@@ -84,9 +99,40 @@ namespace JabyEngine {
return new_matrix;
}
MATRIX& comp(const MATRIX& matrix);
void dump() const {
printf("---\n");
printf("|%i|%i|%i|\n", this->rotation.matrix[0][0], this->rotation.matrix[0][1], this->rotation.matrix[0][2]);
printf("|%i|%i|%i|\n", this->rotation.matrix[1][0], this->rotation.matrix[1][1], this->rotation.matrix[1][2]);
printf("|%i|%i|%i|\n", this->rotation.matrix[2][0], this->rotation.matrix[2][1], this->rotation.matrix[2][2]);
printf("~~~\n");
printf("|%i|%i|%i|\n", this->transfer.x, this->transfer.y, this->transfer.z);
printf("---\n");
}
MATRIX& comp(const MATRIX& matrix);
MATRIX& translate(int32_t x = 0, int32_t y = 0, int32_t z = 0) {
return MATRIX::comp(MATRIX::translated(x, y, z));
}
MATRIX& scale(gte_float sx = 1.0_gf, gte_float sy = 1.0_gf, gte_float sz = 1.0_gf) {
return MATRIX::comp(MATRIX::scaled(sx, sy, sz));
}
MATRIX& rotate(deg_t x = 0.0_deg, deg_t y = 0.0_deg, deg_t z = 0.0_deg) {
return MATRIX::comp(MATRIX::rotated(x, y, z));
}
GPU::Vertex& apply_to(GPU::Vertex& vertex) const;
GPU::Vertex apply_to(const GPU::Vertex& vertex) const;
GPU::POLY_FT4& apply_to(GPU::POLY_FT4& poly) const {
MATRIX::apply_to(poly.vertex0);
MATRIX::apply_to(poly.vertex1);
MATRIX::apply_to(poly.vertex2);
MATRIX::apply_to(poly.vertex3);
return poly;
}
};
}
}