From 832f4abf8b3f6189bdd4ba1906824773c3d6da09 Mon Sep 17 00:00:00 2001 From: SwareJonge <41187958+SwareJonge@users.noreply.github.com> Date: Fri, 10 Jan 2025 20:05:35 +0100 Subject: [PATCH] match and link JPAMath --- configure.py | 2 +- include/JSystem/JParticle/JPAMath.h | 6 +- libs/JSystem/JParticle/JPABaseShape.cpp | 117 +++++++++--------- libs/JSystem/JParticle/JPAMath.cpp | 157 ++++++++++++++++++++++++ 4 files changed, 220 insertions(+), 62 deletions(-) diff --git a/configure.py b/configure.py index 40a3fea1..824348b8 100755 --- a/configure.py +++ b/configure.py @@ -951,7 +951,7 @@ def MatchingFor(*versions): Object(NonMatching, "JSystem/JParticle/JPAExtraShape.cpp"), Object(NonMatching, "JSystem/JParticle/JPAFieldBlock.cpp"), Object(Matching, "JSystem/JParticle/JPAKeyBlock.cpp"), - Object(NonMatching, "JSystem/JParticle/JPAMath.cpp"), + Object(Matching, "JSystem/JParticle/JPAMath.cpp"), Object(NonMatching, "JSystem/JParticle/JPAParticle.cpp"), Object(NonMatching, "JSystem/JParticle/JPAResource.cpp"), Object(NonMatching, "JSystem/JParticle/JPAResourceLoader.cpp"), diff --git a/include/JSystem/JParticle/JPAMath.h b/include/JSystem/JParticle/JPAMath.h index e2a74373..6e8d345b 100644 --- a/include/JSystem/JParticle/JPAMath.h +++ b/include/JSystem/JParticle/JPAMath.h @@ -6,10 +6,10 @@ static inline u32 COLOR_MULTI(u32 color1, u32 color2) { return (color1 * (color2 + 1) * 0x10000) >> 24; } -void JPAConvertFixToFloat(short); +f32 JPAConvertFixToFloat(s16); void JPAGetDirMtx(const JGeometry::TVec3f &, Mtx); -void JPAGetYZRotateMtx(short, short, Mtx); -void JPAGetXYZRotateMtx(short, short, short, Mtx); +void JPAGetYZRotateMtx(s16, s16, Mtx); +void JPAGetXYZRotateMtx(s16, s16, s16, Mtx); void JPASetRMtxfromMtx(const Mtx, Mtx); void JPASetRMtxTVecfromMtx(const Mtx, Mtx, JGeometry::TVec3f *); void JPASetRMtxSTVecfromMtx(const Mtx, Mtx, JGeometry::TVec3f *, JGeometry::TVec3f *); diff --git a/libs/JSystem/JParticle/JPABaseShape.cpp b/libs/JSystem/JParticle/JPABaseShape.cpp index e2eddd7f..5659eeb7 100644 --- a/libs/JSystem/JParticle/JPABaseShape.cpp +++ b/libs/JSystem/JParticle/JPABaseShape.cpp @@ -618,7 +618,7 @@ void JPADrawBillboard(JPAEmitterWorkData *work, JPABaseParticle *particle) return; JGeometry::TVec3f position; - PSMTXMultVec(work->mPosCamMtx, (Vec *)&particle->mPosition, (Vec *)&position); + PSMTXMultVec(work->mPosCamMtx, &particle->mPosition, &position); Mtx mtx; mtx[0][0] = work->mGlobalPtclScl.x * particle->mParticleScaleX; mtx[0][3] = position.x; @@ -636,10 +636,10 @@ void JPADrawBillboard(JPAEmitterWorkData *work, JPABaseParticle *particle) void JPADrawRotBillboard(JPAEmitterWorkData *work, JPABaseParticle *particle) { if (particle->checkStatus(8) != 0) - return; + return; JGeometry::TVec3f position; - PSMTXMultVec(work->mPosCamMtx, (Vec *)&particle->mPosition, (Vec *)&position); + PSMTXMultVec(work->mPosCamMtx, &particle->mPosition, &position); f32 sinRot = JMASSin(particle->mRotateAngle); f32 cosRot = JMASCos(particle->mRotateAngle); f32 particleX = work->mGlobalPtclScl.x * particle->mParticleScaleX; @@ -666,23 +666,23 @@ void JPADrawYBillboard(JPAEmitterWorkData *work, JPABaseParticle *particle) if (particle->checkStatus(8) != 0) return; - JGeometry::TVec3f position; - PSMTXMultVec(work->mPosCamMtx, (Vec *)&particle->mPosition, (Vec *)&position); - Mtx mtx; - f32 particleX = work->mGlobalPtclScl.x * particle->mParticleScaleX; - f32 particleY = work->mGlobalPtclScl.y * particle->mParticleScaleY; - mtx[0][0] = particleX; - mtx[0][3] = position.x; - mtx[1][1] = work->mYBBCamMtx[1][1] * particleY; - mtx[1][2] = work->mYBBCamMtx[1][2]; - mtx[1][3] = position.y; - mtx[2][1] = work->mYBBCamMtx[2][1] * particleY; - mtx[2][2] = work->mYBBCamMtx[2][2]; - mtx[2][3] = position.z; - mtx[0][1] = mtx[0][2] = mtx[1][0] = mtx[2][0] = 0.0f; - GXLoadPosMtxImm(mtx, 0); - p_prj[work->mProjectionType](work, mtx); - GXCallDisplayList(jpa_dl, sizeof(jpa_dl)); + JGeometry::TVec3f position; + PSMTXMultVec(work->mPosCamMtx, &particle->mPosition, &position); + Mtx mtx; + f32 particleX = work->mGlobalPtclScl.x * particle->mParticleScaleX; + f32 particleY = work->mGlobalPtclScl.y * particle->mParticleScaleY; + mtx[0][0] = particleX; + mtx[0][3] = position.x; + mtx[1][1] = work->mYBBCamMtx[1][1] * particleY; + mtx[1][2] = work->mYBBCamMtx[1][2]; + mtx[1][3] = position.y; + mtx[2][1] = work->mYBBCamMtx[2][1] * particleY; + mtx[2][2] = work->mYBBCamMtx[2][2]; + mtx[2][3] = position.z; + mtx[0][1] = mtx[0][2] = mtx[1][0] = mtx[2][0] = 0.0f; + GXLoadPosMtxImm(mtx, 0); + p_prj[work->mProjectionType](work, mtx); + GXCallDisplayList(jpa_dl, sizeof(jpa_dl)); } @@ -692,7 +692,7 @@ void JPADrawRotYBillboard(JPAEmitterWorkData *work, JPABaseParticle *particle) return; JGeometry::TVec3f position; - PSMTXMultVec(work->mPosCamMtx, (Vec *)&particle->mPosition, (Vec *)&position); + PSMTXMultVec(work->mPosCamMtx, &particle->mPosition, &position); f32 sinRot = JMASSin(particle->mRotateAngle); f32 cosRot = JMASCos(particle->mRotateAngle); Mtx mtx; @@ -959,32 +959,32 @@ void JPADrawDBillboard(JPAEmitterWorkData *work, JPABaseParticle *particle) if (particle->checkStatus(8) != 0) return; - JGeometry::TVec3 direction; - p_direction[work->mDirType](work, particle, &direction); - JGeometry::TVec3 cameraPos(work->mPosCamMtx[2][0], work->mPosCamMtx[2][1], work->mPosCamMtx[2][2]); - direction.cross(direction, cameraPos); - if (direction.isZero()) - return; - - direction.normalize(); - PSMTXMultVecSR(work->mPosCamMtx, (Vec *)&direction, (Vec *)&direction); - JGeometry::TVec3 particlePos; - PSMTXMultVec(work->mPosCamMtx, (Vec *)&particle->mPosition, (Vec *)&particlePos); - f32 particleX = work->mGlobalPtclScl.x * particle->mParticleScaleX; - f32 particleY = work->mGlobalPtclScl.y * particle->mParticleScaleY; - Mtx transformMtx; - transformMtx[0][0] = direction.x * particleX; - transformMtx[0][1] = -direction.y * particleY; - transformMtx[0][3] = particlePos.x; - transformMtx[1][0] = direction.y * particleX; - transformMtx[1][1] = direction.x * particleY; - transformMtx[1][3] = particlePos.y; - transformMtx[2][2] = 1.0f; - transformMtx[2][3] = particlePos.z; - transformMtx[0][2] = transformMtx[2][0] = transformMtx[2][1] = 0.0f; - GXLoadPosMtxImm(transformMtx, 0); - p_prj[work->mProjectionType](work, transformMtx); - GXCallDisplayList(jpa_dl, sizeof(jpa_dl)); + JGeometry::TVec3f direction; + p_direction[work->mDirType](work, particle, &direction); + JGeometry::TVec3f cameraPos(work->mPosCamMtx[2][0], work->mPosCamMtx[2][1], work->mPosCamMtx[2][2]); + direction.cross(direction, cameraPos); + if (direction.isZero()) + return; + + direction.normalize(); + PSMTXMultVecSR(work->mPosCamMtx, &direction, &direction); + JGeometry::TVec3 particlePos; + PSMTXMultVec(work->mPosCamMtx, &particle->mPosition, &particlePos); + f32 particleX = work->mGlobalPtclScl.x * particle->mParticleScaleX; + f32 particleY = work->mGlobalPtclScl.y * particle->mParticleScaleY; + Mtx transformMtx; + transformMtx[0][0] = direction.x * particleX; + transformMtx[0][1] = -direction.y * particleY; + transformMtx[0][3] = particlePos.x; + transformMtx[1][0] = direction.y * particleX; + transformMtx[1][1] = direction.x * particleY; + transformMtx[1][3] = particlePos.y; + transformMtx[2][2] = 1.0f; + transformMtx[2][3] = particlePos.z; + transformMtx[0][2] = transformMtx[2][0] = transformMtx[2][1] = 0.0f; + GXLoadPosMtxImm(transformMtx, 0); + p_prj[work->mProjectionType](work, transformMtx); + GXCallDisplayList(jpa_dl, sizeof(jpa_dl)); } void JPADrawRotation(JPAEmitterWorkData *work, JPABaseParticle *ptcl) @@ -1030,21 +1030,22 @@ void JPADrawLine(JPAEmitterWorkData *work, JPABaseParticle *particle) if (particle->checkStatus(8) != 0) return; - JGeometry::TVec3f position(particle->mPosition); - JGeometry::TVec3f direction; - particle->getVelVec(&direction); - if (direction.isZero()) + JGeometry::TVec3f position1(particle->mPosition); + JGeometry::TVec3f position2; + + particle->getVelVec(&position2); + if (position2.isZero()) return; - direction.setLength(work->mGlobalPtclScl.y * (25.0f * particle->mParticleScaleY)); - direction.sub(position, direction); + position2.setLength(work->mGlobalPtclScl.y * (25.0f * particle->mParticleScaleY)); + position2.sub(position1, position2); GXSetVtxDesc(GX_VA_POS, GX_DIRECT); GXSetVtxDesc(GX_VA_TEX0, GX_DIRECT); GXBegin(GX_LINES, GX_VTXFMT1, 2); - GXPosition3f32(position.x, position.y, position.z); + GXPosition3f32(position1.x, position1.y, position1.z); GXTexCoord2f32(0.0f, 0.0f); - GXPosition3f32(direction.x, direction.y, direction.z); + GXPosition3f32(position2.x, position2.y, position2.z); GXTexCoord2f32(0.0f, 1.0f); GXEnd(); @@ -1145,7 +1146,7 @@ void JPADrawStripe(JPAEmitterWorkData *work) matrix[2][2] = particle->mBaseAxis.z; matrix[2][3] = 0.0f; - PSMTXMultVecArraySR(matrix, (Vec *)local_e0, (Vec *)local_e0, 2); // ??? + PSMTXMultVecArraySR(matrix, local_e0, local_e0, 2); // ??? GXPosition3f32(local_e0[0].x + local_ec.x, local_e0[0].y + local_ec.y, local_e0[0].z + local_ec.z); @@ -1250,7 +1251,7 @@ void JPADrawStripeX(JPAEmitterWorkData *work) matrix[2][1] = direction.z; matrix[2][2] = particle->mBaseAxis.z; matrix[2][3] = 0.0f; - PSMTXMultVecArraySR(matrix, (Vec *)local_a8, (Vec *)local_a8, 2); // ??? + PSMTXMultVecArraySR(matrix, local_a8, local_a8, 2); // ??? GXPosition3f32(local_a8[0].x + position.x, local_a8[0].y + position.y, local_a8[0].z + position.z); GXTexCoord2f32( 0.0f, coord); GXPosition3f32(local_a8[1].x + position.x, local_a8[1].y + position.y, local_a8[1].z + position.z); @@ -1309,7 +1310,7 @@ void JPADrawStripeX(JPAEmitterWorkData *work) matrix[2][1] = direction.z; matrix[2][2] = particle->mBaseAxis.z; matrix[2][3] = 0.0f; - PSMTXMultVecArraySR(matrix, (Vec *)local_a8, (Vec *)local_a8, 2); // ??? + PSMTXMultVecArraySR(matrix, local_a8, local_a8, 2); // ??? GXPosition3f32(local_a8[0].x + position.x, local_a8[0].y + position.y, local_a8[0].z + position.z); //const f32 zero = 0.0f; diff --git a/libs/JSystem/JParticle/JPAMath.cpp b/libs/JSystem/JParticle/JPAMath.cpp index e69de29b..9dfa3773 100644 --- a/libs/JSystem/JParticle/JPAMath.cpp +++ b/libs/JSystem/JParticle/JPAMath.cpp @@ -0,0 +1,157 @@ +#include "JSystem/JParticle/JPAMath.h" +#include "JSystem/JGeometry/Vec.h" + +f32 JPAConvertFixToFloat(s16) { + return 1.0f; + // UNUSED FUNCTION +} + +void JPAGetDirMtx(const JGeometry::TVec3f &vec, Mtx mtx) { + Vec *v = (Vec *)&vec; // fakematch? + JGeometry::TVec3f newVec; + newVec.set(vec.y, -vec.x, 0.0f); + f32 mag = newVec.length(); + if (mag <= JGeometry::TUtilf::epsilon()) { + newVec.zero(); + } else { + newVec.scale(1.0f / mag); + } + + const f32 xSq = newVec.x * newVec.x; // f30 + const f32 ySq = newVec.y * newVec.y; // f29 + const f32 xLen = newVec.x * mag; // f28 + const f32 yLen = newVec.y * mag; // f27 + const f32 xyz = (1.0f - vec.z) * (newVec.x * newVec.y); // f26 + + mtx[0][0] = xSq + vec.z * (1.0f - xSq); + mtx[0][1] = xyz; + mtx[0][2] = -yLen; + mtx[0][3] = 0.0f; + + mtx[1][0] = xyz; + mtx[1][1] = ySq + vec.z * (1.0f - ySq); + mtx[1][2] = xLen; + mtx[1][3] = 0.0f; + + mtx[2][0] = yLen; + mtx[2][1] = -xLen; + mtx[2][2] = v->z; + mtx[2][3] = 0.0f; +} + +void JPAGetYZRotateMtx(s16 angleY, s16 angleZ, Mtx m) { + f32 cosy = JMASCos(angleY); + f32 cosz = JMASCos(angleZ); + f32 siny = JMASSin(angleY); + f32 sinz = JMASSin(angleZ); + m[0][0] = (cosy * cosz); + m[0][1] = -sinz; + m[0][2] = (siny * cosz); + m[1][0] = (cosy * sinz); + m[1][1] = cosz; + m[1][2] = (siny * sinz); + m[2][0] = -siny; + m[2][2] = cosy; + m[2][3] = 0.0f; + m[2][1] = 0.0f; + m[1][3] = 0.0f; + m[0][3] = 0.0f; +} + +void JPAGetXYZRotateMtx(s16 x, s16 y, s16 z, Mtx m) { + f32 cx = JMASCos(x); + f32 cy = JMASCos(y); + f32 cz = JMASCos(z); + + f32 sx = JMASSin(x); + f32 sy = JMASSin(y); + f32 sz = JMASSin(z); + + m[0][0] = cy * cz; + m[1][0] = cy * sz; + + m[2][0] = -sy; + m[2][1] = sx * cy; + m[2][2] = cx * cy; + + f32 cxsz = cx * sz; + f32 sxcz = sx * cz; + + m[0][1] = sxcz * sy - cxsz; + m[1][2] = cxsz * sy - sxcz; + + f32 sxsz = sx * sz; + f32 cxcz = cx * cz; + m[0][2] = sxsz + cxcz * sy; + m[1][1] = cxcz + sxsz * sy; + + m[2][3] = 0.0f; + m[1][3] = 0.0f; + m[0][3] = 0.0f; +} + +void JPASetRMtxfromMtx(const Mtx src, Mtx dst) { + JGeometry::TVec3f v1, v2; + JPASetRMtxSTVecfromMtx(src, dst, &v1, &v2); +} + +void JPASetRMtxTVecfromMtx(const Mtx src, Mtx dst, JGeometry::TVec3f *v2) { + JGeometry::TVec3f v; + JPASetRMtxSTVecfromMtx(src, dst, &v, v2); +} + +void JPASetRMtxSTVecfromMtx(const Mtx mtx, Mtx RMtx, JGeometry::TVec3f* lengths, JGeometry::TVec3f* translation) { + JGeometry::TVec3f tempVec; + tempVec.set(mtx[0][0], mtx[1][0], mtx[2][0]); + lengths->x = tempVec.length(); + tempVec.set(mtx[0][1], mtx[1][1], mtx[2][1]); + lengths->y = tempVec.length(); + tempVec.set(mtx[0][2], mtx[1][2], mtx[2][2]); + lengths->z = tempVec.length(); + PSMTXIdentity(RMtx); + if (lengths->x != 0.0f) { + f32 fVar5 = 1.0f / lengths->x; + RMtx[0][0] = mtx[0][0] * fVar5; + RMtx[1][0] = mtx[1][0] * fVar5; + RMtx[2][0] = mtx[2][0] * fVar5; + } + if (lengths->y != 0.0f) { + f32 fVar5 = 1.0f / lengths->y; + RMtx[0][1] = mtx[0][1] * fVar5; + RMtx[1][1] = mtx[1][1] * fVar5; + RMtx[2][1] = mtx[2][1] * fVar5; + } + if (lengths->z != 0.0f) { + f32 fVar5 = 1.0f / lengths->z; + RMtx[0][2] = mtx[0][2] * fVar5; + RMtx[1][2] = mtx[1][2] * fVar5; + RMtx[2][2] = mtx[2][2] * fVar5; + } + + translation->set(mtx[0][3], mtx[1][3], mtx[2][3]); +} + +f32 JPACalcKeyAnmValue(f32 currentFrame, u16 keyFrameCount, const f32* keyFrameData) { +if (currentFrame < keyFrameData[0]) { + return keyFrameData[1]; + } + + int lastKeyFrameIndex = keyFrameCount - 1; + if (keyFrameData[lastKeyFrameIndex * 4] <= currentFrame) { + return keyFrameData[lastKeyFrameIndex * 4 + 1]; + } + + int frame = keyFrameCount; + while (frame > 1) { + u32 halfIndex = frame / 2; + if (currentFrame >= keyFrameData[halfIndex * 4]) { + keyFrameData += halfIndex * 4; + frame -= halfIndex; + } else { + frame = halfIndex; + } + } + + return JMAHermiteInterpolation(currentFrame, keyFrameData[0], keyFrameData[1], keyFrameData[3], keyFrameData[4], keyFrameData[5], + keyFrameData[6]); +}