[libgdx] Float instead of boolean for physics properties.

This commit is contained in:
Nathan Sweet 2023-11-10 14:42:50 -04:00
parent a4efb66d74
commit e00fb24ea3
4 changed files with 35 additions and 35 deletions

View File

@ -114,7 +114,7 @@ public class PhysicsConstraint implements Updatable {
float mix = this.mix; float mix = this.mix;
if (mix == 0) return; if (mix == 0) return;
boolean x = data.x, y = data.y, rotateOrShearX = data.rotate || data.shearX, scaleX = data.scaleX; boolean x = data.x > 0, y = data.y > 0, rotateOrShearX = data.rotate > 0 || data.shearX > 0, scaleX = data.scaleX > 0;
Bone bone = this.bone; Bone bone = this.bone;
float l = bone.data.length; float l = bone.data.length;
@ -161,8 +161,8 @@ public class PhysicsConstraint implements Updatable {
remaining -= step; remaining -= step;
} while (remaining >= step); } while (remaining >= step);
} }
if (x) bone.worldX += xOffset * mix; if (x) bone.worldX += xOffset * mix * data.x;
if (y) bone.worldY += yOffset * mix; if (y) bone.worldY += yOffset * mix * data.y;
} }
if (rotateOrShearX || scaleX) { if (rotateOrShearX || scaleX) {
float ca = atan2(bone.c, bone.a), c, s; float ca = atan2(bone.c, bone.a), c, s;
@ -212,36 +212,36 @@ public class PhysicsConstraint implements Updatable {
cy = bone.worldY; cy = bone.worldY;
break; break;
case pose: case pose:
if (x) bone.worldX += xOffset * mix; if (x) bone.worldX += xOffset * mix * data.x;
if (y) bone.worldY += yOffset * mix; if (y) bone.worldY += yOffset * mix * data.y;
} }
if (rotateOrShearX) { if (rotateOrShearX) {
float r = rotateOffset * mix, a = bone.a, s, c; float r = rotateOffset * mix, a = bone.a, s, c;
if (data.rotate) { if (data.rotate > 0) {
if (data.shearX) { if (data.shearX > 0) {
r *= 0.5f; r *= 0.5f;
s = sin(r); s = sin(r * data.shearX);
c = cos(r); c = cos(r * data.shearX);
bone.a = c * a - s * bone.c; bone.a = c * a - s * bone.c;
bone.c = s * a + c * bone.c; bone.c = s * a + c * bone.c;
a = bone.a; a = bone.a;
} else { } else {
s = sin(r); s = sin(r * data.rotate);
c = cos(r); c = cos(r * data.rotate);
} }
float b = bone.b; float b = bone.b;
bone.b = c * b - s * bone.d; bone.b = c * b - s * bone.d;
bone.d = s * b + c * bone.d; bone.d = s * b + c * bone.d;
} else { } else {
s = sin(r); s = sin(r * data.shearX);
c = cos(r); c = cos(r * data.shearX);
} }
bone.a = c * a - s * bone.c; bone.a = c * a - s * bone.c;
bone.c = s * a + c * bone.c; bone.c = s * a + c * bone.c;
} }
if (scaleX) { if (scaleX) {
float s = 1 + scaleOffset * mix; float s = 1 + scaleOffset * mix * data.scaleX;
bone.a *= s; bone.a *= s;
bone.c *= s; bone.c *= s;
} }

View File

@ -34,7 +34,7 @@ package com.esotericsoftware.spine;
* 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 PhysicsConstraintData extends ConstraintData { public class PhysicsConstraintData extends ConstraintData {
BoneData bone; BoneData bone;
boolean x, y, rotate, scaleX, shearX; float x, y, rotate, scaleX, shearX;
float step, inertia, strength, damping, massInverse, wind, gravity, mix; float step, inertia, strength, damping, massInverse, wind, gravity, mix;
public PhysicsConstraintData (String name) { public PhysicsConstraintData (String name) {
@ -58,43 +58,43 @@ public class PhysicsConstraintData extends ConstraintData {
this.step = step; this.step = step;
} }
public boolean getX () { public float getX () {
return x; return x;
} }
public void setX (boolean x) { public void setX (float x) {
this.x = x; this.x = x;
} }
public boolean getY () { public float getY () {
return y; return y;
} }
public void setY (boolean y) { public void setY (float y) {
this.y = y; this.y = y;
} }
public boolean getRotate () { public float getRotate () {
return rotate; return rotate;
} }
public void setRotate (boolean rotate) { public void setRotate (float rotate) {
this.rotate = rotate; this.rotate = rotate;
} }
public boolean getScaleX () { public float getScaleX () {
return scaleX; return scaleX;
} }
public void setScaleX (boolean scaleX) { public void setScaleX (float scaleX) {
this.scaleX = scaleX; this.scaleX = scaleX;
} }
public boolean getShearX () { public float getShearX () {
return shearX; return shearX;
} }
public void setShearX (boolean shearX) { public void setShearX (float shearX) {
this.shearX = shearX; this.shearX = shearX;
} }

View File

@ -313,11 +313,11 @@ public class SkeletonBinary extends SkeletonLoader {
data.bone = (BoneData)bones[input.readInt(true)]; data.bone = (BoneData)bones[input.readInt(true)];
int flags = input.read(); int flags = input.read();
data.skinRequired = (flags & 1) != 0; data.skinRequired = (flags & 1) != 0;
data.x = (flags & 2) != 0; if ((flags & 2) != 0) data.x = input.readFloat();
data.y = (flags & 4) != 0; if ((flags & 4) != 0) data.y = input.readFloat();
data.rotate = (flags & 8) != 0; if ((flags & 8) != 0) data.rotate = input.readFloat();
data.scaleX = (flags & 16) != 0; if ((flags & 16) != 0) data.scaleX = input.readFloat();
data.shearX = (flags & 32) != 0; if ((flags & 32) != 0) data.shearX = input.readFloat();
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();

View File

@ -299,11 +299,11 @@ public class SkeletonJson extends SkeletonLoader {
data.bone = skeletonData.findBone(boneName); data.bone = skeletonData.findBone(boneName);
if (data.bone == null) throw new SerializationException("Physics bone not found: " + boneName); if (data.bone == null) throw new SerializationException("Physics bone not found: " + boneName);
data.x = constraintMap.getBoolean("x", false); data.x = constraintMap.getFloat("x", 0);
data.y = constraintMap.getBoolean("y", false); data.y = constraintMap.getFloat("y", 0);
data.rotate = constraintMap.getBoolean("rotate", false); data.rotate = constraintMap.getFloat("rotate", 0);
data.scaleX = constraintMap.getBoolean("scaleX", false); data.scaleX = constraintMap.getFloat("scaleX", 0);
data.shearX = constraintMap.getBoolean("shearX", false); data.shearX = constraintMap.getFloat("shearX", 0);
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);