Skip to content

Commit

Permalink
Merge pull request #83 from encounter/j3dmtxcalc
Browse files Browse the repository at this point in the history
Progress on J3DMatBlock, m_Do_ext, J3DUMotion
  • Loading branch information
magcius authored Sep 27, 2023
2 parents 519b977 + 9a6a915 commit e2ddfa7
Show file tree
Hide file tree
Showing 15 changed files with 854 additions and 2,090 deletions.
2 changes: 1 addition & 1 deletion configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def DolphinLib(lib_name, objects):
Object(NonMatching, "m_Do/m_Do_graphic.cpp"),
Object(Matching, "m_Do/m_Do_machine.cpp"),
Object(NonMatching, "m_Do/m_Do_mtx.cpp"),
Object(NonMatching, "m_Do/m_Do_ext.cpp"),
Object(NonMatching, "m_Do/m_Do_ext.cpp", cflags=[*cflags_framework, "-sym off"]),
Object(NonMatching, "m_Do/m_Do_lib.cpp"),
Object(Matching, "m_Do/m_Do_hostIO.cpp"),
Object(Matching, "m_Do/m_Do_Reset.cpp"),
Expand Down
130 changes: 87 additions & 43 deletions include/JSystem/J3DGraphAnimator/J3DJoint.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#ifndef J3DJOINT_H
#define J3DJOINT_H

#include "JSystem/J3DGraphBase/J3DTransform.h"
#include "JSystem/J3DGraphAnimator/J3DNode.h"
#include "JSystem/J3DGraphBase/J3DSys.h"
#include "JSystem/J3DGraphBase/J3DTransform.h"

class J3DAnmTransform;
class J3DJoint;
Expand All @@ -11,42 +12,105 @@ class J3DMtxBuffer;

class J3DMtxCalc {
public:
static void setMtxBuffer(J3DMtxBuffer*);
virtual void init(const Vec&, const Mtx&) {}
virtual void recursiveCalc(J3DNode*) {}
virtual void calcTransform(u16, const J3DTransformInfo&) {}
virtual void calc(u16) {}

void initAnm() {
for (int i = 0; i < 4; i++) {
mOne[i] = 0;
mTwo[i] = 0.0f;
}
}
void setAnmTransform(J3DAnmTransform* mAnmTransform);

public:
u32 mOne[4];
f32 mTwo[4];
};

class J3DMtxCalcAnm : public virtual J3DMtxCalc {
public:
J3DMtxCalcAnm(J3DAnmTransform* mAnmTransform) : J3DMtxCalc() { setAnmTransform(mAnmTransform); }
virtual ~J3DMtxCalcAnm() { initAnm(); }
virtual void calc(u16);
};

virtual ~J3DMtxCalc();
virtual void init(Vec const& param_0, const Mtx&) = 0;
virtual void recursiveCalc(J3DNode *);
virtual void calc() = 0;
virtual void calcTransform(u16, J3DTransformInfo const &) = 0;
class J3DMtxCalcBasic : public virtual J3DMtxCalc {
private:
Mtx mBackupMtx;
Vec mBackupS;
Vec mBackupParentS;

static J3DMtxBuffer* getMtxBuffer() { return mMtxBuffer; }
static J3DJoint* getJoint() { return mJoint; }
static void setJoint(J3DJoint* joint) { mJoint = joint; }
public:
J3DMtxCalcBasic();
virtual ~J3DMtxCalcBasic() {}
virtual void init(const Vec& vec, const Mtx& mtx);
virtual void recursiveCalc(J3DNode*);
virtual void calcTransform(u16, const J3DTransformInfo&);
virtual void calc(u16);

Mtx& getBackupMtx() { return mBackupMtx; }
Vec& getBackupS() { return mBackupS; }
Vec& getBackupParentS() { return mBackupParentS; }

void setBackupS(const Vec& vec) { mBackupS = vec; }
void setBackupParentS(const Vec& vec) { mBackupParentS = vec; }
};

static J3DMtxBuffer* mMtxBuffer;
static J3DJoint* mJoint;
}; // Size: 0x4
class J3DMtxCalcSoftimage : public J3DMtxCalcBasic {
public:
J3DMtxCalcSoftimage() : J3DMtxCalc() {}
virtual ~J3DMtxCalcSoftimage();
virtual void init(const Vec& vec, const Mtx& mtx);
virtual void calcTransform(u16, const J3DTransformInfo&);
};

