mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-04 14:24:53 +08:00
[libgdx] Use delta for physics limit, apply limit to scale.
This commit is contained in:
parent
8dd7016a72
commit
98c5be690a
@ -141,7 +141,8 @@ public class PhysicsConstraint implements Updatable {
|
|||||||
reset();
|
reset();
|
||||||
// Fall through.
|
// Fall through.
|
||||||
case update:
|
case update:
|
||||||
remaining += Math.max(skeleton.time - lastTime, 0);
|
float delta = Math.max(skeleton.time - lastTime, 0);
|
||||||
|
remaining += delta;
|
||||||
lastTime = skeleton.time;
|
lastTime = skeleton.time;
|
||||||
|
|
||||||
float bx = bone.worldX, by = bone.worldY;
|
float bx = bone.worldX, by = bone.worldY;
|
||||||
@ -150,7 +151,7 @@ public class PhysicsConstraint implements Updatable {
|
|||||||
ux = bx;
|
ux = bx;
|
||||||
uy = by;
|
uy = by;
|
||||||
} else {
|
} else {
|
||||||
float a = remaining, i = inertia, q = data.limit, t = data.step, f = skeleton.data.referenceScale, d = -1;
|
float a = remaining, i = inertia, q = data.limit * delta, t = data.step, f = skeleton.data.referenceScale, d = -1;
|
||||||
if (x || y) {
|
if (x || y) {
|
||||||
if (x) {
|
if (x) {
|
||||||
float u = (ux - bx) * i;
|
float u = (ux - bx) * i;
|
||||||
@ -184,11 +185,18 @@ public class PhysicsConstraint implements Updatable {
|
|||||||
}
|
}
|
||||||
if (rotateOrShearX || scaleX) {
|
if (rotateOrShearX || scaleX) {
|
||||||
float ca = atan2(bone.c, bone.a), c, s, mr = 0;
|
float ca = atan2(bone.c, bone.a), c, s, mr = 0;
|
||||||
|
float dx = cx - bone.worldX, dy = cy - bone.worldY;
|
||||||
|
if (dx > q)
|
||||||
|
dx = q;
|
||||||
|
else if (dx < -q) //
|
||||||
|
dx = -q;
|
||||||
|
if (dy > q)
|
||||||
|
dy = q;
|
||||||
|
else if (dy < -q) //
|
||||||
|
dy = -q;
|
||||||
if (rotateOrShearX) {
|
if (rotateOrShearX) {
|
||||||
mr = (data.rotate + data.shearX) * mix;
|
mr = (data.rotate + data.shearX) * mix;
|
||||||
float dx = cx - bone.worldX, dy = cy - bone.worldY;
|
float r = atan2(dy + ty, dx + tx) - ca - rotateOffset * mr;
|
||||||
float r = atan2((dy > q ? q : dy < -q ? -q : dy) + ty, (dx > q ? q : dx < -q ? -q : dx) + tx) - ca
|
|
||||||
- rotateOffset * mr;
|
|
||||||
rotateOffset += (r - (float)Math.ceil(r * invPI2 - 0.5f) * PI2) * i;
|
rotateOffset += (r - (float)Math.ceil(r * invPI2 - 0.5f) * PI2) * i;
|
||||||
r = rotateOffset * mr + ca;
|
r = rotateOffset * mr + ca;
|
||||||
c = cos(r);
|
c = cos(r);
|
||||||
@ -201,7 +209,7 @@ public class PhysicsConstraint implements Updatable {
|
|||||||
c = cos(ca);
|
c = cos(ca);
|
||||||
s = sin(ca);
|
s = sin(ca);
|
||||||
float r = l * bone.getWorldScaleX();
|
float r = l * bone.getWorldScaleX();
|
||||||
if (r > 0) scaleOffset += ((cx - bone.worldX) * c + (cy - bone.worldY) * s) * i / r;
|
if (r > 0) scaleOffset += (dx * c + dy * s) * i / r;
|
||||||
}
|
}
|
||||||
a = remaining;
|
a = remaining;
|
||||||
if (a >= t) {
|
if (a >= t) {
|
||||||
|
|||||||
@ -334,7 +334,7 @@ public class SkeletonBinary extends SkeletonLoader {
|
|||||||
if ((flags & 8) != 0) data.rotate = input.readFloat();
|
if ((flags & 8) != 0) data.rotate = input.readFloat();
|
||||||
if ((flags & 16) != 0) data.scaleX = input.readFloat();
|
if ((flags & 16) != 0) data.scaleX = input.readFloat();
|
||||||
if ((flags & 32) != 0) data.shearX = input.readFloat();
|
if ((flags & 32) != 0) data.shearX = input.readFloat();
|
||||||
data.limit = ((flags & 64) != 0 ? input.readFloat() : 500) * scale;
|
data.limit = ((flags & 64) != 0 ? input.readFloat() : 5000) * scale;
|
||||||
data.step = 1f / input.readByte();
|
data.step = 1f / input.readByte();
|
||||||
data.inertia = input.readFloat();
|
data.inertia = input.readFloat();
|
||||||
data.strength = input.readFloat();
|
data.strength = input.readFloat();
|
||||||
|
|||||||
@ -314,7 +314,7 @@ public class SkeletonJson extends SkeletonLoader {
|
|||||||
data.rotate = constraintMap.getFloat("rotate", 0);
|
data.rotate = constraintMap.getFloat("rotate", 0);
|
||||||
data.scaleX = constraintMap.getFloat("scaleX", 0);
|
data.scaleX = constraintMap.getFloat("scaleX", 0);
|
||||||
data.shearX = constraintMap.getFloat("shearX", 0);
|
data.shearX = constraintMap.getFloat("shearX", 0);
|
||||||
data.limit = constraintMap.getFloat("limit", 500) * scale;
|
data.limit = constraintMap.getFloat("limit", 5000) * scale;
|
||||||
data.step = 1f / constraintMap.getInt("fps", 60);
|
data.step = 1f / constraintMap.getInt("fps", 60);
|
||||||
data.inertia = constraintMap.getFloat("inertia", 1);
|
data.inertia = constraintMap.getFloat("inertia", 1);
|
||||||
data.strength = constraintMap.getFloat("strength", 100);
|
data.strength = constraintMap.getFloat("strength", 100);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user