Skip to content

Commit

Permalink
c_m3d done except for regalloc
Browse files Browse the repository at this point in the history
  • Loading branch information
LagoLunatic committed Feb 5, 2025
1 parent 9875a39 commit 7297cba
Show file tree
Hide file tree
Showing 5 changed files with 1,138 additions and 72 deletions.
35 changes: 33 additions & 2 deletions include/SSystem/SComponent/c_m3d.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef C_M3D_H_
#define C_M3D_H_

#include "math.h"
#include "math.h" // IWYU pragma: keep
#include "dolphin/types.h"
#include "dolphin/mtx/vec.h"
#include "dolphin/mtx/mtx.h"
Expand All @@ -20,6 +20,33 @@ struct Vec;

extern const f32 G_CM3D_F_ABS_MIN;

extern const u32 BPCP_OUTCODE0;
extern const u32 BPCP_OUTCODE1;
extern const u32 BPCP_OUTCODE4;
extern const u32 BPCP_OUTCODE5;
extern const u32 BPCP_OUTCODE2;
extern const u32 BPCP_OUTCODE3;
extern const u32 BEVEL2D_OUTCODE0;
extern const u32 BEVEL2D_OUTCODE1;
extern const u32 BEVEL2D_OUTCODE2;
extern const u32 BEVEL2D_OUTCODE3;
extern const u32 BEVEL2D_OUTCODE4;
extern const u32 BEVEL2D_OUTCODE5;
extern const u32 BEVEL2D_OUTCODE6;
extern const u32 BEVEL2D_OUTCODE7;
extern const u32 BEVEL2D_OUTCODE8;
extern const u32 BEVEL2D_OUTCODE9;
extern const u32 BEVEL2D_OUTCODE10;
extern const u32 BEVEL2D_OUTCODE11;
extern const u32 BEVEL3D_OUTCODE0;
extern const u32 BEVEL3D_OUTCODE1;
extern const u32 BEVEL3D_OUTCODE2;
extern const u32 BEVEL3D_OUTCODE3;
extern const u32 BEVEL3D_OUTCODE4;
extern const u32 BEVEL3D_OUTCODE5;
extern const u32 BEVEL3D_OUTCODE6;
extern const u32 BEVEL3D_OUTCODE7;

struct cM3d_Range {
f32 start;
f32 end;
Expand Down Expand Up @@ -90,7 +117,7 @@ f32 cM3d_lineVsPosSuisenCross(const cM3dGLin*, const Vec*, Vec*);
f32 cM3d_lineVsPosSuisenCross(const Vec&, const Vec&, const Vec&, Vec*);
int cM3d_2PlaneLinePosNearPos(const cM3dGPla&, const cM3dGPla&, const Vec*, Vec*);
void cM3d_CrawVec(const Vec&, const Vec&, Vec*);
void cM3d_UpMtx_Base(const Vec&, const Vec&, MtxP);
int cM3d_UpMtx_Base(const Vec&, const Vec&, MtxP);

inline bool cM3d_IsZero(f32 f) {
return std::fabsf(f) < G_CM3D_F_ABS_MIN;
Expand Down Expand Up @@ -121,4 +148,8 @@ inline bool cM3d_CrossInfLineVsInfPlane_proc(f32 a, f32 b, const Vec* pA, const
}
}

inline f32 cM3d_LenSq(const Vec* a, const Vec* b) {
return VECSquareDistance(a, b);
}

#endif
11 changes: 8 additions & 3 deletions include/SSystem/SComponent/c_m3d_g_lin.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class cM3dGLin {

public:
cM3dGLin() {}
cM3dGLin(const cXyz&, const cXyz&);
cM3dGLin(const cXyz& start, const cXyz& end) : mStart(start), mEnd(end) {}
virtual ~cM3dGLin() {}
void SetStartEnd(const cXyz& start, const cXyz& end) {
mStart = start;
Expand All @@ -27,7 +27,12 @@ class cM3dGLin {
mStart = start;
mEnd = end;
}
void CalcPos(Vec*, f32) const { /* TODO */ }
void CalcPos(Vec* out, f32 scale) const {
Vec tmp;
VECSubtract(&mEnd, &mStart, &tmp);
VECScale(&tmp, &tmp, scale);
VECAdd(&tmp, &mStart, out);
}
void CalcVec(Vec* pOut) const { VECSubtract(&this->mEnd, &this->mStart, pOut); }
void SetEnd(const cXyz& pos) { mEnd = pos; }
const cXyz* GetStartP() const { return &mStart; }
Expand All @@ -43,4 +48,4 @@ class cM3dGLin {

STATIC_ASSERT(0x1C == sizeof(cM3dGLin));

#endif /* C_M3D_G_LIN_H */
#endif /* C_M3D_G_LIN_H */
4 changes: 3 additions & 1 deletion include/SSystem/SComponent/c_m3d_g_pla.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,14 @@ class cM3dGPla {
void SetupFrom3Vtx(const Vec* a, const Vec* b, const Vec* c) {
cM3d_CalcPla(a, b, c, &mNormal, &mD);
}
bool cross(const cM3dGLin& line, Vec& point) const {
return cM3d_Cross_LinPla(&line, this, &point, true, true);
}

virtual ~cM3dGPla() {}

// TODO
cM3dGPla(const cXyz*, f32) {}
void cross(const cM3dGLin&, Vec&) const {}
}; // Size: 0x14

#endif
4 changes: 1 addition & 3 deletions include/dolphin/mtx/mtx.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,7 @@ void C_MTXLightPerspective(Mtx m, f32 fovY, f32 aspect, f32 scale_s, f32 scale_t
void C_MTXLightOrtho(Mtx m, f32 top, f32 bottom, f32 left, f32 right, f32 scale_s, f32 scale_t,
f32 trans_s, f32 trans_t);

inline void C_MTXRotAxisRad(Mtx m, const Vec* axis, f32 rad) {
PSMTXRotAxisRad(m, axis, rad);
}
void C_MTXRotAxisRad(Mtx m, const Vec* axis, f32 rad);

#define MTXDegToRad(deg) ((deg) * 0.01745329252f)
#define MTXRadToDeg(rad) ((rad) * 57.29577951f)
Expand Down
Loading

0 comments on commit 7297cba

Please sign in to comment.