瀏覽代碼

[libgdx] Float instead of boolean for physics properties.

Nathan Sweet 1 年之前
父節點
當前提交
e00fb24ea3

+ 14 - 14
spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PhysicsConstraint.java

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

+ 11 - 11
spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PhysicsConstraintData.java

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

+ 5 - 5
spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonBinary.java

@@ -313,11 +313,11 @@ public class SkeletonBinary extends SkeletonLoader {
 				data.bone = (BoneData)bones[input.readInt(true)];
 				int flags = input.read();
 				data.skinRequired = (flags & 1) != 0;
-				data.x = (flags & 2) != 0;
-				data.y = (flags & 4) != 0;
-				data.rotate = (flags & 8) != 0;
-				data.scaleX = (flags & 16) != 0;
-				data.shearX = (flags & 32) != 0;
+				if ((flags & 2) != 0) data.x = input.readFloat();
+				if ((flags & 4) != 0) data.y = input.readFloat();
+				if ((flags & 8) != 0) data.rotate = input.readFloat();
+				if ((flags & 16) != 0) data.scaleX = input.readFloat();
+				if ((flags & 32) != 0) data.shearX = input.readFloat();
 				data.step = 1f / input.readByte();
 				data.inertia = input.readFloat();
 				data.strength = input.readFloat();

+ 5 - 5
spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/SkeletonJson.java

@@ -299,11 +299,11 @@ public class SkeletonJson extends SkeletonLoader {
 			data.bone = skeletonData.findBone(boneName);
 			if (data.bone == null) throw new SerializationException("Physics bone not found: " + boneName);
 
-			data.x = constraintMap.getBoolean("x", false);
-			data.y = constraintMap.getBoolean("y", false);
-			data.rotate = constraintMap.getBoolean("rotate", false);
-			data.scaleX = constraintMap.getBoolean("scaleX", false);
-			data.shearX = constraintMap.getBoolean("shearX", false);
+			data.x = constraintMap.getFloat("x", 0);
+			data.y = constraintMap.getFloat("y", 0);
+			data.rotate = constraintMap.getFloat("rotate", 0);
+			data.scaleX = constraintMap.getFloat("scaleX", 0);
+			data.shearX = constraintMap.getFloat("shearX", 0);
 			data.step = 1f / constraintMap.getInt("fps", 60);
 			data.inertia = constraintMap.getFloat("inertia", 1);
 			data.strength = constraintMap.getFloat("strength", 100);