mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 01:36:02 +08:00
[libgdx] Added skeleton reference scale.
This commit is contained in:
parent
8e1d3ca898
commit
1dbbfda2c8
@ -150,7 +150,7 @@ public class PhysicsConstraint implements Updatable {
|
|||||||
ux = bx;
|
ux = bx;
|
||||||
uy = by;
|
uy = by;
|
||||||
} else {
|
} else {
|
||||||
float remaining = this.remaining, i = inertia, step = data.step;
|
float a = this.remaining, i = inertia, t = data.step, f = skeleton.data.referenceScale;
|
||||||
if (x || y) {
|
if (x || y) {
|
||||||
if (x) {
|
if (x) {
|
||||||
xOffset += (ux - bx) * i;
|
xOffset += (ux - bx) * i;
|
||||||
@ -160,22 +160,22 @@ public class PhysicsConstraint implements Updatable {
|
|||||||
yOffset += (uy - by) * i;
|
yOffset += (uy - by) * i;
|
||||||
uy = by;
|
uy = by;
|
||||||
}
|
}
|
||||||
if (remaining >= step) {
|
if (a >= t) {
|
||||||
float m = massInverse * step, e = strength, w = wind * 100, g = gravity * -100;
|
float m = massInverse * t, e = strength, w = wind * f, g = gravity * f;
|
||||||
float d = (float)Math.pow(damping, 60 * step);
|
float d = (float)Math.pow(damping, 60 * t);
|
||||||
do {
|
do {
|
||||||
if (x) {
|
if (x) {
|
||||||
xVelocity += (w - xOffset * e) * m;
|
xVelocity += (w - xOffset * e) * m;
|
||||||
xOffset += xVelocity * step;
|
xOffset += xVelocity * t;
|
||||||
xVelocity *= d;
|
xVelocity *= d;
|
||||||
}
|
}
|
||||||
if (y) {
|
if (y) {
|
||||||
yVelocity += (g - yOffset * e) * m;
|
yVelocity -= (g + yOffset * e) * m;
|
||||||
yOffset += yVelocity * step;
|
yOffset += yVelocity * t;
|
||||||
yVelocity *= d;
|
yVelocity *= d;
|
||||||
}
|
}
|
||||||
remaining -= step;
|
a -= t;
|
||||||
} while (remaining >= step);
|
} while (a >= t);
|
||||||
}
|
}
|
||||||
if (x) bone.worldX += xOffset * mix * data.x;
|
if (x) bone.worldX += xOffset * mix * data.x;
|
||||||
if (y) bone.worldY += yOffset * mix * data.y;
|
if (y) bone.worldY += yOffset * mix * data.y;
|
||||||
@ -199,31 +199,31 @@ public class PhysicsConstraint implements Updatable {
|
|||||||
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 += ((cx - bone.worldX) * c + (cy - bone.worldY) * s) * i / r;
|
||||||
}
|
}
|
||||||
remaining = this.remaining;
|
a = this.remaining;
|
||||||
if (remaining >= step) {
|
if (a >= t) {
|
||||||
float m = massInverse * step, e = strength, w = wind, g = gravity;
|
float m = massInverse * t, e = strength, w = wind, g = gravity;
|
||||||
float d = (float)Math.pow(damping, 60 * step);
|
float d = (float)Math.pow(damping, 60 * t), h = l / f;
|
||||||
while (true) {
|
while (true) {
|
||||||
remaining -= step;
|
a -= t;
|
||||||
if (scaleX) {
|
if (scaleX) {
|
||||||
scaleVelocity += (w * c - g * s - scaleOffset * e) * m;
|
scaleVelocity += (w * c - g * s - scaleOffset * e) * m;
|
||||||
scaleOffset += scaleVelocity * step;
|
scaleOffset += scaleVelocity * t;
|
||||||
scaleVelocity *= d;
|
scaleVelocity *= d;
|
||||||
}
|
}
|
||||||
if (rotateOrShearX) {
|
if (rotateOrShearX) {
|
||||||
rotateVelocity += (-0.01f * l * (w * s + g * c) - rotateOffset * e) * m;
|
rotateVelocity -= ((w * s + g * c) * h + rotateOffset * e) * m;
|
||||||
rotateOffset += rotateVelocity * step;
|
rotateOffset += rotateVelocity * t;
|
||||||
rotateVelocity *= d;
|
rotateVelocity *= d;
|
||||||
if (remaining < step) break;
|
if (a < t) break;
|
||||||
float r = rotateOffset * mr + ca;
|
float r = rotateOffset * mr + ca;
|
||||||
c = cos(r);
|
c = cos(r);
|
||||||
s = sin(r);
|
s = sin(r);
|
||||||
} else if (remaining < step) //
|
} else if (a < t) //
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.remaining = remaining;
|
this.remaining = a;
|
||||||
}
|
}
|
||||||
cx = bone.worldX;
|
cx = bone.worldX;
|
||||||
cy = bone.worldY;
|
cy = bone.worldY;
|
||||||
|
|||||||
@ -59,9 +59,7 @@ public class Skeleton {
|
|||||||
final Array<Updatable> updateCache = new Array();
|
final Array<Updatable> updateCache = new Array();
|
||||||
@Null Skin skin;
|
@Null Skin skin;
|
||||||
final Color color;
|
final Color color;
|
||||||
float x, y;
|
float x, y, scaleX = 1, scaleY = 1, time;
|
||||||
float scaleX = 1, scaleY = 1;
|
|
||||||
float time;
|
|
||||||
|
|
||||||
public Skeleton (SkeletonData data) {
|
public Skeleton (SkeletonData data) {
|
||||||
if (data == null) throw new IllegalArgumentException("data cannot be null.");
|
if (data == null) throw new IllegalArgumentException("data cannot be null.");
|
||||||
|
|||||||
@ -174,6 +174,7 @@ public class SkeletonBinary extends SkeletonLoader {
|
|||||||
skeletonData.y = input.readFloat();
|
skeletonData.y = input.readFloat();
|
||||||
skeletonData.width = input.readFloat();
|
skeletonData.width = input.readFloat();
|
||||||
skeletonData.height = input.readFloat();
|
skeletonData.height = input.readFloat();
|
||||||
|
skeletonData.referenceScale = input.readFloat() * scale;
|
||||||
|
|
||||||
boolean nonessential = input.readBoolean();
|
boolean nonessential = input.readBoolean();
|
||||||
if (nonessential) {
|
if (nonessential) {
|
||||||
@ -336,8 +337,8 @@ public class SkeletonBinary extends SkeletonLoader {
|
|||||||
data.strength = input.readFloat();
|
data.strength = input.readFloat();
|
||||||
data.damping = input.readFloat();
|
data.damping = input.readFloat();
|
||||||
data.massInverse = input.readFloat();
|
data.massInverse = input.readFloat();
|
||||||
data.wind = input.readFloat() * scale;
|
data.wind = input.readFloat();
|
||||||
data.gravity = input.readFloat() * scale;
|
data.gravity = input.readFloat();
|
||||||
data.mix = input.readFloat();
|
data.mix = input.readFloat();
|
||||||
flags = input.read();
|
flags = input.read();
|
||||||
if ((flags & 1) != 0) data.inertiaGlobal = true;
|
if ((flags & 1) != 0) data.inertiaGlobal = true;
|
||||||
|
|||||||
@ -48,7 +48,7 @@ public class SkeletonData {
|
|||||||
final Array<TransformConstraintData> transformConstraints = new Array();
|
final Array<TransformConstraintData> transformConstraints = new Array();
|
||||||
final Array<PathConstraintData> pathConstraints = new Array();
|
final Array<PathConstraintData> pathConstraints = new Array();
|
||||||
final Array<PhysicsConstraintData> physicsConstraints = new Array();
|
final Array<PhysicsConstraintData> physicsConstraints = new Array();
|
||||||
float x, y, width, height;
|
float x, y, width, height, referenceScale = 100;
|
||||||
@Null String version, hash;
|
@Null String version, hash;
|
||||||
|
|
||||||
// Nonessential.
|
// Nonessential.
|
||||||
@ -283,6 +283,16 @@ public class SkeletonData {
|
|||||||
this.height = height;
|
this.height = height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** Baseline scale factor for applying distance-dependent effects on non-scalable properties, such as angle or scale. Default
|
||||||
|
* is 100. */
|
||||||
|
public float getReferenceScale () {
|
||||||
|
return referenceScale;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setReferenceScale (float referenceScale) {
|
||||||
|
this.referenceScale = referenceScale;
|
||||||
|
}
|
||||||
|
|
||||||
/** The Spine version used to export the skeleton data, or null. */
|
/** The Spine version used to export the skeleton data, or null. */
|
||||||
public @Null String getVersion () {
|
public @Null String getVersion () {
|
||||||
return version;
|
return version;
|
||||||
|
|||||||
@ -143,6 +143,7 @@ public class SkeletonJson extends SkeletonLoader {
|
|||||||
skeletonData.y = skeletonMap.getFloat("y", 0);
|
skeletonData.y = skeletonMap.getFloat("y", 0);
|
||||||
skeletonData.width = skeletonMap.getFloat("width", 0);
|
skeletonData.width = skeletonMap.getFloat("width", 0);
|
||||||
skeletonData.height = skeletonMap.getFloat("height", 0);
|
skeletonData.height = skeletonMap.getFloat("height", 0);
|
||||||
|
skeletonData.referenceScale = skeletonMap.getFloat("referenceScale", 100) * scale;
|
||||||
skeletonData.fps = skeletonMap.getFloat("fps", 30);
|
skeletonData.fps = skeletonMap.getFloat("fps", 30);
|
||||||
skeletonData.imagesPath = skeletonMap.getString("images", null);
|
skeletonData.imagesPath = skeletonMap.getString("images", null);
|
||||||
skeletonData.audioPath = skeletonMap.getString("audio", null);
|
skeletonData.audioPath = skeletonMap.getString("audio", null);
|
||||||
@ -317,9 +318,9 @@ public class SkeletonJson extends SkeletonLoader {
|
|||||||
data.inertia = constraintMap.getFloat("inertia", 1);
|
data.inertia = constraintMap.getFloat("inertia", 1);
|
||||||
data.strength = constraintMap.getFloat("strength", 100);
|
data.strength = constraintMap.getFloat("strength", 100);
|
||||||
data.damping = constraintMap.getFloat("damping", 1);
|
data.damping = constraintMap.getFloat("damping", 1);
|
||||||
data.massInverse = 1f / constraintMap.getFloat("mass", 1);
|
data.massInverse = 1 / constraintMap.getFloat("mass", 1);
|
||||||
data.wind = constraintMap.getFloat("wind", 0) * scale;
|
data.wind = constraintMap.getFloat("wind", 0);
|
||||||
data.gravity = constraintMap.getFloat("gravity", 0) * scale;
|
data.gravity = constraintMap.getFloat("gravity", 0);
|
||||||
data.mix = constraintMap.getFloat("mix", 1);
|
data.mix = constraintMap.getFloat("mix", 1);
|
||||||
data.inertiaGlobal = constraintMap.getBoolean("inertiaGlobal", false);
|
data.inertiaGlobal = constraintMap.getBoolean("inertiaGlobal", false);
|
||||||
data.strengthGlobal = constraintMap.getBoolean("strengthGlobal", false);
|
data.strengthGlobal = constraintMap.getBoolean("strengthGlobal", false);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user