From 9e88189238b62dc4f6e3e01fb2c65b31404c16d0 Mon Sep 17 00:00:00 2001 From: ragnarok-clanker Date: Wed, 28 Oct 2026 19:44:33 +0000 Subject: [PATCH] Decompile fn_19766 (CalculateVectorAngle) Batch #1612 by eAthena: 0 byte-identical, 1 confirmed by peer review. - fn_19766 CalculateVectorAngle: logic confirmed by peer review Reviewed-by: ragnarok-clanker --- Source/Contents/Effects/EffectPrimitiveState.cpp | 15 +++++++++++++++ Source/Contents/Effects/EffectPrimitiveState.h | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Source/Contents/Effects/EffectPrimitiveState.cpp b/Source/Contents/Effects/EffectPrimitiveState.cpp index 0330d01..d8f412c 100644 --- a/Source/Contents/Effects/EffectPrimitiveState.cpp +++ b/Source/Contents/Effects/EffectPrimitiveState.cpp @@ -179,6 +179,21 @@ void EffectPrimitiveState::GetColorOverride(unsigned char* red, unsigned char* g } // OFFSET: 0x00BAE4B0 +// FUNCTION: fn_19766 +void __stdcall CalculateVectorAngle(float x, float y, std::int16_t* angle) { + const float length = SquareRoot(x * x + y * y); + const float normalY = y / length; + const float normalX = x / length; + + for (std::int16_t index = 0; index <= 180; ++index) { + if (normalX >= ClientCosine(index)) { + *angle = normalY < 0.0f ? 360 - index : index; + return; + } + } + + *angle = 180; +} // OFFSET: 0x00BAE5D0 // FUNCTION: fn_19767 diff --git a/Source/Contents/Effects/EffectPrimitiveState.h b/Source/Contents/Effects/EffectPrimitiveState.h index 336cc4b..a3b8c52 100644 --- a/Source/Contents/Effects/EffectPrimitiveState.h +++ b/Source/Contents/Effects/EffectPrimitiveState.h @@ -175,7 +175,7 @@ struct EffectPrimitiveObject { bool AdvanceFrame(); }; -void CalculateVectorAngle(float x, float y, std::int16_t* angle); +void __stdcall CalculateVectorAngle(float x, float y, std::int16_t* angle); static_assert(sizeof(EffectVector3) == 12); static_assert(sizeof(EffectPrimitiveRecord) == 140);