From 85a8c8327fd1819b683946d142e8350b6e18494e Mon Sep 17 00:00:00 2001 From: Caner Karaca Date: Thu, 8 Oct 2026 16:33:50 +0300 Subject: [PATCH] fix(wheelhub): eliminate rotational drift by reconstructing basis from fixed vertical reference --- src/features/wheelhub.cpp | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/src/features/wheelhub.cpp b/src/features/wheelhub.cpp index 5abe02ff..4618346a 100755 --- a/src/features/wheelhub.cpp +++ b/src/features/wheelhub.cpp @@ -34,21 +34,32 @@ void WheelHub::Init() WheelHubData& data = m_VehData.Get(pVeh); bool modified = false; - // Thanks to Ameer & SanVive team for their rotation fix + // Thanks to Ameer & SanVive team for their rotation fix (re-fixed to eliminate accumulated rotational drift) auto updateRotation = [&](RwFrame* ori, RwFrame* tar, bool isLeft) { - if (tar == nullptr) return; - if (ori == nullptr) return; + if (tar == nullptr || ori == nullptr) return; RwV3d rightVec = ori->modelling.right; if (isLeft) RwV3dNegate(&rightVec, &rightVec); + RwV3dNormalize(&rightVec, &rightVec); - MatrixUtil::ForceRightVector(&tar->modelling, rightVec); - RwV3dNegate(&tar->modelling.up, &tar->modelling.up); + const RwV3d refZ = {0.0f, 0.0f, 1.0f}; + RwV3d fwd; + RwV3dCrossProduct(&fwd, &refZ, &rightVec); + RwV3dNormalize(&fwd, &fwd); + + RwV3d up; + RwV3dCrossProduct(&up, &rightVec, &fwd); + RwV3dNormalize(&up, &up); + + tar->modelling.right = rightVec; + tar->modelling.up = fwd; + tar->modelling.at = up; tar->modelling.pos.z = ori->modelling.pos.z; - pVeh->UpdateRwFrame(); + RwMatrixUpdate(&tar->modelling); + modified = true; }; updateRotation(data.m_pWRF, data.m_pHRF, false);