From 9ed46c4ee124ebe633c5130b3c9352f550b5a2ec Mon Sep 17 00:00:00 2001 From: Nathan Sweet Date: Thu, 6 Oct 2022 09:16:51 -0400 Subject: [PATCH] [libgdx] PhysicsConstraint fixes, bone control. --- .../spine/PhysicsConstraint.java | 31 +++++++++++++++++-- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PhysicsConstraint.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PhysicsConstraint.java index e84cae0d7..d36ec884a 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PhysicsConstraint.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PhysicsConstraint.java @@ -48,7 +48,7 @@ public class PhysicsConstraint implements Updatable { boolean active; - private final Skeleton skeleton; + final Skeleton skeleton; float remaining, lastTime; final Vector2 temp = new Vector2(); @@ -133,15 +133,40 @@ public class PhysicsConstraint implements Updatable { Object[] springs = this.springs.items; int springCount = this.springs.size; - remaining += lastTime - skeleton.time; + remaining += Math.max(skeleton.time - lastTime, 0); lastTime = skeleton.time; - while (remaining > 0.016f) { + while (remaining >= 0.016f) { remaining -= 0.016f; for (int i = 0; i < springCount; i++) ((Spring)springs[i]).update(); for (int i = 0; i < nodeCount; i++) ((Node)nodes[i]).update(this); } + + for (int i = 0; i < nodeCount; i++) { + Node node = (Node)nodes[i]; + Object[] bones = node.bones; + int ii = 0, nn = bones.length; + if (mix == 1) { + for (; ii < nn; ii++) { + Bone bone = (Bone)bones[ii]; + bone.worldX = node.x; + bone.worldY = node.y; + bone.worldToLocal(temp.set(bone.worldX, bone.worldY)); + bone.ax = temp.x; + bone.ay = temp.y; + } + } else { + for (; ii < nn; ii++) { + Bone bone = (Bone)bones[ii]; + bone.worldX = bone.worldX + (node.x - bone.worldX) * mix; + bone.worldY = bone.worldY + (node.y - bone.worldY) * mix; + bone.worldToLocal(temp.set(bone.worldX, bone.worldY)); + bone.ax = temp.x; + bone.ay = temp.y; + } + } + } } public Array getNodes () {