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 91c4ffcf0..28cbe4309 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Bone.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/Bone.java @@ -94,8 +94,7 @@ public class Bone implements Updatable { appliedScaleX = scaleX; appliedScaleY = scaleY; - rotation *= MathUtils.degRad; - float cos = (float)Math.cos(rotation), sin = (float)Math.sin(rotation); + float cos = MathUtils.cosDeg(rotation), sin = MathUtils.sinDeg(rotation); float la = cos * scaleX, lb = -sin * scaleY, lc = sin * scaleX, ld = cos * scaleY; Bone parent = this.parent; if (parent == null) { // Root bone. @@ -139,9 +138,8 @@ public class Bone implements Updatable { pc = 0; pd = 1; do { - rotation = parent.appliedRotation * MathUtils.degRad; - cos = (float)Math.cos(rotation); - sin = (float)Math.sin(rotation); + cos = MathUtils.cosDeg(parent.appliedRotation); + sin = MathUtils.sinDeg(parent.appliedRotation); float temp = pa * cos + pb * sin; pb = pa * -sin + pb * cos; pa = temp; @@ -162,9 +160,9 @@ public class Bone implements Updatable { pc = 0; pd = 1; do { - rotation = parent.appliedRotation * MathUtils.degRad; - cos = (float)Math.cos(rotation); - sin = (float)Math.sin(rotation); + float r = parent.appliedRotation; + cos = MathUtils.cosDeg(r); + sin = MathUtils.sinDeg(r); float psx = parent.appliedScaleX, psy = parent.appliedScaleY; float za = cos * psx, zb = -sin * psy, zc = sin * psx, zd = cos * psy; float temp = pa * za + pb * zc; @@ -174,9 +172,9 @@ public class Bone implements Updatable { pd = pc * zb + pd * zd; pc = temp; - if (psx < 0) rotation = -rotation; - cos = (float)Math.cos(-rotation); - sin = (float)Math.sin(-rotation); + if (psx < 0) r = -r; + cos = MathUtils.cosDeg(-r); + sin = MathUtils.sinDeg(-r); temp = pa * cos + pb * sin; pb = pa * -sin + pb * cos; pa = temp; @@ -318,11 +316,11 @@ public class Bone implements Updatable { } public float getWorldRotationX () { - return (float)Math.atan2(c, a) * MathUtils.radDeg; + return MathUtils.atan2(c, a) * MathUtils.radDeg; } public float getWorldRotationY () { - return (float)Math.atan2(d, b) * MathUtils.radDeg; + return MathUtils.atan2(d, b) * MathUtils.radDeg; } public float getWorldScaleX () { diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/IkConstraint.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/IkConstraint.java index 840d41530..75d12e431 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/IkConstraint.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/IkConstraint.java @@ -124,7 +124,7 @@ public class IkConstraint implements Updatable { static public void apply (Bone bone, float targetX, float targetY, float alpha) { float parentRotation = bone.parent == null ? 0 : bone.parent.getWorldRotationX(); float rotation = bone.rotation; - float rotationIK = (float)Math.atan2(targetY - bone.worldY, targetX - bone.worldX) * radDeg - parentRotation; + float rotationIK = atan2(targetY - bone.worldY, targetX - bone.worldX) * radDeg - parentRotation; if ((bone.worldSignX != bone.worldSignY) != (bone.skeleton.flipX != bone.skeleton.flipY)) rotationIK = 360 - rotationIK; if (rotationIK > 180) rotationIK -= 360; @@ -190,10 +190,10 @@ public class IkConstraint implements Updatable { cos = -1; else if (cos > 1) cos = 1; a2 = (float)Math.acos(cos) * bendDir; - float a = l1 + l2 * cos, o = l2 * (float)Math.sin(a2); - a1 = (float)Math.atan2(ty * a - tx * o, tx * a + ty * o); + float a = l1 + l2 * cos, o = l2 * sin(a2); + a1 = atan2(ty * a - tx * o, tx * a + ty * o); } else { - float a = psx * l2, b = psy * l2, ta = (float)Math.atan2(ty, tx); + float a = psx * l2, b = psy * l2, ta = atan2(ty, tx); float aa = a * a, bb = b * b, ll = l1 * l1, dd = tx * tx + ty * ty; float c0 = bb * ll + aa * dd - aa * bb, c1 = -2 * bb * l1, c2 = bb - aa; float d = c1 * c1 - 4 * c2 * c0; @@ -205,8 +205,8 @@ public class IkConstraint implements Updatable { float r = Math.abs(r0) < Math.abs(r1) ? r0 : r1; if (r * r <= dd) { float y = (float)Math.sqrt(dd - r * r) * bendDir; - a1 = ta - (float)Math.atan2(y, r); - a2 = (float)Math.atan2(y / psy, (r - l1) / psx); + a1 = ta - atan2(y, r); + a2 = atan2(y / psy, (r - l1) / psx); break outer; } } @@ -226,8 +226,8 @@ public class IkConstraint implements Updatable { minX = x; } float angle = (float)Math.acos(-a * l1 / (aa - bb)); - x = a * (float)Math.cos(angle) + l1; - float y = b * (float)Math.sin(angle); + x = a * cos(angle) + l1; + float y = b * sin(angle); dist = x * x + y * y; if (dist < minDist) { minAngle = angle; @@ -242,14 +242,14 @@ public class IkConstraint implements Updatable { maxY = y; } if (dd <= (minDist + maxDist) / 2) { - a1 = ta - (float)Math.atan2(minY * bendDir, minX); + a1 = ta - atan2(minY * bendDir, minX); a2 = minAngle * bendDir; } else { - a1 = ta - (float)Math.atan2(maxY * bendDir, maxX); + a1 = ta - atan2(maxY * bendDir, maxX); a2 = maxAngle * bendDir; } } - float os = (float)Math.atan2(cy, cx) * s2; + float os = atan2(cy, cx) * s2; a1 = (a1 - os) * radDeg + os1; a2 = (a2 + os) * radDeg * s2 + os2; if (a1 > 180) diff --git a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/attachments/RegionAttachment.java b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/attachments/RegionAttachment.java index a965841e7..c645f58ce 100644 --- a/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/attachments/RegionAttachment.java +++ b/spine-libgdx/spine-libgdx/src/com/esotericsoftware/spine/attachments/RegionAttachment.java @@ -92,9 +92,9 @@ public class RegionAttachment extends Attachment { localY *= scaleY; localX2 *= scaleX; localY2 *= scaleY; - float rotation = getRotation() * MathUtils.degRad; - float cos = (float)Math.cos(rotation); - float sin = (float)Math.sin(rotation); + float rotation = getRotation(); + float cos = MathUtils.cosDeg(rotation); + float sin = MathUtils.sinDeg(rotation); float x = getX(); float y = getY(); float localXCos = localX * cos + x;