mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-06 07:14:55 +08:00
[libgdx] Physics mass -> massInverse. Timeline is not inverted.
This commit is contained in:
parent
043a8ea9ae
commit
3541d005a7
@ -2303,7 +2303,7 @@ public class Animation {
|
||||
}
|
||||
}
|
||||
|
||||
/** Changes a physics constraint's {@link PhysicsConstraint#getMass()}. */
|
||||
/** Changes a physics constraint's {@link PhysicsConstraint#getMassInverse()}. The timeline values are not inverted. */
|
||||
static public class PhysicsConstraintMassTimeline extends PhysicsConstraintTimeline {
|
||||
public PhysicsConstraintMassTimeline (int frameCount, int bezierCount, int physicsConstraintIndex) {
|
||||
super(frameCount, bezierCount, physicsConstraintIndex, Property.physicsConstraintMass);
|
||||
@ -2313,7 +2313,10 @@ public class Animation {
|
||||
MixDirection direction) {
|
||||
|
||||
PhysicsConstraint constraint = skeleton.physicsConstraints.get(constraintIndex);
|
||||
if (constraint.active) constraint.mass = getAbsoluteValue(time, alpha, blend, constraint.mass, constraint.data.mass);
|
||||
if (constraint.active) {
|
||||
constraint.massInverse = 1
|
||||
/ getAbsoluteValue(time, alpha, blend, 1 / constraint.massInverse, 1 / constraint.data.massInverse);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -39,7 +39,7 @@ import com.esotericsoftware.spine.Skeleton.Physics;
|
||||
public class PhysicsConstraint implements Updatable {
|
||||
final PhysicsConstraintData data;
|
||||
public Bone bone;
|
||||
float inertia, strength, damping, mass, wind, gravity, mix;
|
||||
float inertia, strength, damping, massInverse, wind, gravity, mix;
|
||||
|
||||
boolean reset = true;
|
||||
float ux, uy, cx, cy, tx, ty;
|
||||
@ -62,7 +62,7 @@ public class PhysicsConstraint implements Updatable {
|
||||
inertia = data.inertia;
|
||||
strength = data.strength;
|
||||
damping = data.damping;
|
||||
mass = data.mass;
|
||||
massInverse = data.massInverse;
|
||||
wind = data.wind;
|
||||
gravity = data.gravity;
|
||||
mix = data.mix;
|
||||
@ -77,7 +77,7 @@ public class PhysicsConstraint implements Updatable {
|
||||
inertia = constraint.inertia;
|
||||
strength = constraint.strength;
|
||||
damping = constraint.damping;
|
||||
mass = constraint.mass;
|
||||
massInverse = constraint.massInverse;
|
||||
wind = constraint.wind;
|
||||
gravity = constraint.gravity;
|
||||
mix = constraint.mix;
|
||||
@ -103,7 +103,7 @@ public class PhysicsConstraint implements Updatable {
|
||||
inertia = data.inertia;
|
||||
strength = data.strength;
|
||||
damping = data.damping;
|
||||
mass = data.mass;
|
||||
massInverse = data.massInverse;
|
||||
wind = data.wind;
|
||||
gravity = data.gravity;
|
||||
mix = data.mix;
|
||||
@ -134,7 +134,7 @@ public class PhysicsConstraint implements Updatable {
|
||||
ux = bx;
|
||||
uy = by;
|
||||
} else {
|
||||
float remaining = this.remaining, i = this.inertia, step = data.step;
|
||||
float remaining = this.remaining, i = inertia, step = data.step;
|
||||
if (x || y) {
|
||||
if (x) {
|
||||
xOffset += (ux - bx) * i;
|
||||
@ -145,8 +145,8 @@ public class PhysicsConstraint implements Updatable {
|
||||
uy = by;
|
||||
}
|
||||
if (remaining >= step) {
|
||||
float m = this.mass * step, e = this.strength, w = wind * 100, g = gravity * -100;
|
||||
float d = (float)Math.pow(this.damping, 60 * step);
|
||||
float m = massInverse * step, e = strength, w = wind * 100, g = gravity * -100;
|
||||
float d = (float)Math.pow(damping, 60 * step);
|
||||
do {
|
||||
if (x) {
|
||||
xVelocity += (w - xOffset * e) * m;
|
||||
@ -154,6 +154,7 @@ public class PhysicsConstraint implements Updatable {
|
||||
xVelocity *= d;
|
||||
}
|
||||
if (y) {
|
||||
System.out.println(massInverse);
|
||||
yVelocity += (g - yOffset * e) * m;
|
||||
yOffset += yVelocity * step;
|
||||
yVelocity *= d;
|
||||
@ -180,8 +181,8 @@ public class PhysicsConstraint implements Updatable {
|
||||
}
|
||||
remaining = this.remaining;
|
||||
if (remaining >= step) {
|
||||
float m = this.mass * step, e = this.strength, w = wind, g = gravity;
|
||||
float d = (float)Math.pow(this.damping, 60 * step);
|
||||
float m = massInverse * step, e = strength, w = wind, g = gravity;
|
||||
float d = (float)Math.pow(damping, 60 * step);
|
||||
while (true) {
|
||||
remaining -= step;
|
||||
if (scaleX) {
|
||||
@ -281,13 +282,12 @@ public class PhysicsConstraint implements Updatable {
|
||||
this.damping = damping;
|
||||
}
|
||||
|
||||
/** The inverse of the mass. */
|
||||
public float getMass () {
|
||||
return mass;
|
||||
public float getMassInverse () {
|
||||
return massInverse;
|
||||
}
|
||||
|
||||
public void setMass (float mass) {
|
||||
this.mass = mass;
|
||||
public void setMassInverse (float massInverse) {
|
||||
this.massInverse = massInverse;
|
||||
}
|
||||
|
||||
public float getWind () {
|
||||
|
||||
@ -35,7 +35,7 @@ package com.esotericsoftware.spine;
|
||||
public class PhysicsConstraintData extends ConstraintData {
|
||||
BoneData bone;
|
||||
boolean x, y, rotate, scaleX, shearX;
|
||||
float step, inertia, strength, damping, mass, wind, gravity, mix;
|
||||
float step, inertia, strength, damping, massInverse, wind, gravity, mix;
|
||||
|
||||
public PhysicsConstraintData (String name) {
|
||||
super(name);
|
||||
@ -122,13 +122,12 @@ public class PhysicsConstraintData extends ConstraintData {
|
||||
this.damping = damping;
|
||||
}
|
||||
|
||||
/** The inverse of the mass. */
|
||||
public float getMass () {
|
||||
return mass;
|
||||
public float getMassInverse () {
|
||||
return massInverse;
|
||||
}
|
||||
|
||||
public void setMass (float mass) {
|
||||
this.mass = mass;
|
||||
public void setMassInverse (float massInverse) {
|
||||
this.massInverse = massInverse;
|
||||
}
|
||||
|
||||
public float getWind () {
|
||||
|
||||
@ -320,7 +320,7 @@ public class SkeletonBinary extends SkeletonLoader {
|
||||
data.inertia = input.readFloat();
|
||||
data.strength = input.readFloat();
|
||||
data.damping = input.readFloat();
|
||||
data.mass = input.readFloat();
|
||||
data.massInverse = input.readFloat();
|
||||
data.wind = input.readFloat();
|
||||
data.gravity = input.readFloat();
|
||||
data.mix = input.readFloat();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user