[libgdx] Avoid a sqrt for 1 bone IK with stretch/compress.

This commit is contained in:
Nathan Sweet 2022-10-18 14:34:43 -04:00
parent c6f8b943b1
commit e9d576185c

View File

@ -222,11 +222,14 @@ public class IkConstraint implements Updatable {
tx = targetX - bone.worldX;
ty = targetY - bone.worldY;
}
float b = bone.data.length * sx, dd = (float)Math.sqrt(tx * tx + ty * ty);
if ((compress && dd < b) || (stretch && dd > b) && b > 0.0001f) {
float s = (dd / b - 1) * alpha + 1;
sx *= s;
if (uniform) sy *= s;
float b = bone.data.length * sx;
if (b > 0.0001f) {
float dd = tx * tx + ty * ty;
if ((compress && dd < b * b) || (stretch && dd > b * b)) {
float s = ((float)Math.sqrt(dd) / b - 1) * alpha + 1;
sx *= s;
if (uniform) sy *= s;
}
}
}
bone.updateWorldTransform(bone.ax, bone.ay, bone.arotation + rotationIK * alpha, sx, sy, bone.ashearX, bone.ashearY);