[csharp] port of bugfix commit 5cab7e9: Fixed 1-bone IK for transform mode noRotationOrReflection when skeleton scale is applied.

This commit is contained in:
Harald Csaszar 2020-06-03 16:35:26 +02:00
parent c54745cbc7
commit 85dd60bf57

View File

@ -170,18 +170,16 @@ namespace Spine {
ty = targetY - bone.worldY; ty = targetY - bone.worldY;
break; break;
case TransformMode.NoRotationOrReflection: { case TransformMode.NoRotationOrReflection: {
rotationIK += (float)Math.Atan2(pc, pa) * MathUtils.RadDeg; float s = Math.Abs(pa * pd - pb * pc) / (pa * pa + pc * pc);
float ps = Math.Abs(pa * pd - pb * pc) / (pa * pa + pc * pc); float sa = pa / bone.skeleton.ScaleX;
pb = -pc * ps; float sc = pc / bone.skeleton.ScaleY;
pd = pa * ps; pb = -sc * s * bone.skeleton.ScaleX;
float x = targetX - p.worldX, y = targetY - p.worldY; pd = sa * s * bone.skeleton.ScaleY;
float d = pa * pd - pb * pc; rotationIK += (float)Math.Atan2(pc, pa) * MathUtils.RadDeg;
tx = (x * pd - y * pb) / d - bone.ax; goto default; // Fall through.
ty = (y * pa - x * pc) / d - bone.ay;
break;
} }
default: { default: {
float x = targetX - p.worldX, y = targetY - p.worldY; float x = targetX - p.worldX, y = targetY - p.worldY;
float d = pa * pd - pb * pc; float d = pa * pd - pb * pc;
tx = (x * pd - y * pb) / d - bone.ax; tx = (x * pd - y * pb) / d - bone.ax;
ty = (y * pa - x * pc) / d - bone.ay; ty = (y * pa - x * pc) / d - bone.ay;