From 37f332d1493d4fb114da282f3acec9ecdb95c129 Mon Sep 17 00:00:00 2001 From: NathanSweet Date: Wed, 24 Sep 2014 15:37:12 +0200 Subject: [PATCH] Fixed IK constraint bend direction keys. --- spine-c/src/spine/Animation.c | 7 ++++--- spine-csharp/src/Animation.cs | 7 ++++--- .../src/com/esotericsoftware/spine/Animation.java | 15 ++++++++------- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/spine-c/src/spine/Animation.c b/spine-c/src/spine/Animation.c index b246e8c07..1bb9a3ba4 100644 --- a/spine-c/src/spine/Animation.c +++ b/spine-c/src/spine/Animation.c @@ -746,8 +746,9 @@ void spFFDTimeline_setFrame (spFFDTimeline* self, int frameIndex, float time, fl /**/ static const int IKCONSTRAINT_PREV_FRAME_TIME = -3; +static const int IKCONSTRAINT_PREV_FRAME_MIX = -2; +static const int IKCONSTRAINT_PREV_FRAME_BEND_DIRECTION = -1; static const int IKCONSTRAINT_FRAME_MIX = 1; -static const int IKCONSTRAINT_FRAME_BEND_DIRECTION = 2; void _spIkConstraintTimeline_apply (const spTimeline* timeline, spSkeleton* skeleton, float lastTime, float time, spEvent** firedEvents, int* eventsCount, float alpha) { @@ -768,14 +769,14 @@ void _spIkConstraintTimeline_apply (const spTimeline* timeline, spSkeleton* skel /* Interpolate between the previous frame and the current frame. */ frameIndex = binarySearch(self->frames, self->framesCount, time, 3); - prevFrameMix = self->frames[frameIndex - 2]; + prevFrameMix = self->frames[frameIndex + IKCONSTRAINT_PREV_FRAME_MIX]; frameTime = self->frames[frameIndex]; percent = 1 - (time - frameTime) / (self->frames[frameIndex + IKCONSTRAINT_PREV_FRAME_TIME] - frameTime); percent = spCurveTimeline_getCurvePercent(SUPER(self), frameIndex / 3 - 1, percent < 0 ? 0 : (percent > 1 ? 1 : percent)); mix = prevFrameMix + (self->frames[frameIndex + IKCONSTRAINT_FRAME_MIX] - prevFrameMix) * percent; ikConstraint->mix += (mix - ikConstraint->mix) * alpha; - ikConstraint->bendDirection = (int)self->frames[frameIndex + IKCONSTRAINT_FRAME_BEND_DIRECTION]; + ikConstraint->bendDirection = (int)self->frames[frameIndex + IKCONSTRAINT_PREV_FRAME_BEND_DIRECTION]; } spIkConstraintTimeline* spIkConstraintTimeline_create (int framesCount) { diff --git a/spine-csharp/src/Animation.cs b/spine-csharp/src/Animation.cs index b11df2ac2..57f878bff 100644 --- a/spine-csharp/src/Animation.cs +++ b/spine-csharp/src/Animation.cs @@ -622,8 +622,9 @@ namespace Spine { public class IkConstraintTimeline : CurveTimeline { private const int PREV_FRAME_TIME = -3; + private const int PREV_FRAME_MIX = -2; + private const int PREV_FRAME_BEND_DIRECTION = -1; private const int FRAME_MIX = 1; - private const int FRAME_BEND_DIRECTION = 2; internal int ikConstraintIndex; internal float[] frames; @@ -662,14 +663,14 @@ namespace Spine { // Interpolate between the previous frame and the current frame. int frameIndex = Animation.binarySearch(frames, time, 3); - float prevFrameMix = frames[frameIndex - 2]; + float prevFrameMix = frames[frameIndex + PREV_FRAME_MIX]; float frameTime = frames[frameIndex]; float percent = 1 - (time - frameTime) / (frames[frameIndex + PREV_FRAME_TIME] - frameTime); percent = GetCurvePercent(frameIndex / 3 - 1, percent < 0 ? 0 : (percent > 1 ? 1 : percent)); float mix = prevFrameMix + (frames[frameIndex + FRAME_MIX] - prevFrameMix) * percent; ikConstraint.mix += (mix - ikConstraint.mix) * alpha; - ikConstraint.bendDirection = (int)frames[frameIndex + FRAME_BEND_DIRECTION]; + ikConstraint.bendDirection = (int)frames[frameIndex + PREV_FRAME_BEND_DIRECTION]; } } } diff --git a/spine-libgdx/src/com/esotericsoftware/spine/Animation.java b/spine-libgdx/src/com/esotericsoftware/spine/Animation.java index 1cc57a1ea..918917ede 100644 --- a/spine-libgdx/src/com/esotericsoftware/spine/Animation.java +++ b/spine-libgdx/src/com/esotericsoftware/spine/Animation.java @@ -373,8 +373,8 @@ public class Animation { Bone bone = skeleton.bones.get(boneIndex); if (time >= frames[frames.length - 3]) { // Time is after last frame. - bone.scaleX += (bone.data.scaleX - 1 + frames[frames.length - 2] - bone.scaleX) * alpha; - bone.scaleY += (bone.data.scaleY - 1 + frames[frames.length - 1] - bone.scaleY) * alpha; + bone.scaleX += (bone.data.scaleX * frames[frames.length - 2] - bone.scaleX) * alpha; + bone.scaleY += (bone.data.scaleY * frames[frames.length - 1] - bone.scaleY) * alpha; return; } @@ -386,9 +386,9 @@ public class Animation { float percent = MathUtils.clamp(1 - (time - frameTime) / (frames[frameIndex + PREV_FRAME_TIME] - frameTime), 0, 1); percent = getCurvePercent(frameIndex / 3 - 1, percent); - bone.scaleX += (bone.data.scaleX - 1 + prevFrameX + (frames[frameIndex + FRAME_X] - prevFrameX) * percent - bone.scaleX) + bone.scaleX += (bone.data.scaleX * (prevFrameX + (frames[frameIndex + FRAME_X] - prevFrameX) * percent) - bone.scaleX) * alpha; - bone.scaleY += (bone.data.scaleY - 1 + prevFrameY + (frames[frameIndex + FRAME_Y] - prevFrameY) * percent - bone.scaleY) + bone.scaleY += (bone.data.scaleY * (prevFrameY + (frames[frameIndex + FRAME_Y] - prevFrameY) * percent) - bone.scaleY) * alpha; } } @@ -719,8 +719,9 @@ public class Animation { static public class IkConstraintTimeline extends CurveTimeline { static private final int PREV_FRAME_TIME = -3; + static private final int PREV_FRAME_MIX = -2; + static private final int PREV_FRAME_BEND_DIRECTION = -1; static private final int FRAME_MIX = 1; - static private final int FRAME_BEND_DIRECTION = 2; int ikConstraintIndex; private final float[] frames; // time, mix, bendDirection, ... @@ -764,14 +765,14 @@ public class Animation { // Interpolate between the previous frame and the current frame. int frameIndex = binarySearch(frames, time, 3); - float prevFrameMix = frames[frameIndex - 2]; + float prevFrameMix = frames[frameIndex + PREV_FRAME_MIX]; float frameTime = frames[frameIndex]; float percent = MathUtils.clamp(1 - (time - frameTime) / (frames[frameIndex + PREV_FRAME_TIME] - frameTime), 0, 1); percent = getCurvePercent(frameIndex / 3 - 1, percent); float mix = prevFrameMix + (frames[frameIndex + FRAME_MIX] - prevFrameMix) * percent; ikConstraint.mix += (mix - ikConstraint.mix) * alpha; - ikConstraint.bendDirection = (int)frames[frameIndex + FRAME_BEND_DIRECTION]; + ikConstraint.bendDirection = (int)frames[frameIndex + PREV_FRAME_BEND_DIRECTION]; } }