From dc96ffc5517d18c7ffcc26ba600b0e3716ca77d6 Mon Sep 17 00:00:00 2001 From: Falco Girgis Date: Tue, 15 Apr 2025 13:53:19 -0500 Subject: [PATCH] FIXED LIBERTY BOAT ROTATION ISSUES. --- src/liberty/math/Matrix.cpp | 2 +- src/liberty/math/Matrix.h | 8 +------- src/liberty/math/Quaternion.h | 5 +++-- src/liberty/math/Vector.cpp | 24 +++++++++--------------- src/liberty/math/Vector.h | 5 +++-- 5 files changed, 17 insertions(+), 27 deletions(-) diff --git a/src/liberty/math/Matrix.cpp b/src/liberty/math/Matrix.cpp index a919baaf..5ac7d4c4 100644 --- a/src/liberty/math/Matrix.cpp +++ b/src/liberty/math/Matrix.cpp @@ -454,7 +454,7 @@ operator*(const CMatrix &m1, const CMatrix &m2) { // TODO: VU0 code CMatrix out; -#if defined(RW_DC) +#ifdef DC_SH4 mat_mult(out, m1, m2); #else out.rx = m1.rx * m2.rx + m1.fx * m2.ry + m1.ux * m2.rz; diff --git a/src/liberty/math/Matrix.h b/src/liberty/math/Matrix.h index 06dab72a..295d5540 100644 --- a/src/liberty/math/Matrix.h +++ b/src/liberty/math/Matrix.h @@ -63,7 +63,6 @@ public: void SetScale(float s); void Scale(float scale) { -#ifndef DC_SH4 for (int i = 0; i < 3; i++) #ifdef FIX_BUGS // BUGFIX from VC for (int j = 0; j < 3; j++) @@ -71,11 +70,6 @@ public: for (int j = 0; j < 4; j++) #endif f[i][j] *= scale; -#else - mat_load(*this); - mat_scale(scale, scale, scale); - mat_store(*this); -#endif } @@ -112,7 +106,7 @@ CMatrix Invert(const CMatrix &matrix); CMatrix operator*(const CMatrix &m1, const CMatrix &m2); inline CVector MultiplyInverse(const CMatrix &mat, const CVector &vec) { -#ifndef DC_SH4 +#if 1 CVector v(vec.x - mat.px, vec.y - mat.py, vec.z - mat.pz); return CVector( mat.rx * v.x + mat.ry * v.y + mat.rz * v.z, diff --git a/src/liberty/math/Quaternion.h b/src/liberty/math/Quaternion.h index c1b0e481..185adb7c 100644 --- a/src/liberty/math/Quaternion.h +++ b/src/liberty/math/Quaternion.h @@ -62,7 +62,7 @@ public: } const CQuaternion &operator/=(float right) { - right = dc::Invert(right); + right = dc::Invert(right); x *= right; y *= right; z *= right; @@ -115,5 +115,6 @@ inline CQuaternion operator*(float left, const CQuaternion &right) inline CQuaternion operator/(const CQuaternion &left, float right) { - return CQuaternion(left.x / right, left.y / right, left.z / right, left.w / right); + right = Invert(right); + return CQuaternion(left.x * right, left.y * right, left.z * right, left.w * right); } diff --git a/src/liberty/math/Vector.cpp b/src/liberty/math/Vector.cpp index 4aebb789..91ac44fe 100644 --- a/src/liberty/math/Vector.cpp +++ b/src/liberty/math/Vector.cpp @@ -27,23 +27,17 @@ CrossProduct(const CVector &v1, const CVector &v2) CVector Multiply3x3(const CMatrix &mat, const CVector &vec) { -#ifdef DC_SH4 - register float __x __asm__("fr12") = vec.x; - register float __y __asm__("fr13") = vec.y; - register float __z __asm__("fr14") = vec.z; - register float __w __asm__("fr15") = 0.0f; - - mat_load(reinterpret_cast(const_cast(&mat))); - - asm volatile( "ftrv xmtrx, fv12\n" - : "=f" (__x), "=f" (__y), "=f" (__z), "=f" (__w) - : "0" (__x), "1" (__y), "2" (__z), "3" (__w) ); - return { __x, __y, __z }; -#else +#ifndef DC_SH4 // TODO: VU0 code return CVector(mat.rx * vec.x + mat.fx * vec.y + mat.ux * vec.z, mat.ry * vec.x + mat.fy * vec.y + mat.uy * vec.z, mat.rz * vec.x + mat.fz * vec.y + mat.uz * vec.z); +#else + CVector out; + mat_load(mat); + mat_trans_normal3_nomod(vec.x, vec.y, vec.z, + out.x, out.y, out.z); + return out; #endif } @@ -58,8 +52,8 @@ Multiply3x3(const CVector &vec, const CMatrix &mat) CVector out; mat_load(mat); mat_transpose(); - mat_trans_vec3_nomod(vec.x, vec.y, vec.z, - out.x, out.y, out.z); + mat_trans_normal3_nomod(vec.x, vec.y, vec.z, + out.x, out.y, out.z); return out; #endif } diff --git a/src/liberty/math/Vector.h b/src/liberty/math/Vector.h index c0996510..1501512d 100644 --- a/src/liberty/math/Vector.h +++ b/src/liberty/math/Vector.h @@ -68,7 +68,7 @@ public: } const CVector &operator/=(float right) { - right = Invert(right); + right = Invert(right); x *= right; y *= right; z *= right; @@ -112,7 +112,8 @@ inline CVector operator*(float left, const CVector &right) inline CVector operator/(const CVector &left, float right) { - return CVector(left.x / right, left.y / right, left.z / right); + right = Invert(right); + return CVector(left.x * right, left.y * right, left.z * right); } __always_inline float