[csharp] Fix of incorrect bugfix commit f5fb9b5a. Fixed IK constraint NaN when a parent bone has zero scale.

This commit is contained in:
Harald Csaszar 2023-04-05 15:42:26 +02:00
parent 6f63f76600
commit fb59ba45b3

View File

@ -182,7 +182,9 @@ namespace Spine {
} }
default: { default: {
float x = targetX - p.worldX, y = targetY - p.worldY; float x = targetX - p.worldX, y = targetY - p.worldY;
float d = Math.Max(0.0001f, pa * pd - pb * pc); float d = pa * pd - pb * pc;
if (d > 0) d = Math.Max(0.0001f, d);
else d = Math.Min(-0.0001f, d);
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;
break; break;
@ -256,7 +258,9 @@ namespace Spine {
b = pp.b; b = pp.b;
c = pp.c; c = pp.c;
d = pp.d; d = pp.d;
float id = 1 / Math.Max(0.0001f, a * d - b * c), x = cwx - pp.worldX, y = cwy - pp.worldY; float id = a * d - b * c, x = cwx - pp.worldX, y = cwy - pp.worldY;
if (id > 0) id = 1 / Math.Max(0.0001f, id);
else id = 1 / Math.Min(-0.0001f, id);
float dx = (x * d - y * b) * id - px, dy = (y * a - x * c) * id - py; float dx = (x * d - y * b) * id - px, dy = (y * a - x * c) * id - py;
float l1 = (float)Math.Sqrt(dx * dx + dy * dy), l2 = child.data.length * csx, a1, a2; float l1 = (float)Math.Sqrt(dx * dx + dy * dy), l2 = child.data.length * csx, a1, a2;
if (l1 < 0.0001f) { if (l1 < 0.0001f) {