diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Bone.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Bone.java index 7a5ad5418..ad7da5ecd 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Bone.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Bone.java @@ -611,10 +611,11 @@ public class Bone implements Updatable { public void rotateWorld (float degrees) { degrees *= degRad; float sin = sin(degrees), cos = cos(degrees); - a = cos * a - sin * c; - b = cos * b - sin * d; - c = sin * a + cos * c; - d = sin * b + cos * d; + float ra = a, rb = b; + a = cos * ra - sin * c; + b = cos * rb - sin * d; + c = sin * ra + cos * c; + d = sin * rb + cos * d; } // --- diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PathConstraint.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PathConstraint.java index 4576d19b8..fbb94d149 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PathConstraint.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PathConstraint.java @@ -47,8 +47,8 @@ import com.esotericsoftware.spine.attachments.PathAttachment; *

* See Path constraints in the Spine User Guide. */ public class PathConstraint implements Updatable { - static private final int NONE = -1, BEFORE = -2, AFTER = -3; - static private final float epsilon = 0.00001f; + static final int NONE = -1, BEFORE = -2, AFTER = -3; + static final float epsilon = 0.00001f; final PathConstraintData data; final Array bones; @@ -122,12 +122,8 @@ public class PathConstraint implements Updatable { for (int i = 0, n = spacesCount - 1; i < n; i++) { Bone bone = (Bone)bones[i]; float setupLength = bone.data.length; - if (setupLength < epsilon) - lengths[i] = 0; - else { - float x = setupLength * bone.a, y = setupLength * bone.c; - lengths[i] = (float)Math.sqrt(x * x + y * y); - } + float x = setupLength * bone.a, y = setupLength * bone.c; + lengths[i] = (float)Math.sqrt(x * x + y * y); } } Arrays.fill(spaces, 1, spacesCount, spacing); 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 2afd10827..885bba8f5 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PhysicsConstraint.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PhysicsConstraint.java @@ -42,7 +42,8 @@ import com.esotericsoftware.spine.PhysicsConstraintData.SpringData; *

* See Physics constraints in the Spine User Guide. */ public class PhysicsConstraint implements Updatable { - static final Vector2 temp = new Vector2(); + static private final Vector2 temp = new Vector2(); + static private final float epsilon = 0.00001f; final PhysicsConstraintData data; final Array nodes; @@ -153,6 +154,13 @@ public class PhysicsConstraint implements Updatable { if (mix == 1) { for (int i = 0; i < nodeCount; i++) { Node node = (Node)nodes[i]; + + // BOZO + if (node.parentBone != null) { + node.parentBone.rotateWorld(node.offset); + node.parentBone.updateAppliedTransform(); + } + Object[] bones = node.bones; for (int ii = 0, nn = bones.length; ii < nn; ii++) { Bone bone = (Bone)bones[ii]; @@ -267,6 +275,9 @@ public class PhysicsConstraint implements Updatable { public float massInverse, vx, vy; + public boolean reset; + public float offset, velocity, wx, wy; + Node (NodeData data) { // Editor. this.data = data; } @@ -299,9 +310,48 @@ public class PhysicsConstraint implements Updatable { y = data.y; vx = 0; vy = 0; + + offset = 0; + velocity = 0; + reset = true; } public void step (PhysicsConstraint constraint) { + // BOZO + if (parentBone != null) { + float strength = 0.1f; + float damping = 0.9f; + float wind = 0; + float gravity = 0;// -0.0048f; + float mass = 4; + + float length = parentBone.data.length, x = length * parentBone.a, y = length * parentBone.c; + length = (float)Math.sqrt(x * x + y * y); + + float r = atan2(parentBone.c, parentBone.a) - offset * degRad; + float cos = (float)Math.cos(r), sin = (float)Math.sin(r); + { + float tx = parentBone.worldX + length * cos, ty = parentBone.worldY + length * sin; + if (reset) + reset = false; + else { + if (wx - tx != 0 || wy - ty != 0) { + float diff = new Vector2(length, 0).rotateRad(r).add(wx - parentBone.worldX, wy - parentBone.worldY) + .angleRad() - r; + offset += diff * radDeg; + } + } + wx = tx; + wy = ty; + } + + velocity += ((((offset % 360) + 540) % 360) - 180) * strength / mass; + r += offset * degRad; + velocity += (length * sin * wind - length * cos * gravity) * mass; + offset -= velocity; + velocity *= damping; + } + if (parentBone != null) return; x += vx; y += vy; diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Skeleton.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Skeleton.java index f67bcf8e4..cdbacc982 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Skeleton.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Skeleton.java @@ -347,35 +347,40 @@ public class Skeleton { int nodeCount = constraint.nodes.size; for (int i = 0; i < nodeCount; i++) { Node node = (Node)nodes[i]; - if (node.parentBone != null) sortBone(node.parentBone); - for (Bone bone : node.bones) - sortBone(bone); + sortBone(node.parentBone); +// for (Bone bone : node.bones) +// sortBone(bone); } updateCache.add(constraint); for (int i = 0; i < nodeCount; i++) { Node node = (Node)nodes[i]; - for (Bone bone : node.bones) - sortReset(bone.children); - } - for (int i = 0; i < nodeCount; i++) { - Node node = (Node)nodes[i]; - for (Bone bone : node.bones) - bone.sorted = true; + sortReset(node.parentBone.children); } - Object[] springs = constraint.springs.items; - for (int i = 0, n = constraint.springs.size; i < n; i++) { - Spring spring = (Spring)springs[i]; - if (spring.bone == null) continue; - sortBone(spring.bone); - updateCache.add(spring); - sortReset(spring.bone.children); - spring.bone.sorted = true; - for (Bone child : spring.bone.children) - sortBone(child); - } +// for (int i = 0; i < nodeCount; i++) { +// Node node = (Node)nodes[i]; +// for (Bone bone : node.bones) +// sortReset(bone.children); +// } +// for (int i = 0; i < nodeCount; i++) { +// Node node = (Node)nodes[i]; +// for (Bone bone : node.bones) +// bone.sorted = true; +// } +// +// Object[] springs = constraint.springs.items; +// for (int i = 0, n = constraint.springs.size; i < n; i++) { +// Spring spring = (Spring)springs[i]; +// if (spring.bone == null) continue; +// sortBone(spring.bone); +// updateCache.add(spring); +// sortReset(spring.bone.children); +// spring.bone.sorted = true; +// for (Bone child : spring.bone.children) +// sortBone(child); +// } } private void sortBone (Bone bone) {