Эх сурвалжийг харах

[csharp] Port of commit 3ea4f66. AnimationState, fixed rotation mix when direction changes. See #2158.

Harald Csaszar 2 жил өмнө
parent
commit
6cdbe81d49

+ 13 - 9
spine-csharp/src/AnimationState.cs

@@ -553,17 +553,21 @@ namespace Spine {
 					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];
 				}
-				bool current = diff > 0, dir = lastTotal >= 0;
-				// Detect cross at 0 (not 180).
-				if (Math.Sign(lastDiff) != Math.Sign(diff) && Math.Abs(lastDiff) <= 90) {
-					// A cross after a 360 rotation is a loop.
-					if (Math.Abs(lastTotal) > 180) lastTotal += 360 * Math.Sign(lastTotal);
-					dir = current;
+				float loops = lastTotal - lastTotal % 360;
+				total = diff + loops;
+				bool current = diff >= 0, dir = lastTotal >= 0;
+				if (Math.Abs(lastDiff) <= 90 && Math.Sign(lastDiff) != Math.Sign(diff)) {
+					if (Math.Abs(lastTotal - loops) > 180) {
+						total += 360 * Math.Sign(lastTotal);
+						dir = current;
+					} else if (loops != 0)
+						total -= 360 * Math.Sign(lastTotal);
+					else
+						dir = current;
 				}
-				total = diff + lastTotal - lastTotal % 360; // Store loops as part of lastTotal.
 				if (dir != current) total += 360 * Math.Sign(lastTotal);
 				timelinesRotation[i] = total;
 			}