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 6a6005ff..96fe4541 100644 --- a/include/Kameda/K2DPicture.h +++ b/include/Kameda/K2DPicture.h @@ -1,19 +1,20 @@ #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 - 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 }; // class K2DPicture #endif // K2DPICTURE_H diff --git a/src/Kameda/K2DPicture.cpp b/src/Kameda/K2DPicture.cpp index 8f646b55..6e13d22b 100644 --- a/src/Kameda/K2DPicture.cpp +++ b/src/Kameda/K2DPicture.cpp @@ -1,9 +1,187 @@ #include "Kameda/K2DPicture.h" -void K2DPicture::drawK2D(float, float, float, float, bool) {} +#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" -void K2DPicture::getNewColor(JUTColor *) {} +static const f32 sZeroDegreeAngle = 0.f; +static const f32 sDegToRad = 0.017453292f; -void K2DPicture::setTevModeK2D() {} +u8 K2DPicture::mK2DGlobalAlpha = 0xFF; -void K2DPicture::makeMatrix(f32, f32) {} +void K2DPicture::drawK2D(float, float, float, float, bool) { + + if(!mIsVisible) + { + return; + } + JUTColor color; + GXSetNumTexGens(0); + + getNewColor(&color); +} + +void K2DPicture::getNewColor(JUTColor colors[4]) { + 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 * 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) + { + 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() { + 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 (mAngleZ != sZeroDegreeAngle) { + PSMTXTrans(_matrix_1, -mAnchorPoint.x, -mAnchorPoint.y, sZeroDegreeAngle); + + f32 degree; + if (mRotationAxis == J2DROTATE_Z) { + degree = -mAngleZ; + } else { + degree = mAngleZ; + } + + PSMTXRotRad(_matrix_2, mRotationAxis, degree * sDegToRad); + + PSMTXTrans(_matrix_3, mAnchorPoint.x + x, mAnchorPoint.y + y, sZeroDegreeAngle); + + PSMTXConcat(_matrix_2, _matrix_1, mPositionMtx); + + PSMTXConcat(_matrix_3, mPositionMtx, mPositionMtx); + } else { + PSMTXTrans(mPositionMtx, x, y, sZeroDegreeAngle); + } +}