mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 17:56:04 +08:00
[cpp] Bone length fix for stretchy IK.
This commit is contained in:
parent
4b66fffcd7
commit
b4d71f68c2
@ -54,8 +54,8 @@ void IkConstraint::apply(Bone &bone, float targetX, float targetY, bool stretch,
|
|||||||
else if (rotationIK < -180) rotationIK += 360;
|
else if (rotationIK < -180) rotationIK += 360;
|
||||||
float sx = bone._ascaleX;
|
float sx = bone._ascaleX;
|
||||||
if (stretch) {
|
if (stretch) {
|
||||||
float dd = MathUtil::sqrt(tx * tx + ty * ty);
|
float b = bone._data.getLength() * sx, dd = MathUtil::sqrt(tx * tx + ty * ty);
|
||||||
if (dd > bone._data.getLength() * sx) sx *= (dd / (bone._data.getLength() * sx) - 1) * alpha + 1;
|
if (dd > b && b > 0.0001f) sx *= (dd / b - 1) * alpha + 1;
|
||||||
}
|
}
|
||||||
bone.updateWorldTransform(bone._ax, bone._ay, bone._arotation + rotationIK * alpha, sx,
|
bone.updateWorldTransform(bone._ax, bone._ay, bone._arotation + rotationIK * alpha, sx,
|
||||||
bone._ascaleY, bone._ashearX, bone._ashearY);
|
bone._ascaleY, bone._ashearX, bone._ashearY);
|
||||||
@ -128,7 +128,7 @@ void IkConstraint::apply(Bone &parent, Bone &child, float targetX, float targetY
|
|||||||
if (cosine < -1) cosine = -1;
|
if (cosine < -1) cosine = -1;
|
||||||
else if (cosine > 1) {
|
else if (cosine > 1) {
|
||||||
cosine = 1;
|
cosine = 1;
|
||||||
if (stretch) sx *= (MathUtil::sqrt(dd) / (l1 + l2) - 1) * alpha + 1;
|
if (stretch && l1 + l2 > 0.0001f) sx *= (MathUtil::sqrt(dd) / (l1 + l2) - 1) * alpha + 1;
|
||||||
}
|
}
|
||||||
a2 = MathUtil::acos(cosine) * bendDir;
|
a2 = MathUtil::acos(cosine) * bendDir;
|
||||||
a = l1 + l2 * cosine;
|
a = l1 + l2 * cosine;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user