From 2dee5d610354a633d926f0cf36cc45599dd94aaf Mon Sep 17 00:00:00 2001 From: NathanSweet Date: Fri, 5 Aug 2016 01:42:24 +0200 Subject: [PATCH] [libgdx] New math for disable inherit scale. More stable (fixes rotation with negative scale) but slightly different behavior: scaling parent bones can cause the rotation to change on a bone with disable inherit scale. This seems like sane behavior though, so likely worth the change. More here: http://esotericsoftware.com/forum/Disabling-inherit-scale-breaks-rotation-v3-4-0-1-6757 --- .../src/com/esotericsoftware/spine/Bone.java | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Bone.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Bone.java index 076a4b2d6..621fc406f 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Bone.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Bone.java @@ -134,26 +134,26 @@ public class Bone implements Updatable { d = pc * lb + pd * ld; } else { if (data.inheritRotation) { // No scale inheritance. - pa = 1; - pb = 0; - pc = 0; - pd = 1; - do { - float cos = cosDeg(parent.appliedRotation), sin = sinDeg(parent.appliedRotation); - float temp = pa * cos + pb * sin; - pb = pb * cos - pa * sin; - pa = temp; - temp = pc * cos + pd * sin; - pd = pd * cos - pc * sin; - pc = temp; - - if (!parent.data.inheritRotation) break; - parent = parent.parent; - } while (parent != null); a = pa * la + pb * lc; b = pa * lb + pb * ld; c = pc * la + pd * lc; d = pc * lb + pd * ld; + float bs = (float)Math.sqrt(a * a + c * c), s = bs > 0.00001f ? 1 / bs : 0; + a *= s; + c *= s; + bs = (float)Math.sqrt(b * b + d * d); + s = bs > 0.00001f ? 1 / bs : 0; + b *= s; + d *= s; + float by = atan2(d, b); + float r = PI / 2 - (by - atan2(c, a)); + if (r > PI) + r -= PI2; + else if (r < -PI) r += PI2; + r += by; + s = (float)Math.sqrt(b * b + d * d); + b = cos(r) * s; + d = sin(r) * s; } else if (data.inheritScale) { // No rotation inheritance. pa = 1; pb = 0;