From 008541ef8eecda4208a1afd5ee5ed890b59f202e Mon Sep 17 00:00:00 2001 From: Nathan Sweet Date: Sun, 1 Oct 2023 14:37:49 -0400 Subject: [PATCH] [libgdx] Scale physics wind and gravity for translation, scale rotation for shear X. --- .../spine/PhysicsConstraint.java | 36 +++++++++---------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PhysicsConstraint.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PhysicsConstraint.java index ca56a1ea4..e2bf0c929 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PhysicsConstraint.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/PhysicsConstraint.java @@ -121,12 +121,12 @@ public class PhysicsConstraint implements Updatable { while (remaining >= step) { remaining -= step; if (x) { - xVelocity += (wind - xOffset * strength - friction * xVelocity) * mass; + xVelocity += (wind * 500 - xOffset * strength - xVelocity * friction) * mass; xOffset += xVelocity * step; xVelocity *= damping; } if (y) { - yVelocity += (-gravity - yOffset * strength - friction * yVelocity) * mass; + yVelocity += (-gravity * 500 - yOffset * strength - yVelocity * friction) * mass; yOffset += yVelocity * step; yVelocity *= damping; } @@ -134,17 +134,17 @@ public class PhysicsConstraint implements Updatable { float r = br + rotateOffset * degRad; cos = cos(r); sin = sin(r); - } - if (rotateOrShear) { - rotateVelocity += (length * (-wind * sin - gravity * cos) - rotateOffset * strength - friction * rotateVelocity) - * mass; - rotateOffset += rotateVelocity * step; - rotateVelocity *= damping; - } - if (scaleX) { - scaleVelocity += (wind * cos - gravity * sin - scaleOffset * strength - friction * scaleVelocity) * mass; - scaleOffset += scaleVelocity * step; - scaleVelocity *= damping; + if (rotateOrShear) { + rotateVelocity += (length * (-wind * sin - gravity * cos) - rotateOffset * strength - rotateVelocity * friction) + * mass; + rotateOffset += rotateVelocity * step; + rotateVelocity *= damping; + } + if (scaleX) { + scaleVelocity += (wind * cos - gravity * sin - scaleOffset * strength - scaleVelocity * friction) * mass; + scaleOffset += scaleVelocity * step; + scaleVelocity *= damping; + } } } @@ -192,16 +192,12 @@ public class PhysicsConstraint implements Updatable { if (rotateOrShear) { float r = rotateOffset * mix; + if (data.rotate) bone.rotateWorld(r); if (data.shearX) { - if (data.rotate) { - r *= 0.5f; - bone.rotateWorld(r); - } - float t = (float)Math.tan(r * degRad); + float t = (float)Math.tan(r * 0.5f * degRad); bone.b += bone.a * t; bone.d += bone.c * t; - } else - bone.rotateWorld(r); + } } if (scaleX) { float s = 1 + scaleOffset * mix;