mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 01:36:02 +08:00
[c] Fixed IK constraint NaN when a parent bone has zero scale.
This commit is contained in:
parent
db90982453
commit
6f63f76600
@ -84,7 +84,7 @@ void spIkConstraint_apply1(spBone *bone, float targetX, float targetY, int /*boo
|
|||||||
ty = targetY - bone->worldY;
|
ty = targetY - bone->worldY;
|
||||||
break;
|
break;
|
||||||
case SP_TRANSFORMMODE_NOROTATIONORREFLECTION: {
|
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;
|
sa = pa / bone->skeleton->scaleX;
|
||||||
sc = pc / bone->skeleton->scaleY;
|
sc = pc / bone->skeleton->scaleY;
|
||||||
pb = -sc * s * bone->skeleton->scaleX;
|
pb = -sc * s * bone->skeleton->scaleX;
|
||||||
@ -94,6 +94,8 @@ void spIkConstraint_apply1(spBone *bone, float targetX, float targetY, int /*boo
|
|||||||
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;
|
||||||
|
if (d > 0) d = MAX(0.0001f, d);
|
||||||
|
else d = 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;
|
||||||
}
|
}
|
||||||
@ -177,7 +179,9 @@ void spIkConstraint_apply2(spBone *parent, spBone *child, float targetX, float t
|
|||||||
b = pp->b;
|
b = pp->b;
|
||||||
c = pp->c;
|
c = pp->c;
|
||||||
d = pp->d;
|
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;
|
x = cwx - pp->worldX;
|
||||||
y = cwy - pp->worldY;
|
y = cwy - pp->worldY;
|
||||||
dx = (x * d - y * b) * id - px;
|
dx = (x * d - y * b) * id - px;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user