Skip to content

Commit cb7ac35

Browse files
committed
cleanup
1 parent 319f5aa commit cb7ac35

File tree

3 files changed

+44
-52
lines changed

3 files changed

+44
-52
lines changed

include/JSystem/JGeometry/Matrix.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,18 +86,12 @@ namespace JGeometry {
8686
TRotation3() {}
8787
void identity33();
8888

89-
// TODO: getYDir doesn't match in StringObj with the same method as getXDir and getZDir
90-
// however there is a chance Sato is a troll and didn't use the inline
91-
// actually, Sato is a troll regardless
9289
inline void getXDir(TVec3f &rDest) const {
9390
rDest.set(this->at(0, 0), this->at(1, 0), this->at(2, 0));
9491
}
9592

9693
inline void getYDir(TVec3f &rDest) const {
97-
f32 z = this->mMtx[2][1];
98-
f32 y = this->mMtx[1][1];
99-
f32 x = this->mMtx[0][1];
100-
rDest.set(x, y, z);
94+
rDest.set(this->at(0,1), this->at(1, 1), this->at(2, 1));
10195
}
10296

10397
inline void getZDir(TVec3f &rDest) const {
@@ -209,10 +203,12 @@ namespace JGeometry {
209203
{
210204
public:
211205
TPosition3() {}
206+
207+
212208
void getTrans(TVec3f &rDest) const {
213209
rDest.set(this->at(0, 3), this->at(1, 3), this->at(2, 3));
214210
}
215-
211+
216212
void setTrans(const TVec3f &rSrc);
217213
void setTrans(f32 x, f32 y, f32 z);
218214
void zeroTrans()

src/Sato/StringObj.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ void StringObj::calc() {
319319
ExModel *exModel = mExModel;
320320
JSUListIterator<StringNode> it(mStringNodeMgr->mStrNodeList.getFirst());
321321

322-
JGeometry::TRot3f m;
322+
JGeometry::TRot3f m; // making this a matrix causes instruction swaps
323323
PSMTXCopy(_14, m);
324324

325325
f32 scale = 0.0001f;
@@ -334,8 +334,7 @@ void StringObj::calc() {
334334
for (u32 i = 0; i < mStringNodeMgr->mStrNodeList.getNumLinks() - 1; i++) {
335335
if (i < mStringNodeMgr->mStrNodeList.getNumLinks() - 1) {
336336
JGeometry::TVec3f cp, ang, vel, pos, pos2;
337-
338-
m.getYDir(ang);
337+
ang.set(m[0][1], m[1][1], m[2][1]);
339338

340339
mStringNodeMgr->getNodePos(i, &pos);
341340
mStringNodeMgr->getNodePos(i + 1, &pos2);

src/Shiraiwa/MapObjWanwan.cpp

Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -304,33 +304,36 @@ void TMapObjWanwan::doFunc_Jumped() {
304304
mPos.add(mVel);
305305
}
306306

307-
void TMapObjWanwan::setRotate(f32 rotate)
308-
{
307+
void TMapObjWanwan::setRotate(f32 rotate) {
309308
mRotate = rotate;
309+
310+
// might be mRotMtx.setEulerXYZ?
310311
const f32 x = 0;
311312
const f32 y = mRotate;
312313
const f32 z = _230;
314+
f32 cr = cos(x); // f26
315+
f32 cp = cos(y); // f31
316+
f32 cy = cos(z); // f30
317+
f32 sr = sin(x); // f29
318+
f32 sp = sin(y); // f28
319+
f32 sy = sin(z); // f7
320+
321+
// ???
322+
f32 tmp = sy * sp;
323+
f32 cpy = (cy * cp);
324+
f32 spy = sp * sy;
325+
326+
mRotMtx[0][0] = ((tmp) * sr + (cp * cr));
327+
mRotMtx[1][0] = (sr * cy);
328+
mRotMtx[2][0] = -(sp * cr) + (sy * cp * sr);
313329

314-
f32 dVar2 = cos(x); // f26
315-
f32 dVar6 = cos(y); // f31
316-
f32 dVar5 = cos(z); // f30
317-
f32 dVar4 = sin(x); // f29
318-
f32 dVar3 = sin(y); // f28
319-
f32 dVar1 = sin(z); // f7
320-
321-
f32 cxy = dVar6 * dVar2;
322-
323-
mRotMtx[0][0] = (dVar1 * dVar3) * dVar4 + cxy;
324-
mRotMtx[1][0] = (dVar4 * dVar5);
325-
mRotMtx[2][0] = -(dVar3 * dVar2) + ((dVar1 * dVar6) * dVar4);
326-
327-
mRotMtx[0][1] = ((-dVar4 * dVar6) + dVar2 * (dVar1 * dVar3));
328-
mRotMtx[1][1] = (dVar5 * dVar2);
329-
mRotMtx[2][1] = (dVar3 * dVar4 + dVar1 * (cxy));
330+
mRotMtx[0][1] = ((-sr * cp) + (spy) * cr);
331+
mRotMtx[1][1] = (cy * cr);
332+
mRotMtx[2][1] = (sp * sr + sy * (cp * cr));
330333

331-
mRotMtx[0][2] = (dVar5 * dVar3);
332-
mRotMtx[1][2] = (-dVar1);
333-
mRotMtx[2][2] = (dVar5 * dVar6);
334+
mRotMtx[0][2] = (cy * sp);
335+
mRotMtx[1][2] = (-sy);
336+
mRotMtx[2][2] = (cpy);
334337
}
335338

336339
void TMapObjWanwan::doFunc_Attack() {
@@ -433,7 +436,6 @@ void TMapObjWanwan::fallDown(s32 nextState, bool p2) {
433436
mVel.y = _218;
434437
}
435438
}
436-
437439
createEmitterOnGround(&mpEmitter, "mk_wanSmoke_a");
438440
}
439441

@@ -506,9 +508,10 @@ f32 TMapObjWanwan::getAngleToRand() {
506508
getWanwanBackPos(&backPos);
507509
backPos.sub(mObjData->position);
508510

509-
const f32 l = posDiff.x * mRotMtx[0][2] + posDiff.z * mRotMtx[2][2];
510-
511-
if ((l < 0.0f)
511+
JGeometry::TVec3f zDir;
512+
mRotMtx.getZDir(zDir);
513+
514+
if ((zDir.dotZX(posDiff) < 0.0f)
512515
&& (backPos.length() > mChainLength * 0.8f))
513516
{
514517
f32 a = std::atan2f(posDiff.x, posDiff.z);
@@ -532,7 +535,6 @@ f32 TMapObjWanwan::getRandRadius(u8 max, u8 min) {
532535
deg += min;
533536
}
534537
return MTXDegToRad(deg);
535-
536538
}
537539

538540
void TMapObjWanwan::getWanwanBackPos(JGeometry::TVec3f *out) {
@@ -544,9 +546,8 @@ void TMapObjWanwan::getWanwanBackPos(JGeometry::TVec3f *out) {
544546
return;
545547
}
546548

547-
// TODO: all matrices from J3D might already be TPos3f of itself
548-
JGeometry::TPos3f *bumpMtx = (JGeometry::TPos3f *)mModel.getModel()->getAnmMtx(sChainJointNo);
549-
bumpMtx->getTrans(*out);
549+
Mtx &bumpMtx = mModel.getModel()->getAnmMtx(sChainJointNo);
550+
out->set(bumpMtx[0][3], bumpMtx[1][3], bumpMtx[2][3]);
550551
}
551552

552553
f32 TMapObjWanwan::getAngleToAttack(JGeometry::TVec3f &v) {
@@ -572,17 +573,15 @@ void TMapObjWanwan::calc() {
572573
mFreeMove.update();
573574
}
574575
chainCorrect();
575-
mpGround->search(mPos);
576-
if (mPos.y - mHeightOffset <= mpGround->getHeight() ) {
576+
577+
if (isTouchGround()) {
577578
mpGround->search(mPos);
578579
mPos.y = mHeightOffset + mpGround->getHeight() - 0.1f;
579580
mVel.y = 0.0f;
580581
}
581582

582583
bool isWall = false;
583584
mpGround->search(mPos, pos);
584-
585-
586585
if (mpGround->getAttribute() == CrsGround::Attr_2) {
587586
JGeometry::TVec3f wall;
588587

@@ -605,7 +604,6 @@ void TMapObjWanwan::calc() {
605604
for (; a >= F_PI; a -= F_TAU);
606605
mAttackAngle = a;
607606
}
608-
609607
}
610608
}
611609

@@ -667,8 +665,6 @@ void TMapObjWanwan::chainCorrect() {
667665

668666
vel.zero();
669667
mpStringNodeMgr->setNodeVel(mNumChains - 1, vel);
670-
671-
672668
fixChain();
673669
}
674670

@@ -723,18 +719,19 @@ void TMapObjWanwan::setChainPosition(TMapObjWanwanChain *pChain, JGeometry::TVec
723719
r_m.setXYZDir(cp, yDir, rPosDiff);
724720
PSMTXIdentity(b);
725721

722+
// might be setRotate?
726723
f32 s = sin(f);
727724
f32 c = cos(f);
728725

729726
b[0][0] = c;
730727
b[0][1] = -s;
731728
b[1][0] = s;
732729
b[1][1] = c;
733-
b[2][2] = 1.0;
734-
b[2][1] = 0.0;
735-
b[1][2] = 0.0;
736-
b[2][0] = 0.0;
737-
b[0][2] = 0.0;
730+
b[2][2] = 1.0f;
731+
b[2][1] = 0.0f;
732+
b[1][2] = 0.0f;
733+
b[2][0] = 0.0f;
734+
b[0][2] = 0.0f;
738735

739736
PSMTXConcat(r_m, b, r_m);
740737
pChain->mRotMtx.set( r_m );

0 commit comments

Comments
 (0)