From 23484e2799521e8be852f22bc11eab5a9e5d63aa Mon Sep 17 00:00:00 2001 From: LagoLunatic Date: Mon, 15 Jul 2024 17:02:00 -0400 Subject: [PATCH] JPAGetDirMtx: fix codegen, break regalloc --- src/JSystem/JParticle/JPAMath.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/JSystem/JParticle/JPAMath.cpp b/src/JSystem/JParticle/JPAMath.cpp index a371e7681..bffd95e8b 100644 --- a/src/JSystem/JParticle/JPAMath.cpp +++ b/src/JSystem/JParticle/JPAMath.cpp @@ -60,30 +60,32 @@ void JPAGetXYZRotateMtx(s16 x, s16 y, s16 z, Mtx dst) { /* 80259A64-80259B6C .text JPAGetDirMtx__FRCQ29JGeometry8TVec3PA4_f */ void JPAGetDirMtx(const JGeometry::TVec3& dir, Mtx dst) { - /* Nonmatching */ + /* Nonmatching - regalloc */ JGeometry::TVec3 perp; perp.x = dir.y; perp.y = -dir.x; f32 z = dir.z; perp.z = 0.0f; - f32 mag = perp.squared(); - mag *= JGeometry::TUtil::inv_sqrt(mag); + f32 mag = perp.length(); if (mag <= JGeometry::TUtil::epsilon()) { - perp.x = perp.y = 0.0f; + perp.zero(); } else { - perp.x *= (1.0f / mag); - perp.y *= (1.0f / mag); + perp.scale(1.0f / mag); } f32 x = perp.x, y = perp.y; - dst[0][0] = x*x + z * (1.0f - x*x); - dst[0][1] = (1.0f - z) * (x * y); + f32 xx = x*x; + f32 yy = y*y; + f32 xy = x*y; + + dst[0][0] = xx + z * (1.0f - xx); + dst[0][1] = xy * (1.0f - z); dst[0][2] = -y * mag; dst[0][3] = 0.0f; - dst[1][0] = (1.0f - z) * (x * y); - dst[1][1] = y*y + z * (1.0f - y*y); + dst[1][0] = xy * (1.0f - z); + dst[1][1] = yy + z * (1.0f - yy); dst[1][2] = x*mag; dst[1][3] = 0.0f;