From 4890acfe80ce5d1b723febfbb0d2a7a1395cc809 Mon Sep 17 00:00:00 2001 From: robojumper Date: Fri, 21 Mar 2025 00:46:41 +0100 Subject: Some frustum/screen --- include/egg/gfx/eggFrustum.h | 142 ++++++++++++++++++++++++++++++----------- include/egg/gfx/eggGXUtility.h | 1 + include/egg/gfx/eggGfxEngine.h | 8 +-- include/egg/gfx/eggScreen.h | 84 +++++++++++++++--------- include/egg/gfx/eggStateGX.h | 10 +-- 5 files changed, 169 insertions(+), 76 deletions(-) (limited to 'include/egg') diff --git a/include/egg/gfx/eggFrustum.h b/include/egg/gfx/eggFrustum.h index f3dd56d3..5adbc40e 100644 --- a/include/egg/gfx/eggFrustum.h +++ b/include/egg/gfx/eggFrustum.h @@ -1,52 +1,54 @@ #ifndef EGG_FRUSTUM_H #define EGG_FRUSTUM_H -#include "common.h" #include "nw4r/g3d/g3d_camera.h" namespace EGG { - -// TODO: Fill out more class Frustum { public: - enum CanvasMode { - CANVAS_0, - CANVAS_1, + enum Flag { + FLAG_DIRTY = (1 << 0), + FLAG_0x40 = (1 << 6), }; + enum ProjectionType { PROJ_ORTHO, PROJ_PERSP }; - enum Flag { - FLAG_DIRTY = (1 << 0), - FLAG_0x40 = 0x40, + enum CanvasMode { + CANVASMODE_0, + CANVASMODE_1, }; -private: - /* 0x00 */ ProjectionType mProjType; - /* 0x04 */ CanvasMode mCanvasMode; - /* 0x08 */ nw4r::math::VEC2 mSize; - /* 0x10 */ f32 mFovY; - /* 0x14 */ f32 mTanFovY; - /* 0x18 */ f32 mNearZ; - /* 0x1C */ f32 mFarZ; - /* 0x20 */ nw4r::math::VEC2 mOffset; - /* 0x28 */ nw4r::math::VEC3 mScale; - /* 0x34 */ mutable u16 mFlags; +protected: + ProjectionType mProjType; // at 0x0 + CanvasMode mCanvasMode; // at 0x4 + nw4r::math::VEC2 mSize; // at 0x8 + f32 mFovY; // at 0x10 + f32 mTanFovY; // at 0x14 + f32 mNearZ; // at 0x18 + f32 mFarZ; // at 0x1C + nw4r::math::VEC2 mOffset; // at 0x20 + nw4r::math::VEC3 mScale; // at 0x28 + mutable u16 mFlags; // at 0x34 public: - // vt at 0x38 - virtual ~Frustum() {} - virtual void SetProjectionGX() const; - virtual void CopyToG3D(nw4r::g3d::Camera) const; + Frustum(ProjectionType, const nw4r::math::VEC2 &, f32, f32, CanvasMode); + Frustum(const Frustum &); - ProjectionType GetProjectionType() const { - return mProjType; - } - void SetProjectionType(ProjectionType type) { - mProjType = type; - } + virtual ~Frustum() {} // at 0x8 + virtual void SetProjectionGX() const; // at 0xC + virtual void CopyToG3D(nw4r::g3d::Camera) const; // at 0x10 + void ResetOrthographic(f32, f32, f32, f32, f32, f32); + void CopyFromAnother(const Frustum &); + void SetFovy(f32); + void ConvertToCanvasLU(f32, f32, f32 *, f32 *) const; + + static void SetGlobalScaleOffset(f32, f32, f32, f32); + static void GetGlobalScaleOffset(f32 *, f32 *, f32 *, f32 *); + + f32 GetScreenSizeToViewSize(f32, f32) const; void SetDirty(bool dirty) const { if (dirty) { @@ -56,27 +58,75 @@ public: } } - void SetFlag(Flag f) const { - mFlags |= f; + ProjectionType GetProjectionType() const { + return mProjType; + } + void SetProjectionType(ProjectionType type) { + mProjType = type; } CanvasMode GetCanvasMode() const { return mCanvasMode; } void SetCanvasMode(CanvasMode mode) { - if (mCanvasMode != mode) { + if (mode != mCanvasMode) { SetDirty(true); mCanvasMode = mode; } } + const nw4r::math::VEC2 &GetSize() const { + return mSize; + } + + u16 GetWidth() const { + return mSize.x; + } + f32 GetSizeX() const { + return mSize.x; + } + void SetSizeX(f32 sizeX) { + SetDirty(true); + mSize.x = sizeX; + } + + u16 GetHeight() const { + return mSize.y; + } + f32 GetSizeY() const { + return mSize.y; + } + void SetSizeY(f32 sizeY) { + SetDirty(true); + mSize.y = sizeY; + } + + void SetSize(const nw4r::math::VEC2 &size) { + // ??? + mSize.x = size.x; + SetDirty(true); + mSize.y = size.y; + } + + void SetNearZ(f32 nearZ) { + mNearZ = nearZ; + } + f32 GetNearZ() const { + return mNearZ; + } + + void SetFarZ(f32 farZ) { + mFarZ = farZ; + } + f32 GetFarZ() const { + return mFarZ; + } + void SetNearFar(f32 near, f32 far) { mNearZ = near; mFarZ = far; } - void ResetOrthographic(f32, f32, f32, f32, f32, f32); - void SetScale(const nw4r::math::VEC3 &scale) { mScale = scale; } @@ -84,11 +134,27 @@ public: mOffset = offset; } - const nw4r::math::VEC2 &GetSize() { - return mSize; + void SetFlag(u32 flag) { + mFlags |= flag; } -}; +private: + void SetProjectionPerspectiveGX_() const; + void SetProjectionOrthographicGX_() const; + + void CopyToG3D_Perspective_(nw4r::g3d::Camera) const; + void CopyToG3D_Orthographic_(nw4r::g3d::Camera) const; + + void CalcMtxPerspective_(nw4r::math::MTX44 *) const; + + void GetOrthographicParam_(f32 *) const; + void GetPerspectiveParam_(f32 *) const; + void GetOrthographicParam_(f32 *, f32 *, f32 *, f32 *) const; + +private: + static nw4r::math::VEC2 sGlobalScale; + static nw4r::math::VEC2 sGlobalOffset; +}; } // namespace EGG #endif diff --git a/include/egg/gfx/eggGXUtility.h b/include/egg/gfx/eggGXUtility.h index d3ac74b7..cba929e6 100644 --- a/include/egg/gfx/eggGXUtility.h +++ b/include/egg/gfx/eggGXUtility.h @@ -16,6 +16,7 @@ public: static void getTexObj(GXTexObj *, nw4r::g3d::ResTex, GXTexWrapMode, GXTexWrapMode, GXTexFilter, GXTexFilter); static void getNormalColor(GXColor &outColor, const Vector3f &vec); + static void setScaleOffsetPerspective(f32*, f32, f32, f32, f32); }; } // namespace EGG diff --git a/include/egg/gfx/eggGfxEngine.h b/include/egg/gfx/eggGfxEngine.h index 56e8d67b..20b6729b 100644 --- a/include/egg/gfx/eggGfxEngine.h +++ b/include/egg/gfx/eggGfxEngine.h @@ -2,12 +2,12 @@ #define EGG_GFXENGINE_H #include "common.h" -#include "rvl/GX.h" +#include "rvl/GX/GXTypes.h" namespace EGG { -namespace GfxEngine { - +class GfxEngine { +public: struct Configuration { /* 0x00 */ u16 efbWidth; /* 0x02 */ u16 efbHeight; @@ -23,7 +23,7 @@ struct Configuration { virtual ~Configuration() {} }; -} // namespace GfxEngine +}; } // namespace EGG diff --git a/include/egg/gfx/eggScreen.h b/include/egg/gfx/eggScreen.h index 699df321..df63bf81 100644 --- a/include/egg/gfx/eggScreen.h +++ b/include/egg/gfx/eggScreen.h @@ -1,41 +1,20 @@ #ifndef EGG_SCREEN_H #define EGG_SCREEN_H -#include "common.h" +#include "egg/egg_types.h" #include "egg/gfx/eggFrustum.h" namespace EGG { -// TODO: Fill out more class Screen : public Frustum { public: - Screen(); - Screen(const Screen &other); - Screen(f32, f32, f32, f32, Screen *, CanvasMode); - - virtual ~Screen() {} - virtual void SetProjectionGX() const override; - virtual void CopyToG3D(nw4r::g3d::Camera) const override; + enum TVMode { TV_MODE_4_3, TV_MODE_16_9, TV_MODE_UNK_3, TV_MODE_MAX }; - static void Initialize(const u16 *, const u16 *, Screen *); - static void SetTVModeDefault(); - - u8 TODO_0x3C[0x88 - 0x3C]; - - enum TVMode { - TV_MODE_1, - TV_MODE_2, - TV_MODE_3, - TV_MODE_4, - TV_MODE_MAX - }; + typedef void (*ChangeTVModeFunc)(void *); - struct TVModeInfo { - TVModeInfo() {} - u16 width; - u16 height; - f32 w_ratio; - f32 h_ratio; + struct UnkStruct { + UNKWORD field_0x00; + UNKWORD field_0x04; }; struct DataEfb { @@ -49,10 +28,26 @@ public: f32 z2; // at 0x14 } vp; - s32 sc_ox; // at 0x18 - s32 sc_oy; // at 0x1C + u32 sc_x; + u32 sc_y; + u32 sc_w; + u32 sc_h; + + s32 sc_ox; // at 0x28 + s32 sc_oy; // at 0x2C }; + struct TVModeInfo { + u16 width; + u16 height; + nw4r::math::VEC2 ratios; + }; + +public: + static void Initialize(const u16 *, const u16 *, Screen *); + static void SetTVMode(TVMode); + static void SetTVModeDefault(); + static u16 GetSizeXMax(TVMode mode) { return sTVModeInfo[mode].width; } @@ -74,11 +69,40 @@ public: return sTVMode; } + Screen(); + Screen(f32, f32, f32, f32, const Screen *, CanvasMode); + Screen(const Screen &); + + virtual ~Screen() {} // at 0x8 + virtual void SetProjectionGX() const; // at 0xC + virtual void CopyToG3D(nw4r::g3d::Camera) const; // at 0x10 + + const Screen *GetParent() const { + return mParent; + } + void SetParent(const Screen *parent); + void SetUnkFlag8(); + + void CopyFromAnother(const Screen &other); + void Reset(f32, f32, f32, f32, CanvasMode); + void GetPosSizeInEfb() const; + const DataEfb &GetDataEfb() const; + bool IsChangeEfb() const; + void CalcMatrixForDrawQuad(nw4r::math::MTX34 *, f32, f32, f32, f32) const; + void FillBufferGX(u32, GXColor, u32) const; + void GetGlobalPos(f32 *, f32 *) const; + +private: + const Screen *mParent; // at 0x3C + nw4r::math::VEC2 mPosition; // at 0x40 + nw4r::math::VEC2 field_0x44; + nw4r::math::VEC2 field_0x48; + mutable DataEfb mDataEfb; // at 0x58 + static TVMode sTVMode; static Screen *spRoot; - typedef void (*ChangeTVModeFunc)(void *); static ChangeTVModeFunc sChangeTVModeFunc; static void *spChangeTVModeFuncInfo; static TVModeInfo sTVModeInfo[Screen::TV_MODE_MAX]; diff --git a/include/egg/gfx/eggStateGX.h b/include/egg/gfx/eggStateGX.h index e575dcc8..bcc4e9f8 100644 --- a/include/egg/gfx/eggStateGX.h +++ b/include/egg/gfx/eggStateGX.h @@ -88,14 +88,16 @@ public: static bool GXSetDstAlpha(); // Unk func here static void GXSetProjection(Mtx44, int); - static void GXSetProjectionv(const f32 *); - static void GXSetViewport(f32, f32, f32, f32, f32, f32); - static void GZSetScissor(u32, u32, u32, u32); - static void GZSetScissorBoxOffset(s32, s32); + static void GXSetProjectionv_(const f32 *); + static void GXSetViewport_(f32, f32, f32, f32, f32, f32); + static void GXSetScissor_(u32, u32, u32, u32); + static void GXSetScissorBoxOffset_(s32, s32); static u16 s_commandFlag; static u16 s_flag; + static u16 s_widthEfb; + static u16 s_heightEfb; static GXColor sDefaultTexColor; }; -- cgit v1.2.3