Fixed single bone IK with skeleton flipping.

This commit is contained in:
NathanSweet 2016-02-27 02:13:05 +01:00
parent ef0b4b4bb9
commit f9d3988ee5
3 changed files with 5 additions and 3 deletions

View File

@ -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);

View File

@ -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);

View File

@ -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;