From 53eacdae43b9ff959c3f64088391807bba9e7f07 Mon Sep 17 00:00:00 2001 From: jaby Date: Tue, 2 Apr 2024 11:24:11 -0500 Subject: [PATCH] =?UTF-8?q?Rotate=20D=C3=B6nerfisch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/Overlay/GTETest/gte_test.cpp | 27 ++++++++---- include/PSX/GTE/gte.hpp | 2 +- include/PSX/GTE/gte_types.hpp | 3 ++ src/Library/reference/about_inline_n.md | 38 +++++++++++++++- src/Library/src/GTE/gte.cpp | 43 ++++++++++++++++++- 5 files changed, 101 insertions(+), 12 deletions(-) diff --git a/examples/PoolBox/application/src/Overlay/GTETest/gte_test.cpp b/examples/PoolBox/application/src/Overlay/GTETest/gte_test.cpp index 999ddac2..57c1ffdc 100644 --- a/examples/PoolBox/application/src/Overlay/GTETest/gte_test.cpp +++ b/examples/PoolBox/application/src/Overlay/GTETest/gte_test.cpp @@ -8,20 +8,25 @@ namespace GTETest { using namespace JabyEngine; - static auto matrix = GTE::MATRIX::identity(); + static auto matrix = GTE::MATRIX::identity(); + static GPU::POLY_FT4 doener_fish; + static auto rotation = 5_DEG; - static auto doener_fish = Make::POLY_FT4( - GPU::Display::center(Make::AreaI16(Make::PositionI16(0, 0), Assets::Main::DoenerFishInfo.size)), - Assets::Main::DoenerFishInfo.tim.get_page_offset_clut4(), - Make::TPage(Assets::Main::DoenerFishInfo.tim.get_texture_position(), GPU::SemiTransparency::B_add_F, GPU::TextureColorMode::clut4), - Make::PageClut(Assets::Main::DoenerFishInfo.tim.get_clut_position()), - GPU::Color24::Grey() - ); + static GPU::POLY_FT4 create_doener_fish() { + return Make::POLY_FT4( + GPU::Display::center(Make::AreaI16(Make::PositionI16(0, 0), Assets::Main::DoenerFishInfo.size)), + Assets::Main::DoenerFishInfo.tim.get_page_offset_clut4(), + Make::TPage(Assets::Main::DoenerFishInfo.tim.get_texture_position(), GPU::SemiTransparency::B_add_F, GPU::TextureColorMode::clut4), + Make::PageClut(Assets::Main::DoenerFishInfo.tim.get_clut_position()), + GPU::Color24::Grey() + ); + } static void setup() { Shared::back_menu.reset(); - matrix.trans[0] += 50; + matrix = GTE::MATRIX::rotation(0, 0, 0); + doener_fish = create_doener_fish(); GTE::set_geom_offset(0, 0); GTE::set_geom_screen(512); @@ -37,6 +42,7 @@ namespace GTETest { GTE::set_rot_matrix(matrix); // for now? + doener_fish = create_doener_fish(); GPU::Vertex* doener_vertices[] = {&doener_fish.vertex0, &doener_fish.vertex1, &doener_fish.vertex2, &doener_fish.vertex3}; for(auto* vertex : doener_vertices) { GTE::VECTOR output; @@ -46,6 +52,9 @@ namespace GTETest { *vertex = output.to(); } + matrix = GTE::MATRIX::rotation(0, 0, rotation); + rotation += 5_DEG; + //GTE::multiply_matrix(matrix, GTE::MATRIX::rotation(0, 0, 5_DEG), matrix); return false; } diff --git a/include/PSX/GTE/gte.hpp b/include/PSX/GTE/gte.hpp index dae1c0a7..359dd6d6 100644 --- a/include/PSX/GTE/gte.hpp +++ b/include/PSX/GTE/gte.hpp @@ -8,7 +8,7 @@ namespace JabyEngine { /* RotTrans - Jaby: Can we use gte_stsv instead of gte_stlvnl for writing to a SVECTOR? + TODO: Can we use gte_stsv instead of gte_stlvnl for writing to a SVECTOR? Do we have to use gte_stflg?? Look at: RotTransSV??? diff --git a/include/PSX/GTE/gte_types.hpp b/include/PSX/GTE/gte_types.hpp index d28515de..b5482b1d 100644 --- a/include/PSX/GTE/gte_types.hpp +++ b/include/PSX/GTE/gte_types.hpp @@ -32,6 +32,7 @@ namespace JabyEngine { }; } + // TODO: Split MATRIX into ROTMATRIX and TRANSFERVECTOR or something like that. But first get it running struct MATRIX { int16_t rot[3][3]; // Rotation matrix int32_t trans[3]; // Translation vector @@ -46,6 +47,8 @@ namespace JabyEngine { .trans = {0, 0, 0} }; } + + static MATRIX rotation(int32_t x, int32_t y, int32_t z); }; using VECTOR = internal::VECTOR; diff --git a/src/Library/reference/about_inline_n.md b/src/Library/reference/about_inline_n.md index 19deef73..87206878 100644 --- a/src/Library/reference/about_inline_n.md +++ b/src/Library/reference/about_inline_n.md @@ -1,3 +1,39 @@ # inline_n.h -This header is directly lifted from psx-redux and not my creation. I will try to give it my personal touch but the original implementation will be always from [pcsx-redux](https://github.com/grumpycoders/pcsx-redux) and the **grumpycoders**. \ No newline at end of file +This header is directly lifted from psx-redux and not my creation. I will try to give it my personal touch but the original implementation will be always from [pcsx-redux](https://github.com/grumpycoders/pcsx-redux) and the **grumpycoders**. + +```c++ +MATRIX *HiRotMatrix(VECTOR *r, MATRIX *m) { + + short s[3],c[3]; + MATRIX tm[3]; + + s[0] = hisin(r->vx); s[1] = hisin(r->vy); s[2] = hisin(r->vz); + c[0] = hicos(r->vx); c[1] = hicos(r->vy); c[2] = hicos(r->vz); + + // mX + m->m[0][0] = ONE; m->m[0][1] = 0; m->m[0][2] = 0; + m->m[1][0] = 0; m->m[1][1] = c[0]; m->m[1][2] = -s[0]; + m->m[2][0] = 0; m->m[2][1] = s[0]; m->m[2][2] = c[0]; + + // mY + tm[0].m[0][0] = c[1]; tm[0].m[0][1] = 0; tm[0].m[0][2] = s[1]; + tm[0].m[1][0] = 0; tm[0].m[1][1] = ONE; tm[0].m[1][2] = 0; + tm[0].m[2][0] = -s[1]; tm[0].m[2][1] = 0; tm[0].m[2][2] = c[1]; + + // mZ + tm[1].m[0][0] = c[2]; tm[1].m[0][1] = -s[2]; tm[1].m[0][2] = 0; + tm[1].m[1][0] = s[2]; tm[1].m[1][1] = c[2]; tm[1].m[1][2] = 0; + tm[1].m[2][0] = 0; tm[1].m[2][1] = 0; tm[1].m[2][2] = ONE; + + PushMatrix(); + + MulMatrix0( m, &tm[0], &tm[2] ); + MulMatrix0( &tm[2], &tm[1], m ); + + PopMatrix(); + + return m; + +} +``` \ No newline at end of file diff --git a/src/Library/src/GTE/gte.cpp b/src/Library/src/GTE/gte.cpp index 5a711ea3..1abdd1ed 100644 --- a/src/Library/src/GTE/gte.cpp +++ b/src/Library/src/GTE/gte.cpp @@ -26,6 +26,20 @@ int32_t cos(int32_t value) { namespace JabyEngine { namespace GTE { + namespace MatrixHelper { + struct SinCosPair { + int16_t sin; + int16_t cos; + + static SinCosPair create_for(int32_t value) { + return SinCosPair{ + .sin = static_cast(::sin(value)), + .cos = static_cast(::cos(value)), + }; + } + }; + } + static MATRIX Stack[StackSize]; static MATRIX* FreeStackEntry = Stack; @@ -80,6 +94,33 @@ namespace JabyEngine { pop_matrix(); return matrix; - } + } + + MATRIX MATRIX :: rotation(int32_t x, int32_t y, int32_t z) { + using namespace MatrixHelper; + + const auto sincos_x = SinCosPair::create_for(x); + const auto sincos_y = SinCosPair::create_for(y); + const auto sincos_z = SinCosPair::create_for(z); + + auto rotX = MATRIX::identity(); + rotX.rot[1][1] = sincos_x.cos; rotX.rot[1][2] = -sincos_x.sin; + rotX.rot[2][1] = sincos_x.sin; rotX.rot[2][2] = sincos_x.cos; + + auto rotY = MATRIX::identity(); + rotY.rot[0][0] = sincos_y.cos; rotY.rot[0][2] = sincos_y.sin; + rotY.rot[2][0] = -sincos_y.sin; rotY.rot[2][2] = sincos_y.cos; + + auto rotZ = MATRIX::identity(); + rotZ.rot[0][0] = sincos_z.cos; rotZ.rot[0][1] = -sincos_z.sin; + rotZ.rot[1][0] = sincos_z.sin; rotZ.rot[1][1] = sincos_z.cos; + + push_matrix(); + multiply_matrix(rotX, rotY, rotX); + multiply_matrix(rotX, rotZ, rotX); + pop_matrix(); + + return rotX; + } } } \ No newline at end of file