[libgdx] Better way to reset rotation direction on first frame.

This commit is contained in:
NathanSweet 2016-11-28 18:10:44 +01:00
parent fdd66af5e0
commit 6af978871b

View File

@ -239,6 +239,9 @@ public class AnimationState {
private void applyRotateTimeline (Timeline timeline, Skeleton skeleton, float time, float alpha, boolean setupPose, private void applyRotateTimeline (Timeline timeline, Skeleton skeleton, float time, float alpha, boolean setupPose,
float[] timelinesRotation, int i, boolean firstFrame) { float[] timelinesRotation, int i, boolean firstFrame) {
if (firstFrame) timelinesRotation[i] = 0;
if (alpha == 1) { if (alpha == 1) {
timeline.apply(skeleton, 0, time, null, 1, setupPose, false); timeline.apply(skeleton, 0, time, null, 1, setupPose, false);
return; return;
@ -272,13 +275,9 @@ public class AnimationState {
// Mix between rotations using the direction of the shortest route on the first frame while detecting crosses. // Mix between rotations using the direction of the shortest route on the first frame while detecting crosses.
float r1 = setupPose ? bone.data.rotation : bone.rotation; float r1 = setupPose ? bone.data.rotation : bone.rotation;
float total, diff = r2 - r1; float total, diff = r2 - r1;
if (diff == 0) { if (diff == 0)
if (firstFrame) { total = timelinesRotation[i];
timelinesRotation[i] = 0; else {
total = 0;
} else
total = timelinesRotation[i];
} else {
diff -= (16384 - (int)(16384.499999999996 - diff / 360)) * 360; diff -= (16384 - (int)(16384.499999999996 - diff / 360)) * 360;
float lastTotal, lastDiff; float lastTotal, lastDiff;
if (firstFrame) { if (firstFrame) {