[libgdx] AnimationState, fixed rotation mix when direction changes.

closes #2158
This commit is contained in:
Nathan Sweet 2022-10-05 22:27:53 -04:00
parent 8583947368
commit 3ea4f66642

View File

@ -441,17 +441,21 @@ public class AnimationState {
lastTotal = 0; lastTotal = 0;
lastDiff = diff; lastDiff = diff;
} else { } else {
lastTotal = timelinesRotation[i]; // Angle and direction of mix, including loops. lastTotal = timelinesRotation[i];
lastDiff = timelinesRotation[i + 1]; // Difference between bones. lastDiff = timelinesRotation[i + 1];
} }
boolean current = diff > 0, dir = lastTotal >= 0; float loops = lastTotal - lastTotal % 360;
// Detect cross at 0 (not 180). total = diff + loops;
if (Math.signum(lastDiff) != Math.signum(diff) && Math.abs(lastDiff) <= 90) { boolean current = diff >= 0, dir = lastTotal >= 0;
// A cross after a 360 rotation is a loop. if (Math.abs(lastDiff) <= 90 && Math.signum(lastDiff) != Math.signum(diff)) {
if (Math.abs(lastTotal) > 180) lastTotal += 360 * Math.signum(lastTotal); if (Math.abs(lastTotal - loops) > 180) {
dir = current; 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); if (dir != current) total += 360 * Math.signum(lastTotal);
timelinesRotation[i] = total; timelinesRotation[i] = total;
} }