From 0c32a3d3c1cd5c70ba2dbf48b97ec9c99042f20b Mon Sep 17 00:00:00 2001 From: LagoLunatic Date: Sun, 14 Apr 2024 18:10:49 -0400 Subject: [PATCH] fix TVec3::setLength --- .../JSystem/J3DGraphAnimator/J3DAnimation.h | 14 +++++++------- include/JSystem/JGeometry.h | 11 +++++++---- src/JSystem/JParticle/JPAField.cpp | 6 +----- src/JSystem/JParticle/JPAParticle.cpp | 18 ++++++++---------- 4 files changed, 23 insertions(+), 26 deletions(-) diff --git a/include/JSystem/J3DGraphAnimator/J3DAnimation.h b/include/JSystem/J3DGraphAnimator/J3DAnimation.h index 5d8d37df6..5c732255e 100644 --- a/include/JSystem/J3DGraphAnimator/J3DAnimation.h +++ b/include/JSystem/J3DGraphAnimator/J3DAnimation.h @@ -12,13 +12,13 @@ struct J3DAnmKeyTableBase { }; // Size = 0x6 struct J3DAnmColorKeyTable { - enum Color { - RED = 0, - GREEN = 1, - BLUE = 2, - ALPHA = 3, - }; - /* 0x00 */ J3DAnmKeyTableBase mColorInfo[4]; + enum Color { + RED = 0, + GREEN = 1, + BLUE = 2, + ALPHA = 3, + }; + /* 0x00 */ J3DAnmKeyTableBase mColorInfo[4]; }; // Size = 0x18 struct J3DAnmColorFullTable { diff --git a/include/JSystem/JGeometry.h b/include/JSystem/JGeometry.h index 60dcb12b8..3eb947076 100644 --- a/include/JSystem/JGeometry.h +++ b/include/JSystem/JGeometry.h @@ -207,22 +207,25 @@ struct TVec3 : public Vec { z = a.x * b.y - a.y * b.x; } - void setLength(f32 len) { + f32 setLength(f32 len) { f32 sq = squared(); if (sq <= TUtil::epsilon()) { - return; + return 0.0f; } f32 norm = TUtil::inv_sqrt(sq); scale(norm * len); + return sq * norm; } - void setLength(const TVec3& b, f32 len) { + f32 setLength(const TVec3& b, f32 len) { f32 sq = b.squared(); if (sq <= TUtil::epsilon()) { - return; + zero(); + return 0.0f; } f32 norm = TUtil::inv_sqrt(sq); scale(norm * len, b); + return sq * norm; } template diff --git a/src/JSystem/JParticle/JPAField.cpp b/src/JSystem/JParticle/JPAField.cpp index 4f02ed0de..750d6fffc 100644 --- a/src/JSystem/JParticle/JPAField.cpp +++ b/src/JSystem/JParticle/JPAField.cpp @@ -270,11 +270,7 @@ void JPAConvectionField::calc(JPAFieldData* data, JPABaseParticle* ptcl) { JGeometry::TVec3 newPos; newPos.add(axisX, axisZ); - if (newPos.isZero()) { - newPos.zero(); - } else { - newPos.setLength(data->mVal1); - } + newPos.setLength(newPos, data->mVal1); JGeometry::TVec3 delta, axisY; delta.sub(ptcl->mLocalPosition, newPos); diff --git a/src/JSystem/JParticle/JPAParticle.cpp b/src/JSystem/JParticle/JPAParticle.cpp index 56ac95832..af3cfa086 100644 --- a/src/JSystem/JParticle/JPAParticle.cpp +++ b/src/JSystem/JParticle/JPAParticle.cpp @@ -28,13 +28,15 @@ void JPABaseParticle::initParticle() { mGlobalPosition.set(emtrInfo.mEmitterGlobalCenter); - velOmni.zero(); - if (emtr->mInitialVelOmni != 0.0f && !emtrInfo.mVelOmni.isZero()) + if (emtr->mInitialVelOmni) velOmni.setLength(emtrInfo.mVelOmni, emtr->mInitialVelOmni); + else + velOmni.zero(); - velAxis.zero(); - if (emtr->mInitialVelAxis != 0.0f && !emtrInfo.mVelAxis.isZero()) + if (emtr->mInitialVelAxis) velAxis.setLength(emtrInfo.mVelAxis, emtr->mInitialVelAxis); + else + velAxis.zero(); velDir.zero(); if (emtr->mInitialVelDir != 0.0f) { @@ -63,12 +65,8 @@ void JPABaseParticle::initParticle() { MTXMultVec(emtrInfo.mEmitterGlobalRot, mBaseVel, mBaseVel); - if (mBaseVel.isZero()) { - mAccel.zero(); - } else { - f32 accel = emtr->mAccel * (1.0f + emtr->getRandomRF() * emtr->mAccelRndm); - mAccel.setLength(mBaseVel, accel); - } + f32 accel = emtr->mAccel * (1.0f + emtr->getRandomRF() * emtr->mAccelRndm); + mAccel.setLength(mBaseVel, accel); mAirResist = emtr->mAirResist + emtr->mAirResistRndm * emtr->getRandomSF(); if (mAirResist > 1.0f)