Some frustum/screen

This commit is contained in:
robojumper
2025-03-21 00:46:41 +01:00
parent 70123b2777
commit 4890acfe80
12 changed files with 773 additions and 96 deletions
+104 -38
View File
@@ -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
+1
View File
@@ -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
+4 -4
View File
@@ -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
+54 -30
View File
@@ -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);
enum TVMode { TV_MODE_4_3, TV_MODE_16_9, TV_MODE_UNK_3, TV_MODE_MAX };
virtual ~Screen() {}
virtual void SetProjectionGX() const override;
virtual void CopyToG3D(nw4r::g3d::Camera) const override;
typedef void (*ChangeTVModeFunc)(void *);
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
};
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];
+6 -4
View File
@@ -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;
};