[c] Fixed IK constraint NaN when a parent bone has zero scale.

This commit is contained in:
Mario Zechner 2023-04-05 15:30:10 +02:00
parent db90982453
commit 6f63f76600

View File

@ -84,7 +84,7 @@ void spIkConstraint_apply1(spBone *bone, float targetX, float targetY, int /*boo
ty = targetY - bone->worldY;
break;
case SP_TRANSFORMMODE_NOROTATIONORREFLECTION: {
s = ABS(pa * pd - pb * pc) / (pa * pa + pc * pc);
s = ABS(pa * pd - pb * pc) / MAX(0.0001f, pa * pa + pc * pc);
sa = pa / bone->skeleton->scaleX;
sc = pc / bone->skeleton->scaleY;
pb = -sc * s * bone->skeleton->scaleX;
@ -94,6 +94,8 @@ void spIkConstraint_apply1(spBone *bone, float targetX, float targetY, int /*boo
default: {
float x = targetX - p->worldX, y = targetY - p->worldY;
float d = pa * pd - pb * pc;
if (d > 0) d = MAX(0.0001f, d);
else d = MIN(-0.0001f, d);
tx = (x * pd - y * pb) / d - bone->ax;
ty = (y * pa - x * pc) / d - bone->ay;
}
@ -177,7 +179,9 @@ void spIkConstraint_apply2(spBone *parent, spBone *child, float targetX, float t
b = pp->b;
c = pp->c;
d = pp->d;
id = 1 / (a * d - b * c);
id = a * d - b * c;
if (id > 0) id = 1 / MAX(0.0001f, id);
else id = 1 / MIN(0.0001f, id);
x = cwx - pp->worldX;
y = cwy - pp->worldY;
dx = (x * d - y * b) * id - px;