This commit is contained in:
Nathan Sweet 2023-01-26 13:20:44 -04:00
parent d8f0e9e88d
commit 9ac1d77d32
4 changed files with 86 additions and 34 deletions

View File

@ -611,10 +611,11 @@ public class Bone implements Updatable {
public void rotateWorld (float degrees) { public void rotateWorld (float degrees) {
degrees *= degRad; degrees *= degRad;
float sin = sin(degrees), cos = cos(degrees); float sin = sin(degrees), cos = cos(degrees);
a = cos * a - sin * c; float ra = a, rb = b;
b = cos * b - sin * d; a = cos * ra - sin * c;
c = sin * a + cos * c; b = cos * rb - sin * d;
d = sin * b + cos * d; c = sin * ra + cos * c;
d = sin * rb + cos * d;
} }
// --- // ---

View File

@ -47,8 +47,8 @@ import com.esotericsoftware.spine.attachments.PathAttachment;
* <p> * <p>
* See <a href="http://esotericsoftware.com/spine-path-constraints">Path constraints</a> in the Spine User Guide. */ * See <a href="http://esotericsoftware.com/spine-path-constraints">Path constraints</a> in the Spine User Guide. */
public class PathConstraint implements Updatable { public class PathConstraint implements Updatable {
static private final int NONE = -1, BEFORE = -2, AFTER = -3; static final int NONE = -1, BEFORE = -2, AFTER = -3;
static private final float epsilon = 0.00001f; static final float epsilon = 0.00001f;
final PathConstraintData data; final PathConstraintData data;
final Array<Bone> bones; final Array<Bone> bones;
@ -122,12 +122,8 @@ public class PathConstraint implements Updatable {
for (int i = 0, n = spacesCount - 1; i < n; i++) { for (int i = 0, n = spacesCount - 1; i < n; i++) {
Bone bone = (Bone)bones[i]; Bone bone = (Bone)bones[i];
float setupLength = bone.data.length; float setupLength = bone.data.length;
if (setupLength < epsilon) float x = setupLength * bone.a, y = setupLength * bone.c;
lengths[i] = 0; lengths[i] = (float)Math.sqrt(x * x + y * y);
else {
float x = setupLength * bone.a, y = setupLength * bone.c;
lengths[i] = (float)Math.sqrt(x * x + y * y);
}
} }
} }
Arrays.fill(spaces, 1, spacesCount, spacing); Arrays.fill(spaces, 1, spacesCount, spacing);

View File

@ -42,7 +42,8 @@ import com.esotericsoftware.spine.PhysicsConstraintData.SpringData;
* <p> * <p>
* See <a href="http://esotericsoftware.com/spine-physics-constraints">Physics constraints</a> in the Spine User Guide. */ * See <a href="http://esotericsoftware.com/spine-physics-constraints">Physics constraints</a> in the Spine User Guide. */
public class PhysicsConstraint implements Updatable { 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 PhysicsConstraintData data;
final Array<Node> nodes; final Array<Node> nodes;
@ -153,6 +154,13 @@ public class PhysicsConstraint implements Updatable {
if (mix == 1) { if (mix == 1) {
for (int i = 0; i < nodeCount; i++) { for (int i = 0; i < nodeCount; i++) {
Node node = (Node)nodes[i]; Node node = (Node)nodes[i];
// BOZO
if (node.parentBone != null) {
node.parentBone.rotateWorld(node.offset);
node.parentBone.updateAppliedTransform();
}
Object[] bones = node.bones; Object[] bones = node.bones;
for (int ii = 0, nn = bones.length; ii < nn; ii++) { for (int ii = 0, nn = bones.length; ii < nn; ii++) {
Bone bone = (Bone)bones[ii]; Bone bone = (Bone)bones[ii];
@ -267,6 +275,9 @@ public class PhysicsConstraint implements Updatable {
public float massInverse, vx, vy; public float massInverse, vx, vy;
public boolean reset;
public float offset, velocity, wx, wy;
Node (NodeData data) { // Editor. Node (NodeData data) { // Editor.
this.data = data; this.data = data;
} }
@ -299,9 +310,48 @@ public class PhysicsConstraint implements Updatable {
y = data.y; y = data.y;
vx = 0; vx = 0;
vy = 0; vy = 0;
offset = 0;
velocity = 0;
reset = true;
} }
public void step (PhysicsConstraint constraint) { 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; if (parentBone != null) return;
x += vx; x += vx;
y += vy; y += vy;

View File

@ -347,35 +347,40 @@ public class Skeleton {
int nodeCount = constraint.nodes.size; int nodeCount = constraint.nodes.size;
for (int i = 0; i < nodeCount; i++) { for (int i = 0; i < nodeCount; i++) {
Node node = (Node)nodes[i]; Node node = (Node)nodes[i];
if (node.parentBone != null) sortBone(node.parentBone); sortBone(node.parentBone);
for (Bone bone : node.bones) // for (Bone bone : node.bones)
sortBone(bone); // sortBone(bone);
} }
updateCache.add(constraint); updateCache.add(constraint);
for (int i = 0; i < nodeCount; i++) { for (int i = 0; i < nodeCount; i++) {
Node node = (Node)nodes[i]; Node node = (Node)nodes[i];
for (Bone bone : node.bones) sortReset(node.parentBone.children);
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; i < nodeCount; i++) {
for (int i = 0, n = constraint.springs.size; i < n; i++) { // Node node = (Node)nodes[i];
Spring spring = (Spring)springs[i]; // for (Bone bone : node.bones)
if (spring.bone == null) continue; // sortReset(bone.children);
sortBone(spring.bone); // }
updateCache.add(spring); // for (int i = 0; i < nodeCount; i++) {
sortReset(spring.bone.children); // Node node = (Node)nodes[i];
spring.bone.sorted = true; // for (Bone bone : node.bones)
for (Bone child : spring.bone.children) // bone.sorted = true;
sortBone(child); // }
} //
// 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) { private void sortBone (Bone bone) {