mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-04 14:24:53 +08:00
WIP
This commit is contained in:
parent
d8f0e9e88d
commit
9ac1d77d32
@ -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;
|
||||
}
|
||||
|
||||
// ---
|
||||
|
||||
@ -47,8 +47,8 @@ import com.esotericsoftware.spine.attachments.PathAttachment;
|
||||
* <p>
|
||||
* See <a href="http://esotericsoftware.com/spine-path-constraints">Path constraints</a> 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<Bone> bones;
|
||||
@ -122,14 +122,10 @@ 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Arrays.fill(spaces, 1, spacesCount, spacing);
|
||||
break;
|
||||
case proportional:
|
||||
|
||||
@ -42,7 +42,8 @@ import com.esotericsoftware.spine.PhysicsConstraintData.SpringData;
|
||||
* <p>
|
||||
* See <a href="http://esotericsoftware.com/spine-physics-constraints">Physics constraints</a> 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<Node> 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;
|
||||
|
||||
@ -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) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user