diff --git a/examples/PoolBox/application/src/Overlay/GTETest/include/GTE_Sprite.hpp b/examples/PoolBox/application/src/Overlay/GTETest/include/GTE_Sprite.hpp index 32f8ad7a..1fd470a7 100644 --- a/examples/PoolBox/application/src/Overlay/GTETest/include/GTE_Sprite.hpp +++ b/examples/PoolBox/application/src/Overlay/GTETest/include/GTE_Sprite.hpp @@ -18,19 +18,13 @@ namespace GTETest { } void apply(const GTE::MATRIX& matrix) { - static const auto apply_to = [](const GTE::MATRIX& matrix, GPU::Vertex vertex) -> GPU::Vertex { - GTE::MATRIX move_back = GTE::MATRIX{ - GTE::ROTMATRIX::identity(), GTE::TRANSFERVECTOR::translated(-matrix.transfer.x, -matrix.transfer.y, -matrix.transfer.z) - }; - GTE::comp_matrix(matrix, move_back, move_back); - return GTE::apply_matrix(move_back, vertex, vertex); - }; + const auto move_back = GTE::MATRIX::comp(GTE::MATRIX::translated(-matrix.transfer.x, -matrix.transfer.y, -matrix.transfer.z), matrix); + const auto& area = this->area; - const auto& area = this->area; - this->display.vertex0 = apply_to(matrix, area.get_top_left()); - this->display.vertex1 = apply_to(matrix, area.get_top_right()); - this->display.vertex2 = apply_to(matrix, area.get_bottom_left()); - this->display.vertex3 = apply_to(matrix, area.get_bottom_right()); + this->display.vertex0 = move_back.apply_to(area.get_top_left()); + this->display.vertex1 = move_back.apply_to(area.get_top_right()); + this->display.vertex2 = move_back.apply_to(area.get_bottom_left()); + this->display.vertex3 = move_back.apply_to(area.get_bottom_right()); } void render() { diff --git a/include/PSX/GTE/gte.hpp b/include/PSX/GTE/gte.hpp index 7c271963..6a7f92e6 100644 --- a/include/PSX/GTE/gte.hpp +++ b/include/PSX/GTE/gte.hpp @@ -202,5 +202,21 @@ namespace JabyEngine { static void set_geom_screen(int32_t h) { __asm__ volatile("ctc2 %0, $26" :: "r"(h)); } + + // Implementations for the MATRIX struct + inline MATRIX& MATRIX :: comp(const MATRIX& matrix) { + return comp_matrix(matrix, *this, *this); + } + + inline GPU::Vertex& MATRIX :: apply_to(GPU::Vertex& vertex) const { + return apply_matrix(*this, vertex, vertex); + } + + inline GPU::Vertex MATRIX :: apply_to(const GPU::Vertex& vertex) const { + GPU::Vertex result; + + apply_matrix(*this, vertex, result); + return result; + } } } \ No newline at end of file diff --git a/include/PSX/GTE/gte_types.hpp b/include/PSX/GTE/gte_types.hpp index 603ecd96..907fcc11 100644 --- a/include/PSX/GTE/gte_types.hpp +++ b/include/PSX/GTE/gte_types.hpp @@ -60,11 +60,28 @@ namespace JabyEngine { struct MATRIX { ROTMATRIX rotation; - TRANSFERVECTOR transfer; + TRANSFERVECTOR transfer; static constexpr MATRIX identity() { return MATRIX{.rotation = ROTMATRIX::identity(), .transfer = TRANSFERVECTOR::identity()}; } + + static constexpr MATRIX translated(int32_t x = 0, int32_t y = 0, int32_t z = 0) { + return MATRIX{.rotation = ROTMATRIX::identity(), .transfer = TRANSFERVECTOR::translated(x, y, z)}; + } + + static constexpr MATRIX rotated(int32_t x_deg = 0, int32_t y_deg = 0, int32_t z_deg = 0) { + return MATRIX{.rotation = ROTMATRIX::rotated(x_deg, y_deg, z_deg), .transfer = TRANSFERVECTOR::identity()}; + } + + static MATRIX comp(MATRIX new_matrix, const MATRIX& matrix) { + new_matrix.comp(matrix); + return new_matrix; + } + + MATRIX& comp(const MATRIX& matrix); + GPU::Vertex& apply_to(GPU::Vertex& vertex) const; + GPU::Vertex apply_to(const GPU::Vertex& vertex) const; }; static constexpr auto one_degree = FULL_CIRCLE/360;