From d8a0182f720173b8793ff8a75a89975d0faf4265 Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Sun, 14 Apr 2024 09:26:20 -0700 Subject: [PATCH] TVec3 cleanup, JPAField work --- include/JSystem/JGeometry.h | 165 ++++++++++++++++------------- src/JSystem/JParticle/JPAField.cpp | 8 +- 2 files changed, 92 insertions(+), 81 deletions(-) diff --git a/include/JSystem/JGeometry.h b/include/JSystem/JGeometry.h index 56268aeaf..0a711c9f7 100644 --- a/include/JSystem/JGeometry.h +++ b/include/JSystem/JGeometry.h @@ -74,16 +74,10 @@ struct TVec3 : public SVec { template <> struct TVec3 : public Vec { - // f32 x; - // f32 y; - // f32 z; - inline TVec3(const Vec& i_vec) { set(i_vec); } - TVec3() {} - TVec3(f32 x, f32 y, f32 z) { set(x, y, z); } operator Vec*() { return (Vec*)&x; } @@ -107,74 +101,18 @@ struct TVec3 : public Vec { z = z_; } - inline void add(const TVec3& b) { - C_VECAdd((Vec*)&x, (Vec*)&b.x, (Vec*)&x); - } - void zero() { x = y = z = 0.0f; } - void mul(const TVec3& a, const TVec3& b) { - x = a.x * b.x; - y = a.y * b.y; - z = a.z * b.z; + void add(const TVec3& b) { + x += b.x; + y += b.y; + z += b.z; } - inline TVec3& operator+=(const TVec3& b) { - add(b); - return *this; - } - - // inline TVec3 operator+(const TVec3& b) { - // TVec3 res(*(Vec*)this); - // res += b; - // return res; - // } - - inline TVec3& operator=(const TVec3& b) { - set(b.x, b.y, b.z); - return *this; - } - - inline TVec3& operator=(const Vec& vec) { - set(vec); - return *this; - } - - f32 squared() const { - return C_VECSquareMag((Vec*)&x); - } - - f32 normalize() { - f32 sq = squared(); - if (sq <= TUtil::epsilon()) { - return 0.0f; - } - f32 norm = TUtil::inv_sqrt(sq); - scale(norm); - return norm; - } - - f32 length() const { - f32 sqr = squared(); - return TUtil::sqrt(sqr); - } - - void scale(f32 sc) { - x *= sc; - y *= sc; - z *= sc; - } - - void scale(f32 sc, const TVec3& b) { - x = b.x * sc; - y = b.y * sc; - z = b.z * sc; - } - - void negate() { - x = -x; - y = -y; - z = -z; + void add(const TVec3& a, const TVec3& b) { + x = a.x + b.x; + y = a.x + b.y; + z = a.x + b.z; } void sub(const TVec3& b) { @@ -189,6 +127,69 @@ struct TVec3 : public Vec { z = a.z - b.z; } + void mul(const TVec3& b) { + x *= b.x; + y *= b.y; + z *= b.z; + } + + void mul(const TVec3& a, const TVec3& b) { + x = a.x * b.x; + y = a.y * b.y; + z = a.z * b.z; + } + + void scale(f32 scale, const TVec3& b) { + x = b.x * scale; + y = b.y * scale; + z = b.z * scale; + } + + void scale(f32 scale) { + x *= scale; + y *= scale; + z *= scale; + } + + void scaleAdd(f32 scale, const TVec3& b, const TVec3& c) { + x = b.x + c.x * scale; + y = b.y + c.y * scale; + z = b.z + c.z * scale; + } + + void negate() { + x = -x; + y = -y; + z = -z; + } + + f32 dot(const TVec3& b) const { + return x*b.x + y*b.y * z*b.z; + } + + f32 squared() const { + return x*x + y*y + z*z; + } + + f32 squared(const TVec3& b) const { + return (x - b.x)*(x - b.x) + (y - b.y)*(y - b.y) + (z - b.z)*(z - b.z); + } + + f32 length() const { + f32 sqr = squared(); + return TUtil::sqrt(sqr); + } + + f32 normalize() { + f32 sq = squared(); + if (sq <= TUtil::epsilon()) { + return 0.0f; + } + f32 norm = TUtil::inv_sqrt(sq); + scale(norm); + return norm; + } + bool isZero() const { return squared() <= TUtil::epsilon(); } @@ -206,10 +207,6 @@ struct TVec3 : public Vec { scale(norm * len); } - f32 dot(const TVec3& b) const { - return x*b.x + y*b.y * z*b.z; - } - template void cubic(const JGeometry::TVec3& vec1, const JGeometry::TVec3& vec2, const JGeometry::TVec3& vec3, const JGeometry::TVec3& vec4, f32 f19) { // TODO: name variables properly @@ -223,6 +220,26 @@ struct TVec3 : public Vec { this->y = (f3 * vec1.y) + (f2 * vec2.y) + (f1 * vec4.y) + (f0 * vec3.y); this->z = (f3 * vec1.z) + (f2 * vec2.z) + (f1 * vec4.z) + (f0 * vec3.x); } + + inline TVec3& operator+=(const TVec3& b) { + add(b); + return *this; + } + + inline TVec3& operator*=(const TVec3& b) { + mul(b); + return *this; + } + + inline TVec3& operator=(const TVec3& b) { + set(b.x, b.y, b.z); + return *this; + } + + inline TVec3& operator=(const Vec& vec) { + set(vec); + return *this; + } }; template diff --git a/src/JSystem/JParticle/JPAField.cpp b/src/JSystem/JParticle/JPAField.cpp index fa3b5a601..37688568b 100644 --- a/src/JSystem/JParticle/JPAField.cpp +++ b/src/JSystem/JParticle/JPAField.cpp @@ -296,16 +296,10 @@ void JPAFieldManager::preCalc() { /* 8025BA10-8025BAD8 .text calc__15JPAFieldManagerFP15JPABaseParticle */ void JPAFieldManager::calc(JPABaseParticle* ptcl) { - /* Nonmatching */ for (JSULink* link = mList.getFirst(); link != NULL; link = link->getNext()) { JPAFieldData* data = link->getObject(); if (data->mSttFlag & 0x80) { - // This isn't quite right, probably a TVec3 inline? - f32 z = ptcl->mPosition.z - data->mPos.z; z *= z; - f32 x = ptcl->mPosition.x - data->mPos.x; x *= x; - f32 y = ptcl->mPosition.y - data->mPos.y; y *= y; - f32 dist = z + y + x; - if (!data->mpBaseField->isItinRange(data, dist)) + if (!data->mpBaseField->isItinRange(data, ptcl->mPosition.squared(data->mPos))) continue; } data->mpBaseField->calc(data, ptcl);