From 02180b8af7ad4aa331ff69abf662711c2e83b156 Mon Sep 17 00:00:00 2001 From: Joachim Divet Date: Sun, 26 Jul 2026 14:39:12 +0200 Subject: [PATCH 1/3] Implement K2dPicture::getNewColor --- include/Kameda/K2DPicture.h | 13 +++++-- src/Kameda/K2DPicture.cpp | 69 ++++++++++++++++++++++++++++++++++--- 2 files changed, 76 insertions(+), 6 deletions(-) diff --git a/include/Kameda/K2DPicture.h b/include/Kameda/K2DPicture.h index 6a6005ff..d9bc8117 100644 --- a/include/Kameda/K2DPicture.h +++ b/include/Kameda/K2DPicture.h @@ -8,12 +8,21 @@ class K2DPicture { // Autogenerated public: void drawK2D(f32, f32, f32, f32, bool); // 0x8013b9e8 void setTevModeK2D(); // 0x8013bd34 - void makeMatrix(f32, f32); // 0x8013c0fc + void makeMatrix(f32 x, f32 y); // 0x8013c0fc static u8 mK2DGlobalAlpha; // 0x804145a8 // Inline/Unused void drawOutK2D(const JGeometry::TBox2f &, const JGeometry::TBox2f &); ~K2DPicture(); // Inline - void getNewColor(JUTColor *); // 0x8013bbf8 + void getNewColor(JUTColor colors[4]); // 0x8013bbf8 +private: + u8 _00[0x50]; // 0x00 + float mMatrix[4][4]; // 0x50 + u8 _90[0xb0 - 0x90]; // 0x90 + JUTColor _b0; //0xb0 + u8 _b4[0xc0 - 0xb4]; // 0xb4 + f32 _c0; // 0xc0 + u8 _c4[0x150 - 0xc4]; // 0xc4 + JUTColor mColors[4]; //0x150 }; // class K2DPicture #endif // K2DPICTURE_H diff --git a/src/Kameda/K2DPicture.cpp b/src/Kameda/K2DPicture.cpp index 8f646b55..09dc5d0c 100644 --- a/src/Kameda/K2DPicture.cpp +++ b/src/Kameda/K2DPicture.cpp @@ -1,9 +1,70 @@ #include "Kameda/K2DPicture.h" -void K2DPicture::drawK2D(float, float, float, float, bool) {} +#include "dolphin/gx/GXGeometry.h" +#include "dolphin/mtx.h" -void K2DPicture::getNewColor(JUTColor *) {} +static const float _g00 = 0.f; +static const u32 _g04 = 0x3c8efa35; -void K2DPicture::setTevModeK2D() {} +void K2DPicture::drawK2D(float, float, float, float, bool) { -void K2DPicture::makeMatrix(f32, f32) {} + JUTColor color; + GXSetNumTexGens(0); + + getNewColor(&color); +} + +void K2DPicture::getNewColor(JUTColor colors[4]) { + colors[0].r = mColors[0].r; + colors[0].g = mColors[0].g; + colors[0].b = mColors[0].b; + colors[0].a = mColors[0].a; + + colors[1].r = mColors[1].r; + colors[1].g = mColors[1].g; + colors[1].b = mColors[1].b; + colors[1].a = mColors[1].a; + + colors[2].r = mColors[2].r; + colors[2].g = mColors[2].g; + colors[2].b = mColors[2].b; + colors[2].a = mColors[2].a; + + colors[3].r = mColors[3].r; + colors[3].g = mColors[3].g; + colors[3].b = mColors[3].b; + colors[3].a = mColors[3].a; + + if(_b0.a != 0xFF) + { + colors[0].a = (colors[0].a * _b0.a / 0xFF); + colors[1].a = (colors[1].a * _b0.a / 0xFF); + colors[2].a = (colors[2].a * _b0.a / 0xFF); + colors[3].a = (colors[3].a * _b0.a / 0xFF); + } + + if(mK2DGlobalAlpha == 0xFF) + { + return; + } + colors[0].a = ((colors[0].a * mK2DGlobalAlpha) / 0xFF); + colors[1].a = ((colors[1].a * mK2DGlobalAlpha) / 0xFF); + colors[2].a = ((colors[2].a * mK2DGlobalAlpha) / 0xFF); + colors[3].a = ((colors[3].a * mK2DGlobalAlpha) / 0xFF); +} + +void K2DPicture::setTevModeK2D() { + +} + +void K2DPicture::makeMatrix(f32 x, f32 y) { + f32 _matrix[4][4]; + u8 _padding[0x100]; + + if(_c0 != _g00) + { + + } + + PSMTXTrans(mMatrix, x, y, _g00); +} From 8072317b71f6d02db08dc9856e794cf35c5a2c4e Mon Sep 17 00:00:00 2001 From: Joachim Divet Date: Sun, 26 Jul 2026 21:38:36 +0200 Subject: [PATCH 2/3] Add K2DPicture::makeMatrix --- include/Kameda/K2DPicture.h | 13 +++++++++---- src/Kameda/K2DPicture.cpp | 31 +++++++++++++++++++++++-------- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/include/Kameda/K2DPicture.h b/include/Kameda/K2DPicture.h index d9bc8117..a8812ed6 100644 --- a/include/Kameda/K2DPicture.h +++ b/include/Kameda/K2DPicture.h @@ -17,12 +17,17 @@ class K2DPicture { // Autogenerated void getNewColor(JUTColor colors[4]); // 0x8013bbf8 private: u8 _00[0x50]; // 0x00 - float mMatrix[4][4]; // 0x50 - u8 _90[0xb0 - 0x90]; // 0x90 + Mtx mMatrix; // 0x50 + u8 _80[0xb0 - 0x80]; // 0x80 JUTColor _b0; //0xb0 - u8 _b4[0xc0 - 0xb4]; // 0xb4 + u8 _padding[2]; // 0xb4 + char mAxis; // 0xb6 + u8 _padding2; //0xb7 + u8 _b8[0xc0 - 0xb8]; // 0xb8 f32 _c0; // 0xc0 - u8 _c4[0x150 - 0xc4]; // 0xc4 + f32 _c4; // 0xc4 + f32 _c8; // 0xc8 + u8 _cc[0x150 - 0xcc]; // 0xcc JUTColor mColors[4]; //0x150 }; // class K2DPicture #endif // K2DPICTURE_H diff --git a/src/Kameda/K2DPicture.cpp b/src/Kameda/K2DPicture.cpp index 09dc5d0c..0be3f0fb 100644 --- a/src/Kameda/K2DPicture.cpp +++ b/src/Kameda/K2DPicture.cpp @@ -3,8 +3,8 @@ #include "dolphin/gx/GXGeometry.h" #include "dolphin/mtx.h" -static const float _g00 = 0.f; -static const u32 _g04 = 0x3c8efa35; +static const f32 _g00 = 0.f; +static const f32 sDegToRad = 0.017453292f; void K2DPicture::drawK2D(float, float, float, float, bool) { @@ -58,13 +58,28 @@ void K2DPicture::setTevModeK2D() { } void K2DPicture::makeMatrix(f32 x, f32 y) { - f32 _matrix[4][4]; - u8 _padding[0x100]; + Mtx _matrix_1; + Mtx _matrix_2; + Mtx _matrix_3; - if(_c0 != _g00) - { + if (_c0 != _g00) { + PSMTXTrans(_matrix_1, -_c4, -_c8, _g00); - } + f32 degree; + if (mAxis == 'z') { + degree = -_c0; + } else { + degree = _c0; + } + + PSMTXRotRad(_matrix_2, mAxis, degree * sDegToRad); - PSMTXTrans(mMatrix, x, y, _g00); + PSMTXTrans(_matrix_3, _c4 + x, _c8 + y, _g00); + + PSMTXConcat(_matrix_2, _matrix_1, mMatrix); + + PSMTXConcat(_matrix_3, mMatrix, mMatrix); + } else { + PSMTXTrans(mMatrix, x, y, _g00); + } } From bd7399bd5291b4ed32fbc1d2bea2f41f102f3177 Mon Sep 17 00:00:00 2001 From: Joachim Divet Date: Fri, 31 Jul 2026 08:35:02 +0200 Subject: [PATCH 3/3] Add K2DPicture::setTevModeK2D --- include/JSystem/J2D/J2DPane.h | 2 +- include/Kameda/K2DPicture.h | 17 +--- src/Kameda/K2DPicture.cpp | 176 +++++++++++++++++++++++++++------- 3 files changed, 142 insertions(+), 53 deletions(-) diff --git a/include/JSystem/J2D/J2DPane.h b/include/JSystem/J2D/J2DPane.h index 7ccec81f..fece5f04 100644 --- a/include/JSystem/J2D/J2DPane.h +++ b/include/JSystem/J2D/J2DPane.h @@ -401,7 +401,7 @@ struct J2DPane u8 mColorAlpha; // _0B3 bool mIsInfluencedAlpha; // _0B4 bool mIsConnected; // _0B5 - u8 mRotationAxis; // _0B6 + char mRotationAxis; // _0B6 u8 mBasePosition; // _0B7 f32 mAngleX; // _0B8 f32 mAngleY; // _0BC diff --git a/include/Kameda/K2DPicture.h b/include/Kameda/K2DPicture.h index a8812ed6..96fe4541 100644 --- a/include/Kameda/K2DPicture.h +++ b/include/Kameda/K2DPicture.h @@ -1,10 +1,11 @@ #ifndef K2DPICTURE_H #define K2DPICTURE_H +#include "JSystem/J2D/J2DPicture.h" #include "JSystem/JGeometry/Box.h" #include "JSystem/JUtility/TColor.h" -class K2DPicture { // Autogenerated +class K2DPicture : public J2DPicture { public: void drawK2D(f32, f32, f32, f32, bool); // 0x8013b9e8 void setTevModeK2D(); // 0x8013bd34 @@ -15,19 +16,5 @@ class K2DPicture { // Autogenerated ~K2DPicture(); // Inline void getNewColor(JUTColor colors[4]); // 0x8013bbf8 -private: - u8 _00[0x50]; // 0x00 - Mtx mMatrix; // 0x50 - u8 _80[0xb0 - 0x80]; // 0x80 - JUTColor _b0; //0xb0 - u8 _padding[2]; // 0xb4 - char mAxis; // 0xb6 - u8 _padding2; //0xb7 - u8 _b8[0xc0 - 0xb8]; // 0xb8 - f32 _c0; // 0xc0 - f32 _c4; // 0xc4 - f32 _c8; // 0xc8 - u8 _cc[0x150 - 0xcc]; // 0xcc - JUTColor mColors[4]; //0x150 }; // class K2DPicture #endif // K2DPICTURE_H diff --git a/src/Kameda/K2DPicture.cpp b/src/Kameda/K2DPicture.cpp index 0be3f0fb..6e13d22b 100644 --- a/src/Kameda/K2DPicture.cpp +++ b/src/Kameda/K2DPicture.cpp @@ -1,13 +1,24 @@ #include "Kameda/K2DPicture.h" +#include "dolphin/gx/GXEnum.h" #include "dolphin/gx/GXGeometry.h" +#include "dolphin/gx/GXLighting.h" +#include "dolphin/gx/GXPixel.h" +#include "dolphin/gx/GXStruct.h" +#include "dolphin/gx/GXTev.h" #include "dolphin/mtx.h" -static const f32 _g00 = 0.f; +static const f32 sZeroDegreeAngle = 0.f; static const f32 sDegToRad = 0.017453292f; +u8 K2DPicture::mK2DGlobalAlpha = 0xFF; + void K2DPicture::drawK2D(float, float, float, float, bool) { + if(!mIsVisible) + { + return; + } JUTColor color; GXSetNumTexGens(0); @@ -15,32 +26,32 @@ void K2DPicture::drawK2D(float, float, float, float, bool) { } void K2DPicture::getNewColor(JUTColor colors[4]) { - colors[0].r = mColors[0].r; - colors[0].g = mColors[0].g; - colors[0].b = mColors[0].b; - colors[0].a = mColors[0].a; - - colors[1].r = mColors[1].r; - colors[1].g = mColors[1].g; - colors[1].b = mColors[1].b; - colors[1].a = mColors[1].a; - - colors[2].r = mColors[2].r; - colors[2].g = mColors[2].g; - colors[2].b = mColors[2].b; - colors[2].a = mColors[2].a; - - colors[3].r = mColors[3].r; - colors[3].g = mColors[3].g; - colors[3].b = mColors[3].b; - colors[3].a = mColors[3].a; - - if(_b0.a != 0xFF) + colors[0].r = mCornerColors[0].r; + colors[0].g = mCornerColors[0].g; + colors[0].b = mCornerColors[0].b; + colors[0].a = mCornerColors[0].a; + + colors[1].r = mCornerColors[1].r; + colors[1].g = mCornerColors[1].g; + colors[1].b = mCornerColors[1].b; + colors[1].a = mCornerColors[1].a; + + colors[2].r = mCornerColors[2].r; + colors[2].g = mCornerColors[2].g; + colors[2].b = mCornerColors[2].b; + colors[2].a = mCornerColors[2].a; + + colors[3].r = mCornerColors[3].r; + colors[3].g = mCornerColors[3].g; + colors[3].b = mCornerColors[3].b; + colors[3].a = mCornerColors[3].a; + + if(mColorAlpha != 0xFF) { - colors[0].a = (colors[0].a * _b0.a / 0xFF); - colors[1].a = (colors[1].a * _b0.a / 0xFF); - colors[2].a = (colors[2].a * _b0.a / 0xFF); - colors[3].a = (colors[3].a * _b0.a / 0xFF); + colors[0].a = (colors[0].a * mColorAlpha / 0xFF); + colors[1].a = (colors[1].a * mColorAlpha / 0xFF); + colors[2].a = (colors[2].a * mColorAlpha / 0xFF); + colors[3].a = (colors[3].a * mColorAlpha / 0xFF); } if(mK2DGlobalAlpha == 0xFF) @@ -54,32 +65,123 @@ void K2DPicture::getNewColor(JUTColor colors[4]) { } void K2DPicture::setTevModeK2D() { + bool test = false; + bool test_2 = false; + u32 numStages; + + if(mBlack != 0 || mWhite != -1) + { + test = true; + } + if (mColorAlpha != 0xff || + mCornerColors[0] != -1 || + mCornerColors[1] != -1 || + mCornerColors[2] != -1 || + mCornerColors[3] != -1 || + K2DPicture::mK2DGlobalAlpha != 0xff) + { + test_2 = true; + } + + if(!test_2) { + if(!test){ + GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR_NULL); + GXSetTevColorIn(GX_TEVSTAGE0, GX_CC_TEXC, GX_CC_ZERO, GX_CC_ZERO, GX_CC_ZERO); + + if ((s32)mTextures[0]->getTexInfo()->mTransparency != 0) { + GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_TEXA, GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO); + } else { + s32 white = -1; + GXSetTevColor(GX_TEVREG2, *(GXColor*)(&white)); + GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_A2, GX_CA_ZERO, GX_CA_ZERO, GX_CA_ZERO); + } + + numStages = 1; + } + else { + GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR_NULL); + + GXSetTevColor(GX_TEVREG0, mBlack); + GXSetTevColor(GX_TEVREG1, mWhite); + GXSetTevColorIn(GX_TEVSTAGE0, GX_CC_C0, GX_CC_C1, GX_CC_TEXC, GX_CC_ZERO); + + if ((s32)mTextures[0]->getTexInfo()->mTransparency != 0) { + GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_A0, GX_CA_A1, GX_CA_TEXA, GX_CA_ZERO); + } else { + s32 white = -1; + GXSetTevColor(GX_TEVREG2, *(GXColor*)(&white)); + GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_A0, GX_CA_A1, GX_CA_A2, GX_CA_ZERO); + } + + numStages = 1; + } + } else { + if (!test) + { + GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0); + GXSetTevColorIn(GX_TEVSTAGE0, GX_CC_ZERO, GX_CC_TEXC, GX_CC_RASC, GX_CC_ZERO); + + if ((s32)mTextures[0]->getTexInfo()->mTransparency != 0) { + GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_ZERO, GX_CA_TEXA, GX_CA_RASA, GX_CA_ZERO); + } else { + s32 white = -1; + GXSetTevColor(GX_TEVREG2, *(GXColor*)(&white)); + GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_ZERO, GX_CA_A0, GX_CA_RASA, GX_CA_ZERO); + } + + numStages = 1; + } else { + + GXSetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR_NULL); + + GXSetTevColor(GX_TEVREG0, *(GXColor*)&mBlack); + GXSetTevColor(GX_TEVREG1, *(GXColor*)&mWhite); + GXSetTevColorIn(GX_TEVSTAGE0, GX_CC_C0, GX_CC_C1, GX_CC_TEXC, GX_CC_ZERO); + + if ((s32)mTextures[0]->getTexInfo()->mTransparency != 0) { + GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_A0, GX_CA_A1, GX_CA_TEXA, GX_CA_ZERO); + } else { + s32 white = -1; + GXSetTevColor(GX_TEVREG2, *(GXColor*)(&white)); + GXSetTevAlphaIn(GX_TEVSTAGE0, GX_CA_A0, GX_CA_A1, GX_CA_A2, GX_CA_ZERO); + } + + GXSetTevOrder(GX_TEVSTAGE1, GX_TEXCOORD_NULL, GX_TEXMAP_NULL, GX_COLOR0A0); + GXSetTevColorIn(GX_TEVSTAGE1, GX_CC_ZERO, GX_CC_CPREV, GX_CC_RASC, GX_CC_ZERO); + GXSetTevAlphaIn(GX_TEVSTAGE1, GX_CA_ZERO, GX_CA_APREV, GX_CA_RASA, GX_CA_ZERO); + + numStages = 2; + } + } + + GXSetNumTevStages(numStages); + GXSetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_SET); + GXSetNumChans(1); } void K2DPicture::makeMatrix(f32 x, f32 y) { Mtx _matrix_1; Mtx _matrix_2; Mtx _matrix_3; - - if (_c0 != _g00) { - PSMTXTrans(_matrix_1, -_c4, -_c8, _g00); + if (mAngleZ != sZeroDegreeAngle) { + PSMTXTrans(_matrix_1, -mAnchorPoint.x, -mAnchorPoint.y, sZeroDegreeAngle); f32 degree; - if (mAxis == 'z') { - degree = -_c0; + if (mRotationAxis == J2DROTATE_Z) { + degree = -mAngleZ; } else { - degree = _c0; + degree = mAngleZ; } - PSMTXRotRad(_matrix_2, mAxis, degree * sDegToRad); + PSMTXRotRad(_matrix_2, mRotationAxis, degree * sDegToRad); - PSMTXTrans(_matrix_3, _c4 + x, _c8 + y, _g00); + PSMTXTrans(_matrix_3, mAnchorPoint.x + x, mAnchorPoint.y + y, sZeroDegreeAngle); - PSMTXConcat(_matrix_2, _matrix_1, mMatrix); + PSMTXConcat(_matrix_2, _matrix_1, mPositionMtx); - PSMTXConcat(_matrix_3, mMatrix, mMatrix); + PSMTXConcat(_matrix_3, mPositionMtx, mPositionMtx); } else { - PSMTXTrans(mMatrix, x, y, _g00); + PSMTXTrans(mPositionMtx, x, y, sZeroDegreeAngle); } }