mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-03-25 22:23:42 +08:00
[c][cpp] Fixed IK constraint NaN when a parent bone has zero scale.
This commit is contained in:
parent
bc8fc3906d
commit
2b5bedd543
@ -181,7 +181,7 @@ void spIkConstraint_apply2(spBone *parent, spBone *child, float targetX, float t
|
|||||||
d = pp->d;
|
d = pp->d;
|
||||||
id = a * d - b * c;
|
id = a * d - b * c;
|
||||||
if (id > 0) id = 1 / MAX(0.0001f, id);
|
if (id > 0) id = 1 / MAX(0.0001f, id);
|
||||||
else id = 1 / MIN(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;
|
||||||
|
|||||||
@ -51,7 +51,7 @@ void IkConstraint::apply(Bone &bone, float targetX, float targetY, bool compress
|
|||||||
ty = targetY - bone._worldY;
|
ty = targetY - bone._worldY;
|
||||||
break;
|
break;
|
||||||
case TransformMode_NoRotationOrReflection: {
|
case TransformMode_NoRotationOrReflection: {
|
||||||
float s = MathUtil::abs(pa * pd - pb * pc) / (pa * pa + pc * pc);
|
float s = MathUtil::abs(pa * pd - pb * pc) / MathUtil::max(0.0001f, pa * pa + pc * pc);
|
||||||
float sa = pa / bone._skeleton.getScaleX();
|
float sa = pa / bone._skeleton.getScaleX();
|
||||||
float sc = pc / bone._skeleton.getScaleY();
|
float sc = pc / bone._skeleton.getScaleY();
|
||||||
pb = -sc * s * bone._skeleton.getScaleX();
|
pb = -sc * s * bone._skeleton.getScaleX();
|
||||||
@ -61,6 +61,8 @@ void IkConstraint::apply(Bone &bone, float targetX, float targetY, bool compress
|
|||||||
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 = MathUtil::max(0.0001f, d);
|
||||||
|
d = MathUtil::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;
|
||||||
}
|
}
|
||||||
@ -140,8 +142,10 @@ void IkConstraint::apply(Bone &parent, Bone &child, float targetX, float targetY
|
|||||||
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;
|
||||||
x = cwx - pp->_worldX;
|
if (id > 0) MathUtil::max(0.0001f, id);
|
||||||
|
else MathUtil::min(-0.0001f, id);
|
||||||
|
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;
|
||||||
dy = (y * a - x * c) * id - py;
|
dy = (y * a - x * c) * id - py;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user