class J3DMtxCalcNoAnmBase : public J3DMtxCalc {
class J3DMtxCalcMaya : public J3DMtxCalcBasic {
public:
virtual ~J3DMtxCalcNoAnmBase();
J3DMtxCalcMaya() : J3DMtxCalcBasic() {}
virtual ~J3DMtxCalcMaya() {}
virtual void init(const Vec& vec, const Mtx& mtx) {
// TODO: This breaks some TUs by adding extra data ({0x3F800000, 0x3F800000, 0x3F800000})
// J3DSys::mParentS = (Vec){1.0f, 1.0f, 1.0f};
J3DSys::mCurrentS = vec;
J3DSys::mCurrentMtx[0][0] = mtx[0][0] * J3DSys::mCurrentS.x;
J3DSys::mCurrentMtx[0][1] = mtx[0][1] * J3DSys::mCurrentS.y;
J3DSys::mCurrentMtx[0][2] = mtx[0][2] * J3DSys::mCurrentS.z;
J3DSys::mCurrentMtx[0][3] = mtx[0][3];
J3DSys::mCurrentMtx[1][0] = mtx[1][0] * J3DSys::mCurrentS.x;
J3DSys::mCurrentMtx[1][1] = mtx[1][1] * J3DSys::mCurrentS.y;
J3DSys::mCurrentMtx[1][2] = mtx[1][2] * J3DSys::mCurrentS.z;
J3DSys::mCurrentMtx[1][3] = mtx[1][3];
J3DSys::mCurrentMtx[2][0] = mtx[2][0] * J3DSys::mCurrentS.x;
J3DSys::mCurrentMtx[2][1] = mtx[2][1] * J3DSys::mCurrentS.y;
J3DSys::mCurrentMtx[2][2] = mtx[2][2] * J3DSys::mCurrentS.z;
J3DSys::mCurrentMtx[2][3] = mtx[2][3];
}
virtual void calcTransform(u16, const J3DTransformInfo&);
};

template <class A, class B>
class J3DMtxCalcNoAnm : public J3DMtxCalcNoAnmBase, public A, public B {
class J3DMtxCalcMayaAnm : public J3DMtxCalcMaya, public J3DMtxCalcAnm {
public:
J3DMtxCalcNoAnm() {}
virtual ~J3DMtxCalcNoAnm() {}
virtual void init(Vec const& param_0, f32 const (&param_1)[3][4]);
virtual void calc();
J3DMtxCalcMayaAnm(J3DAnmTransform* pAnmTransform)
: J3DMtxCalcMaya(), J3DMtxCalcAnm(pAnmTransform) {}
virtual ~J3DMtxCalcMayaAnm() {}
virtual void calc(u16 v) { J3DMtxCalcAnm::calc(v); }
};

class J3DJoint : public J3DNode {
public:
J3DJoint();
void initialize();
void addMesh(J3DMaterial*);
void calcIn();
void calcOut();
void entryIn();
u32 getType() const { return 'NJNT'; }
void recursiveCalc();
void addMesh(J3DMaterial*);

J3DJoint();
~J3DJoint() {}

J3DMaterial* getMesh() { return mMesh; }
u16 getJntNo() const { return mJntNo; }
Expand Down Expand Up @@ -79,24 +143,4 @@ class J3DJoint : public J3DNode {
/* 0x60 */ J3DMaterial* mMesh;
}; // Size: 0x54

struct J3DMtxCalcJ3DSysInitMaya {
static void init(Vec const&, f32 const (&)[3][4]);
};

struct J3DMtxCalcJ3DSysInitBasic {
static void init(Vec const&, f32 const (&)[3][4]);
};

struct J3DMtxCalcCalcTransformSoftimage {
static void calcTransform(J3DTransformInfo const&);
};

struct J3DMtxCalcCalcTransformMaya {
static void calcTransform(J3DTransformInfo const&);
};

struct J3DMtxCalcCalcTransformBasic {
static void calcTransform(J3DTransformInfo const&);
};

#endif /* J3DJOINT_H */
7 changes: 4 additions & 3 deletions include/JSystem/J3DGraphAnimator/J3DNode.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
#include "dolphin/mtx/mtx.h"

class J3DNode;
class J3DModelData;
typedef int (*J3DNodeCallBack)(J3DNode*, int);

class J3DNode {
public:
virtual void init(Vec const& param_0, Mtx*);
virtual void init(J3DModelData*) {}
virtual void entryIn();
virtual void calcIn();
virtual void calcOut();
virtual void calcIn() {}
virtual void calcOut() {}
virtual u32 getType() const;
virtual ~J3DNode();

Expand Down
20 changes: 16 additions & 4 deletions include/JSystem/J3DGraphBase/J3DGD.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ inline void J3DGDWrite_u8(u8 param) {
}

inline void J3DGDWrite_u16(u16 param) {
__GDWrite((param & 0xffff) >> 8);
__GDWrite((param >> 8) & 0xff);
__GDWrite(param & 0xff);
}

Expand All @@ -20,15 +20,27 @@ inline void J3DGDWrite_u32(u32 param) {
__GDWrite(param & 0xff);
}

inline void J3DGDWriteXFCmd(u16 param_1, u32 param_2) {
inline void J3DGDWrite_f32(f32 param) {
u32 tmp = *(u32*)&param;
J3DGDWrite_u32(tmp);
}

inline void J3DGDWriteXFCmd(u16 cmd, u32 param) {
J3DGDWrite_u8(0x10);
J3DGDWrite_u16(0);
J3DGDWrite_u16(param_1);
J3DGDWrite_u32(param_2);
J3DGDWrite_u16(cmd);
J3DGDWrite_u32(param);
}

inline void J3DGDWriteXFCmdHdr(u16 cmd, u8 len) {
J3DGDWrite_u8(0x10);
J3DGDWrite_u16(len - 1);
J3DGDWrite_u16(cmd);
}

void J3DGDSetGenMode(u8 texGenNum, u8 colorChanNum, u8 tevStageNum, u8 IndTexStageNum, _GXCullMode cullMode);
void J3DGDSetGenMode_3Param(u8 texGenNum, u8 tevStageNum, u8 indTexStageNum);
void J3DGDSetTexCoordGen(GXTexGenType, GXTexGenSrc);

static inline void J3DFifoLoadIndx(u8 cmd, u16 indx, u16 addr) {
GFX_FIFO(u8) = cmd;
Expand Down
Loading

0 comments on commit e2ddfa7

Please sign in to comment.