瀏覽代碼

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

Nathan Sweet 2 年之前
父節點
當前提交
3fd5ed2287
共有 1 個文件被更改,包括 3 次插入3 次删除
  1. 3 3
      spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/IkConstraint.java

+ 3 - 3
spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/IkConstraint.java

@@ -186,7 +186,7 @@ public class IkConstraint implements Updatable {
 			ty = targetY - bone.worldY;
 			ty = targetY - bone.worldY;
 			break;
 			break;
 		case noRotationOrReflection:
 		case noRotationOrReflection:
-			float s = Math.abs(pa * pd - pb * pc) / (pa * pa + pc * pc);
+			float s = Math.abs(pa * pd - pb * pc) / Math.max(0.0001f, pa * pa + pc * pc);
 			float sa = pa / bone.skeleton.scaleX;
 			float sa = pa / bone.skeleton.scaleX;
 			float sc = pc / bone.skeleton.scaleY;
 			float sc = pc / bone.skeleton.scaleY;
 			pb = -sc * s * bone.skeleton.scaleX;
 			pb = -sc * s * bone.skeleton.scaleX;
@@ -195,7 +195,7 @@ public class IkConstraint implements Updatable {
 			// Fall through.
 			// Fall through.
 		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 = Math.max(0.0001f, pa * pd - pb * pc);
 			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;
 		}
 		}
@@ -264,7 +264,7 @@ public class IkConstraint implements Updatable {
 		b = pp.b;
 		b = pp.b;
 		c = pp.c;
 		c = pp.c;
 		d = pp.d;
 		d = pp.d;
-		float id = 1 / (a * d - b * c), x = cwx - pp.worldX, y = cwy - pp.worldY;
+		float id = 1 / Math.max(0.0001f, a * d - b * c), x = cwx - pp.worldX, y = cwy - pp.worldY;
 		float dx = (x * d - y * b) * id - px, dy = (y * a - x * c) * id - py;
 		float dx = (x * d - y * b) * id - px, dy = (y * a - x * c) * id - py;
 		float l1 = (float)Math.sqrt(dx * dx + dy * dy), l2 = child.data.length * csx, a1, a2;
 		float l1 = (float)Math.sqrt(dx * dx + dy * dy), l2 = child.data.length * csx, a1, a2;
 		if (l1 < 0.0001f) {
 		if (l1 < 0.0001f) {