Merge pull request #135 from robojumper/minor-shadow-fixes

m_shadow improvements
This commit is contained in:
robojumper
2025-03-14 11:47:47 +01:00
committed by GitHub
5 changed files with 81 additions and 32 deletions
+4 -4
View File
@@ -1085,7 +1085,7 @@ FUN_8002d810__9dAcBase_cFv = .text:0x8002D810; // type:function size:0x20
FUN_8002d830__9dAcBase_cFv = .text:0x8002D830; // type:function size:0x28
FUN_8002d860__9dAcBase_cFv = .text:0x8002D860; // type:function size:0x20
getSoundSource__9dAcBase_cFv = .text:0x8002D880; // type:function size:0x8
FUN_8002d890__9dAcBase_cFv = .text:0x8002D890; // type:function size:0x88
FUN_8002d890__9dAcBase_cFP9SoundInfo = .text:0x8002D890; // type:function size:0x88
setActorRef__9dAcBase_cFP9dAcBase_c = .text:0x8002D920; // type:function size:0x8
setEnemyDefeatFlag__9dAcBase_cFv = .text:0x8002D930; // type:function size:0x10
changeLoadedEntitiesWithSet__9dAcBase_cFv = .text:0x8002D940; // type:function size:0x14
@@ -17679,7 +17679,7 @@ destroy__Q23m3d9mShadow_cFv = .text:0x802ED2D0; // type:function size:0x60
__dt__Q23m3d14mShadowChild_cFv = .text:0x802ED330; // type:function size:0x9C
create__Q23m3d14mShadowChild_cFUcPQ23EGG4Heap = .text:0x802ED3D0; // type:function size:0x7C
set__Q23m3d14mShadowChild_cFRC7mVec3_cf6mColor = .text:0x802ED450; // type:function size:0x40
addMdl__Q23m3d14mShadowChild_cFRQ23m3d9scnLeaf_cR7mQuat_c = .text:0x802ED490; // type:function size:0x16C
addMdl__Q23m3d14mShadowChild_cFRQ23m3d9scnLeaf_cRC7mQuat_c = .text:0x802ED490; // type:function size:0x16C
setGeom__Q23m3d14mShadowChild_cFPC9_GXTexObjRC6mMtx_cRC7mQuat_c = .text:0x802ED600; // type:function size:0xF8
updateMtx__Q23m3d14mShadowChild_cFv = .text:0x802ED700; // type:function size:0x148
drawMdl__Q23m3d14mShadowChild_cFv = .text:0x802ED850; // type:function size:0x24C
@@ -17688,7 +17688,7 @@ __dt__Q23m3d15mShadowCircle_cFv = .text:0x802EDBB0; // type:function size:0x68
__dt__Q23m3d15mCustomShadow_cFv = .text:0x802EDC20; // type:function size:0x58
getType__Q23m3d15mCustomShadow_cCFv = .text:0x802EDC80; // type:function size:0x8
draw__Q23m3d15mCustomShadow_cFRC6mMtx_c = .text:0x802EDC90; // type:function size:0x17C
calc__Q23m3d15mCustomShadow_cF6mMtx_cR6mMtx_c = .text:0x802EDE10; // type:function size:0x10C
calc__Q23m3d15mCustomShadow_cCF6mMtx_cR6mMtx_c = .text:0x802EDE10; // type:function size:0x10C
__sinit_\m_shadow_cpp = .text:0x802EDF20; // type:function size:0xC scope:local
__ct__Q23m3d6smdl_cFv = .text:0x802EDF30; // type:function size:0x4C
__dt__Q23m3d6smdl_cFv = .text:0x802EDF80; // type:function size:0x58
@@ -17811,7 +17811,7 @@ fadeIn__12mFaderBase_cFv = .text:0x802F0740; // type:function size:0x28
fadeOut__12mFaderBase_cFv = .text:0x802F0770; // type:function size:0x2C
calc__12mFaderBase_cFv = .text:0x802F07A0; // type:function size:0x7C
mFrustum_c__set = .text:0x802F0820; // type:function size:0xB8
mFrustum_c__set2 = .text:0x802F08E0; // type:function size:0x370
set__10mFrustum_cFffffffRC6mMtx_cb = .text:0x802F08E0; // type:function size:0x370
fn_802F0C50 = .text:0x802F0C50; // type:function size:0x160
fn_802F0DB0 = .text:0x802F0DB0; // type:function size:0x8
fn_802F0DC0 = .text:0x802F0DC0; // type:function size:0x13C
+21 -1
View File
@@ -66,6 +66,26 @@ public:
field_0x154 = arg;
}
const mQuat_c &GetQuat() const {
return mQuat;
}
const mVec3_c &GetPostion() const {
return mPositionMaybe;
}
const f32 GetOffset() const {
return mOffsetMaybe;
}
const f32 Get0x13C() const {
return field_0x13C;
}
void Set0x13C(const f32 f) {
field_0x13C = f;
}
const mFrustum_c &GetFrustum() const {
return mFrustum;
}
private:
/* 0x00C */ EGG::Heap *mpHeap;
/* 0x010 */ mShadowCircle_c *mpCircle;
@@ -189,7 +209,7 @@ public:
virtual int getType() const override;
/* 0x24 */ virtual void draw(const mMtx_c &);
void calc(mMtx_c, mMtx_c &);
void calc(mMtx_c, mMtx_c &) const;
/* 0x18 */ mMtx_c mMtx;
/* 0x48 */ f32 field_0x48;
+5
View File
@@ -6,6 +6,7 @@
#include "common.h"
#include "egg/math/eggMatrix.h"
#include "m/m_angle.h"
#include "m/m_quat.h"
#include "m/m_vec.h"
#include "nw4r/types_nw4r.h"
#include "rvl/MTX/mtx.h"
@@ -82,6 +83,10 @@ public:
return *this;
}
void applyQuat(mQuat_c &quat) {
PSMTXMultVec(m, quat.v, quat.v);
}
public:
static mMtx_c Identity;
};
+8
View File
@@ -8,12 +8,20 @@ class mQuat_c : public EGG::Quatf {
public:
mQuat_c() {}
mQuat_c(f32 x, f32 y, f32 z, f32 w) : EGG::Quatf(w, x, y, z) {}
mQuat_c(const mQuat_c &other) : EGG::Quatf(other.w, other.v) {}
mQuat_c &operator=(const EGG::Quatf &rhs) {
v = rhs.v;
w = rhs.w;
return *this;
}
mQuat_c &operator=(const mQuat_c &rhs) {
v = rhs.v;
w = rhs.w;
return *this;
}
bool Set(const mVec3_c &, const mVec3_c &);
void fn_802F2780(const mQuat_c &other);
bool fn_802F2450(const mVec3_c &, const mVec3_c &, f32);
+43 -27
View File
@@ -1,5 +1,9 @@
#include "m/m3d/m_shadow.h"
#include "c/c_math.h"
#include "m/m_mtx.h"
#include "m/m_quat.h"
#include "m/m_vec.h"
#include "nw4r/g3d/g3d_calcview.h"
#include "nw4r/g3d/g3d_draw.h"
#include "nw4r/g3d/g3d_draw1mat1shp.h"
@@ -486,9 +490,8 @@ bool mShadowChild_c::addMdl(scnLeaf_c &mdl, const mQuat_c &quat) {
mtx.copyFrom(static_cast<mCustomShadow_c &>(mdl).mMtx);
}
// TODO this copy is a bit weird (reads members in a different order)
mQuat_c q = quat;
PSMTXMultVec(mtx.m, q.v, q.v);
mtx.applyQuat(q);
if (mNumLeaves == 0) {
mQuat = q;
@@ -511,20 +514,34 @@ bool mShadowChild_c::setGeom(const GXTexObj *texObj, const mMtx_c &mtx, const mQ
}
void mShadowChild_c::updateMtx() {
// TODO all of this is broken
mVec3_c a = *(mVec3_c *)(&mQuat) + mPositionMaybe * mOffsetMaybe;
mVec3_c b = *(mVec3_c *)(&mQuat) - mPositionMaybe * field_0x13C;
const mQuat_c &q = GetQuat();
const mVec3_c &pos = GetPostion();
Set0x13C(q.w);
mVec3_c a(q.v);
a += pos * GetOffset();
mVec3_c b(q.v);
b -= pos * Get0x13C();
const mVec3_c *up;
if (cM::isZero((a - b).squareMagXZ())) {
up = &mVec3_c::Ez;
} else {
up = &mVec3_c::Ey;
}
mMtx_c mtx;
C_MTXLookAt(
mtx.m, b,
*(fabsf((a.x - b.x) * (a.x - b.x) + (a.z - b.z) * (a.z - b.z)) <= FLT_EPSILON ? &mVec3_c::Ez : &mVec3_c::Ey), a
);
f32 f = field_0x13C;
mFrustum.set(f, -f, -f, f, f, f + mOffsetMaybe, mtx, true);
C_MTXLookAt(mtx.m, a, *up, b);
const f32 f = Get0x13C();
mFrustum.set(f, -f, -f, f, f, f + GetOffset(), mtx, true);
}
void mShadowChild_c::drawMdl() {
// TODO maybe roughly equivalent
// Equivalent, but stack problems and regswaps
using namespace nw4r;
mMtx_c mtx;
GXSetTevColor(GX_TEVREG0, sColors[mColorChanIdx]);
@@ -532,33 +549,35 @@ void mShadowChild_c::drawMdl() {
GXSetProjection(mtx.m, GX_ORTHOGRAPHIC);
g3d::G3DState::Invalidate(0x7FF);
mMtx_c &viewMtx = mFrustum.mView;
for (scnLeaf_c **leaf = &mpLeaves[mNumLeaves - 1]; leaf >= &mpLeaves[0]; leaf--) {
scnLeaf_c *lf = *leaf;
if (lf->getType() == 0 /* Model */) {
g3d::ScnMdlSimple *mdl = g3d::G3dObj::DynamicCast<g3d::ScnMdlSimple>(lf->getG3dObject());
if ((*leaf)->getType() == 0 /* Model */) {
g3d::ScnMdlSimple *mdl = g3d::G3dObj::DynamicCast<g3d::ScnMdlSimple>((*leaf)->getG3dObject());
u32 bufSize = mdl->GetNumViewMtx() * sizeof(math::MTX34);
math::MTX34 *viewPosArray = static_cast<math::MTX34 *>(mShadow_c::GetInstance()->mpHeap->alloc(bufSize, 0x20));
math::MTX34 *viewPosArray =
static_cast<math::MTX34 *>(mShadow_c::GetInstance()->mpCurrentHeap->alloc(bufSize, 0x20));
g3d::ResMdl resMdl = mdl->GetResMdl();
g3d::CalcView(
viewPosArray, nullptr, mdl->GetWldMtxArray(), mdl->GetWldMtxAttribArray(), mdl->GetNumViewMtx(),
mFrustum.mView, mdl->GetResMdl(), nullptr
viewMtx, resMdl, nullptr
);
DCStoreRange(viewPosArray, bufSize);
g3d::ScnMdl *mdl2 = g3d::G3dObj::DynamicCast<g3d::ScnMdl>(lf->getG3dObject());
g3d::ScnMdl *mdl2 = g3d::G3dObj::DynamicCast<g3d::ScnMdl>((*leaf)->getG3dObject());
g3d::DrawResMdlReplacement *pRep = mdl2 ? &mdl2->GetDrawResMdlReplacement() : nullptr;
g3d::DrawResMdlDirectly(
mdl->GetResMdl(), viewPosArray, nullptr, nullptr,
mdl2->GetByteCode(g3d::ScnMdlSimple::BYTE_CODE_DRAW_OPA), nullptr, pRep,
g3d::RESMDL_DRAWMODE_FORCE_LIGHTOFF | g3d::RESMDL_DRAWMODE_IGNORE_MATERIAL
resMdl, viewPosArray, nullptr, nullptr, mdl2->GetByteCode(g3d::ScnMdlSimple::BYTE_CODE_DRAW_OPA),
nullptr, pRep, g3d::RESMDL_DRAWMODE_FORCE_LIGHTOFF | g3d::RESMDL_DRAWMODE_IGNORE_MATERIAL
);
GXInvalidateVtxCache();
} else {
// this happens with bomb bag, and goes to 0x802EDC90 (mCustomShadow_c::draw)
static_cast<mCustomShadow_c *>(lf)->draw(mFrustum.mView);
static_cast<mCustomShadow_c *>(*leaf)->draw(viewMtx);
}
}
}
@@ -609,13 +628,10 @@ void mCustomShadow_c::draw(const mMtx_c &arg) {
GXSetTevColorIn(GX_TEVSTAGE0, GX_CC_ZERO, GX_CC_ZERO, GX_CC_ZERO, GX_CC_C0);
}
void mCustomShadow_c::calc(mMtx_c mtx, mMtx_c &mtx2) {
// TODO some shuffles
void mCustomShadow_c::calc(mMtx_c mtx, mMtx_c &mtx2) const {
mVec3_c trans;
mtx2.copyFrom(mMtx);
mVec3_c offset(0.0f, 0.0f, 0.0f);
offset.y = field_0x48;
mVec3_c offset(0.0f, field_0x48, 0.0f);
PSMTXMultVec(mtx2, offset, trans);
PSMTXMultVec(mtx, trans, trans);