From 3ea4f66642f9a82eece1f0e9c10b273373306ded Mon Sep 17 00:00:00 2001 From: Nathan Sweet Date: Wed, 5 Oct 2022 22:27:53 -0400 Subject: [PATCH] [libgdx] AnimationState, fixed rotation mix when direction changes. closes #2158 --- .../spine/AnimationState.java | 22 +++++++++++-------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/AnimationState.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/AnimationState.java index a7d9e52cf..74ff0bd0a 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/AnimationState.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/AnimationState.java @@ -441,17 +441,21 @@ public class AnimationState { lastTotal = 0; lastDiff = diff; } else { - lastTotal = timelinesRotation[i]; // Angle and direction of mix, including loops. - lastDiff = timelinesRotation[i + 1]; // Difference between bones. + lastTotal = timelinesRotation[i]; + lastDiff = timelinesRotation[i + 1]; } - boolean current = diff > 0, dir = lastTotal >= 0; - // Detect cross at 0 (not 180). - if (Math.signum(lastDiff) != Math.signum(diff) && Math.abs(lastDiff) <= 90) { - // A cross after a 360 rotation is a loop. - if (Math.abs(lastTotal) > 180) lastTotal += 360 * Math.signum(lastTotal); - dir = current; + float loops = lastTotal - lastTotal % 360; + total = diff + loops; + boolean current = diff >= 0, dir = lastTotal >= 0; + if (Math.abs(lastDiff) <= 90 && Math.signum(lastDiff) != Math.signum(diff)) { + if (Math.abs(lastTotal - loops) > 180) { + total += 360 * Math.signum(lastTotal); + dir = current; + } else if (loops != 0) + total -= 360 * Math.signum(lastTotal); + else + dir = current; } - total = diff + lastTotal - lastTotal % 360; // Store loops as part of lastTotal. if (dir != current) total += 360 * Math.signum(lastTotal); timelinesRotation[i] = total; }