Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Projection Libraries #129

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
14 changes: 14 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,17 +100,31 @@ add_library(sead OBJECT
include/gfx/seadDrawContext.h
include/gfx/seadDrawLockContext.h
include/gfx/seadFrameBuffer.h
include/gfx/seadGraphics.h
include/gfx/seadGraphicsContext.h
include/gfx/seadPrimitiveRenderer.h
include/gfx/seadPrimitiveRendererUtil.h
include/gfx/seadProjection.h
include/gfx/seadFrustumProjection.h
include/gfx/seadPerspectiveProjection.h
include/gfx/seadOrthoProjection.h
include/gfx/seadDirectProjection.h
include/gfx/seadTexture.h
include/gfx/seadViewport.h
modules/src/gfx/seadCamera.cpp
modules/src/gfx/seadColor.cpp
modules/src/gfx/seadDrawLockContext.cpp
modules/src/gfx/seadFrameBuffer.cpp
modules/src/gfx/seadGraphics.cpp
modules/src/gfx/seadGraphicsContext.cpp
modules/src/gfx/seadViewport.cpp
# modules/src/gfx/seadPrimitiveRenderer.cpp
# modules/src/gfx/seadPrimitiveRendererUtil.cpp
modules/src/gfx/seadProjection.cpp
modules/src/gfx/seadFrustumProjection.cpp
modules/src/gfx/seadPerspectiveProjection.cpp
modules/src/gfx/seadOrthoProjection.cpp
modules/src/gfx/seadDirectProjection.cpp

include/heap/seadArena.h
include/heap/seadDisposer.h
Expand Down
4 changes: 2 additions & 2 deletions include/gfx/nin/seadGraphicsNvn.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ class GraphicsNvn : public Graphics
bool _201;
bool _202;
};
static_assert(sizeof(GraphicsNvn) == 0x208);
// static_assert(sizeof(GraphicsNvn) == 0x208);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason why this was commented out?


} // namespace sead
} // namespace sead
44 changes: 44 additions & 0 deletions include/gfx/seadDirectProjection.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#pragma once
#include <gfx/seadProjection.h>

namespace sead
{

class DirectProjection : public Projection
{
SEAD_RTTI_OVERRIDE(DirectProjection, Projection)

public:
DirectProjection();
DirectProjection(const Matrix44f* mtx, Graphics::DevicePosture posture);
~DirectProjection() override = default;

void updateAttributesForDirectProjection() override;
Type getProjectionType() const override { return cType_Undefined; }
void doUpdateMatrix(Matrix44f* dst) const override;

void setDirectProjectionMatrix(const Matrix44f* mtx, Graphics::DevicePosture posture);

f32 getNear() const override { return mNear; }
f32 getFar() const override { return mFar; }
f32 getFovy() const override { return mFovy; }

f32 getAspect() const override { return mAspect; }
void getOffset(Vector2f* offset) const override { *offset = mOffset; }

void doScreenPosToCameraPosTo(Vector3f* dst, const Vector3f& screen_pos) const override;

private:
Matrix44f mDirectMatrix = Matrix44f::ident;
f32 mNear = 0.0;
f32 mFar = 0.0;
f32 mFovy = 0.0;
f32 mAspect = 0.0;
Vector2f mOffset = Vector2f::zero;
bool someBool = true;
};
#ifdef cafe
static_assert(sizeof(FrustumProjection) == 0xAC, "sead::FrustumProjection size mismatch");
#endif // cafe

} // namespace sead
57 changes: 57 additions & 0 deletions include/gfx/seadFrustumProjection.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#pragma once
#include <gfx/seadProjection.h>

namespace sead
{

class FrustumProjection : public Projection
{
SEAD_RTTI_OVERRIDE(FrustumProjection, Projection)

public:
FrustumProjection() = default;
FrustumProjection(f32 _near, f32 _far, f32 top, f32 bottom, f32 left, f32 right);
FrustumProjection(f32 _near, f32 _far, const BoundBox2f& box);
~FrustumProjection() override = default;

Type getProjectionType() const override { return Projection::cType_Perspective; }
void doUpdateMatrix(Matrix44f* dst) const override;
void doScreenPosToCameraPosTo(Vector3f* dst, const Vector3f& screen_pos) const override;

void setNear(f32 near);
void setFar(f32 far);
void setTop(f32 top);
void setBottom(f32 bottom);
void setLeft(f32 left);
void setRight(f32 right);

void setTBLR(f32 top, f32 bottom, f32 left, f32 right);

void setBoundBox(const BoundBox2f& box);

void createDividedProjection(FrustumProjection* dst, s32 partno_x, s32 partno_y, s32 divnum_x,
s32 divnum_y) const;

f32 getNear() const override { return mNear; }
f32 getFar() const override { return mFar; }
f32 getTop() const { return mTop; }
f32 getBottom() const { return mBottom; }
f32 getLeft() const { return mLeft; }
f32 getRight() const { return mRight; }

f32 getFovy() const override;
f32 getAspect() const override;
void getOffset(Vector2f* dst) const override;

void setFovyAspectOffset(f32 fovy, f32 aspect, const Vector2f& offset);

private:
f32 mNear;
f32 mFar;
f32 mTop;
f32 mBottom;
f32 mLeft;
f32 mRight;
};

} // namespace sead
Loading