From cd7c1294454b9f8e18d1e595a3226f07367ea8ce Mon Sep 17 00:00:00 2001 From: ricardoofnl Date: Fri, 4 Sep 2026 22:27:13 +0700 Subject: [PATCH] [saco] Implement/match `VectorNormaliseTo`; casting the sum to `double` picks the `fsqrt` intrinsic instead of the float `sqrt` overload --- saco/game/util.cpp | 11 +++++++++++ saco/game/util.h | 1 + 2 files changed, 12 insertions(+) diff --git a/saco/game/util.cpp b/saco/game/util.cpp index 717c4ce..f6489d0 100644 --- a/saco/game/util.cpp +++ b/saco/game/util.cpp @@ -793,6 +793,17 @@ void VectorCrossProduct(VECTOR *vecOut, VECTOR *vec1, VECTOR *vec2) vecOut->Z = f1 - f2; } +//---------------------------------------------------- + +void VectorNormaliseTo(VECTOR *vecOut, VECTOR *vecIn) +{ + float fInv = 1.0f / (float)sqrt((double)(vecIn->X * vecIn->X + vecIn->Y * vecIn->Y + + vecIn->Z * vecIn->Z)); + + vecOut->X = fInv * vecIn->X; + vecOut->Y = fInv * vecIn->Y; + vecOut->Z = fInv * vecIn->Z; +} //---------------------------------------------------- diff --git a/saco/game/util.h b/saco/game/util.h index ce613f5..48f2bb8 100644 --- a/saco/game/util.h +++ b/saco/game/util.h @@ -101,6 +101,7 @@ const char* GetTaskNameFromTask(DWORD *task); int FUNC_100B4BC0(int a1, int a2, int a3); // .text:100B4BC0 float FastSqrt(float x); // .text:100B5A60 void VectorCrossProduct(VECTOR *vecOut, VECTOR *vec1, VECTOR *vec2); // .text:100B4C20 +void VectorNormaliseTo(VECTOR *vecOut, VECTOR *vecIn); // .text:100B4CC0 void FUNC_100B5210(int a1, void *a2); // .text:100B5210, __cdecl: the caller's // stack cleanup is folded into the next call's argument setup