From f9d3988ee5d708205abca8ab6ea3cdaa1bc7c784 Mon Sep 17 00:00:00 2001 From: NathanSweet Date: Sat, 27 Feb 2016 02:13:05 +0100 Subject: [PATCH] Fixed single bone IK with skeleton flipping. --- spine-c/src/spine/IkConstraint.c | 3 ++- spine-csharp/src/IkConstraint.cs | 3 ++- .../src/com/esotericsoftware/spine/IkConstraint.java | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/spine-c/src/spine/IkConstraint.c b/spine-c/src/spine/IkConstraint.c index 45672c273..298196630 100644 --- a/spine-c/src/spine/IkConstraint.c +++ b/spine-c/src/spine/IkConstraint.c @@ -72,7 +72,8 @@ void spIkConstraint_apply1 (spBone* bone, float targetX, float targetY, float al float parentRotation = !bone->parent ? 0 : spBone_getWorldRotationX(bone->parent); float rotation = bone->rotation; float rotationIK = ATAN2(targetY - bone->worldY, targetX - bone->worldX) * RAD_DEG - parentRotation; - if (bone->worldSignX != bone->worldSignY) rotationIK = 360 - rotationIK; + if ((bone->worldSignX != bone->worldSignY) != (bone->skeleton->flipX != (bone->skeleton->flipY != spBone_isYDown()))) + rotationIK = 360 - rotationIK; if (rotationIK > 180) rotationIK -= 360; else if (rotationIK < -180) rotationIK += 360; spBone_updateWorldTransformWith(bone, bone->x, bone->y, rotation + (rotationIK - rotation) * alpha, bone->scaleX, bone->scaleY); diff --git a/spine-csharp/src/IkConstraint.cs b/spine-csharp/src/IkConstraint.cs index d457ac563..4faf851f9 100644 --- a/spine-csharp/src/IkConstraint.cs +++ b/spine-csharp/src/IkConstraint.cs @@ -86,7 +86,8 @@ namespace Spine { float parentRotation = bone.parent == null ? 0 : bone.parent.WorldRotationX; float rotation = bone.rotation; float rotationIK = MathUtils.Atan2(targetY - bone.worldY, targetX - bone.worldX) * MathUtils.radDeg - parentRotation; - if (bone.worldSignX != bone.worldSignY) rotationIK = 360 - rotationIK; + if ((bone.worldSignX != bone.worldSignY) != (bone.skeleton.flipX != (bone.skeleton.flipY != Bone.yDown))) + rotationIK = 360 - rotationIK; if (rotationIK > 180) rotationIK -= 360; else if (rotationIK < -180) rotationIK += 360; bone.UpdateWorldTransform(bone.x, bone.y, rotation + (rotationIK - rotation) * alpha, bone.scaleX, bone.scaleY); diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/IkConstraint.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/IkConstraint.java index 46eecfa25..4cd5d28bd 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/IkConstraint.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/IkConstraint.java @@ -125,7 +125,7 @@ public class IkConstraint implements Updatable { float parentRotation = bone.parent == null ? 0 : bone.parent.getWorldRotationX(); float rotation = bone.rotation; float rotationIK = atan2(targetY - bone.worldY, targetX - bone.worldX) * radDeg - parentRotation; - if (bone.worldSignX != bone.worldSignY) rotationIK = 360 - rotationIK; + if ((bone.worldSignX != bone.worldSignY) != (bone.skeleton.flipX != bone.skeleton.flipY)) rotationIK = 360 - rotationIK; if (rotationIK > 180) rotationIK -= 360; else if (rotationIK < -180) rotationIK += 360;