From 42e2b60018e1ef044b2b6937cacbe0b1e559eba4 Mon Sep 17 00:00:00 2001 From: ragnarok-clanker Date: Tue, 10 Nov 2026 14:46:25 +0000 Subject: [PATCH] Decompile fn_01724 (ModelRotationTrack::Sample) Batch #16140 by youko: 0 byte-identical, 1 confirmed by peer review. - fn_01724 ModelRotationTrack::Sample: logic confirmed by peer review Peer-reviewed-by: ragnarok-clanker, Yommy, alisonrag Accepted without human review: peers confirmed the logic ("same" ahead by at least 3, with 70% of the votes). --- Source/Contents/Models/ModelAnimation.cpp | 52 ++++++++++++++--------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/Source/Contents/Models/ModelAnimation.cpp b/Source/Contents/Models/ModelAnimation.cpp index c6d949c48..8bb45d90f 100644 --- a/Source/Contents/Models/ModelAnimation.cpp +++ b/Source/Contents/Models/ModelAnimation.cpp @@ -234,6 +234,7 @@ void ModelRotationTrack::Sample(float frame, const matrix& base, matrix& output) if (static_cast(keys[next].frame) > frame) { if (next == 0) { a = MatrixQuaternion(base); + a.frame = 0; } else { a = keys[next - 1]; } @@ -243,14 +244,28 @@ void ModelRotationTrack::Sample(float frame, const matrix& base, matrix& output) } } - const float amount = b.frame != a.frame ? (frame - static_cast(a.frame)) / static_cast((b.frame - a.frame)) : 0.0f; - float dot = ((b.rotation[0] * a.rotation[0] + b.rotation[1] * a.rotation[1]) + b.rotation[2] * a.rotation[2]) + b.rotation[3] * a.rotation[3]; + float amount = 0.0f; + + if (b.frame != a.frame) { + amount = (frame - static_cast(a.frame)) / static_cast((b.frame - a.frame)); + } + + ModelRotationKey result{0, {0, 0, 0, 1}}; + float ax = a.rotation[0]; + float ay = a.rotation[1]; + float az = a.rotation[2]; + float aw = a.rotation[3]; + float bx = b.rotation[0]; + float by = b.rotation[1]; + float bz = b.rotation[2]; + float bw = b.rotation[3]; + float dot = ((bx * ax + by * ay) + bz * az) + bw * aw; if (dot < 0.0f) { - for (float& value : a.rotation) { - value = -value; - } - + ax = -ax; + ay = -ay; + az = -az; + aw = -aw; dot = -dot; } @@ -258,29 +273,28 @@ void ModelRotationTrack::Sample(float frame, const matrix& base, matrix& output) float secondWeight; if (dot > -0.95f) { - if (dot <= 0.95f) { + if (dot > 0.95f) { + firstWeight = 1.0f - amount; + secondWeight = amount; + } else { const float angle = static_cast(std::acos(static_cast(dot))); const float denominator = ClientSin(angle); firstWeight = ClientSin((1.0f - amount) * angle) / denominator; secondWeight = ClientSin(angle * amount) / denominator; - } else { - firstWeight = 1.0f - amount; - secondWeight = amount; } } else { - b.rotation[0] = -a.rotation[1]; - b.rotation[1] = a.rotation[0]; - b.rotation[2] = -a.rotation[3]; - b.rotation[3] = a.rotation[2]; + bx = -ay; + by = ax; + bz = -aw; + bw = az; firstWeight = ClientSin((0.5f - amount) * 3.141592f); secondWeight = ClientSin(amount * 3.141592f); } - ModelRotationKey result{0, {}}; - result.rotation[0] = b.rotation[0] * secondWeight + firstWeight * a.rotation[0]; - result.rotation[1] = b.rotation[1] * secondWeight + firstWeight * a.rotation[1]; - result.rotation[2] = b.rotation[2] * secondWeight + a.rotation[2] * firstWeight; - result.rotation[3] = b.rotation[3] * secondWeight + a.rotation[3] * firstWeight; + result.rotation[0] = bx * secondWeight + firstWeight * ax; + result.rotation[1] = by * secondWeight + firstWeight * ay; + result.rotation[2] = bz * secondWeight + az * firstWeight; + result.rotation[3] = bw * secondWeight + aw * firstWeight; QuaternionMatrix(result, rotation); }