mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-04 14:24:53 +08:00
Cleaned up trigonometry.
* Do one conversion to radians for sin and cos. * Added atan2Deg. * PathConstraint wasn't using SpineUtils. * PointAttachment was using MathUtils.
This commit is contained in:
parent
45c51b0c4f
commit
92164921a5
@ -110,11 +110,13 @@ public class Bone implements Updatable {
|
|||||||
Bone parent = this.parent;
|
Bone parent = this.parent;
|
||||||
if (parent == null) { // Root bone.
|
if (parent == null) { // Root bone.
|
||||||
Skeleton skeleton = this.skeleton;
|
Skeleton skeleton = this.skeleton;
|
||||||
float rotationY = rotation + 90 + shearY, sx = skeleton.scaleX, sy = skeleton.scaleY;
|
float sx = skeleton.scaleX, sy = skeleton.scaleY;
|
||||||
a = cosDeg(rotation + shearX) * scaleX * sx;
|
float rx = (rotation + shearX) * degRad;
|
||||||
b = cosDeg(rotationY) * scaleY * sx;
|
float ry = (rotation + 90 + shearY) * degRad;
|
||||||
c = sinDeg(rotation + shearX) * scaleX * sy;
|
a = cos(rx) * scaleX * sx;
|
||||||
d = sinDeg(rotationY) * scaleY * sy;
|
b = cos(ry) * scaleY * sx;
|
||||||
|
c = sin(rx) * scaleX * sy;
|
||||||
|
d = sin(ry) * scaleY * sy;
|
||||||
worldX = x * sx + skeleton.x;
|
worldX = x * sx + skeleton.x;
|
||||||
worldY = y * sy + skeleton.y;
|
worldY = y * sy + skeleton.y;
|
||||||
return;
|
return;
|
||||||
@ -126,11 +128,12 @@ public class Bone implements Updatable {
|
|||||||
|
|
||||||
switch (data.transformMode) {
|
switch (data.transformMode) {
|
||||||
case normal: {
|
case normal: {
|
||||||
float rotationY = rotation + 90 + shearY;
|
float rx = (rotation + shearX) * degRad;
|
||||||
float la = cosDeg(rotation + shearX) * scaleX;
|
float ry = (rotation + 90 + shearY) * degRad;
|
||||||
float lb = cosDeg(rotationY) * scaleY;
|
float la = cos(rx) * scaleX;
|
||||||
float lc = sinDeg(rotation + shearX) * scaleX;
|
float lb = cos(ry) * scaleY;
|
||||||
float ld = sinDeg(rotationY) * scaleY;
|
float lc = sin(rx) * scaleX;
|
||||||
|
float ld = sin(ry) * scaleY;
|
||||||
a = pa * la + pb * lc;
|
a = pa * la + pb * lc;
|
||||||
b = pa * lb + pb * ld;
|
b = pa * lb + pb * ld;
|
||||||
c = pc * la + pd * lc;
|
c = pc * la + pd * lc;
|
||||||
@ -138,11 +141,12 @@ public class Bone implements Updatable {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
case onlyTranslation: {
|
case onlyTranslation: {
|
||||||
float rotationY = rotation + 90 + shearY;
|
float rx = (rotation + shearX) * degRad;
|
||||||
a = cosDeg(rotation + shearX) * scaleX;
|
float ry = (rotation + 90 + shearY) * degRad;
|
||||||
b = cosDeg(rotationY) * scaleY;
|
a = cos(rx) * scaleX;
|
||||||
c = sinDeg(rotation + shearX) * scaleX;
|
b = cos(ry) * scaleY;
|
||||||
d = sinDeg(rotationY) * scaleY;
|
c = sin(rx) * scaleX;
|
||||||
|
d = sin(ry) * scaleY;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case noRotationOrReflection: {
|
case noRotationOrReflection: {
|
||||||
@ -153,18 +157,18 @@ public class Bone implements Updatable {
|
|||||||
pc /= skeleton.scaleY;
|
pc /= skeleton.scaleY;
|
||||||
pb = pc * s;
|
pb = pc * s;
|
||||||
pd = pa * s;
|
pd = pa * s;
|
||||||
prx = atan2(pc, pa) * radDeg;
|
prx = atan2Deg(pc, pa);
|
||||||
} else {
|
} else {
|
||||||
pa = 0;
|
pa = 0;
|
||||||
pc = 0;
|
pc = 0;
|
||||||
prx = 90 - atan2(pd, pb) * radDeg;
|
prx = 90 - atan2Deg(pd, pb);
|
||||||
}
|
}
|
||||||
float rx = rotation + shearX - prx;
|
float rx = (rotation + shearX - prx) * degRad;
|
||||||
float ry = rotation + shearY - prx + 90;
|
float ry = (rotation + shearY - prx + 90) * degRad;
|
||||||
float la = cosDeg(rx) * scaleX;
|
float la = cos(rx) * scaleX;
|
||||||
float lb = cosDeg(ry) * scaleY;
|
float lb = cos(ry) * scaleY;
|
||||||
float lc = sinDeg(rx) * scaleX;
|
float lc = sin(rx) * scaleX;
|
||||||
float ld = sinDeg(ry) * scaleY;
|
float ld = sin(ry) * scaleY;
|
||||||
a = pa * la - pb * lc;
|
a = pa * la - pb * lc;
|
||||||
b = pa * lb - pb * ld;
|
b = pa * lb - pb * ld;
|
||||||
c = pc * la + pd * lc;
|
c = pc * la + pd * lc;
|
||||||
@ -173,7 +177,8 @@ public class Bone implements Updatable {
|
|||||||
}
|
}
|
||||||
case noScale:
|
case noScale:
|
||||||
case noScaleOrReflection:
|
case noScaleOrReflection:
|
||||||
float cos = cosDeg(rotation), sin = sinDeg(rotation);
|
rotation *= degRad;
|
||||||
|
float cos = cos(rotation), sin = sin(rotation);
|
||||||
float za = (pa * cos + pb * sin) / skeleton.scaleX;
|
float za = (pa * cos + pb * sin) / skeleton.scaleX;
|
||||||
float zc = (pc * cos + pd * sin) / skeleton.scaleY;
|
float zc = (pc * cos + pd * sin) / skeleton.scaleY;
|
||||||
float s = (float)Math.sqrt(za * za + zc * zc);
|
float s = (float)Math.sqrt(za * za + zc * zc);
|
||||||
@ -183,13 +188,15 @@ public class Bone implements Updatable {
|
|||||||
s = (float)Math.sqrt(za * za + zc * zc);
|
s = (float)Math.sqrt(za * za + zc * zc);
|
||||||
if (data.transformMode == TransformMode.noScale
|
if (data.transformMode == TransformMode.noScale
|
||||||
&& (pa * pd - pb * pc < 0) != (skeleton.scaleX < 0 != skeleton.scaleY < 0)) s = -s;
|
&& (pa * pd - pb * pc < 0) != (skeleton.scaleX < 0 != skeleton.scaleY < 0)) s = -s;
|
||||||
float r = PI / 2 + atan2(zc, za);
|
rotation = PI / 2 + atan2(zc, za);
|
||||||
float zb = cos(r) * s;
|
float zb = cos(rotation) * s;
|
||||||
float zd = sin(r) * s;
|
float zd = sin(rotation) * s;
|
||||||
float la = cosDeg(shearX) * scaleX;
|
shearX *= degRad;
|
||||||
float lb = cosDeg(90 + shearY) * scaleY;
|
shearY = (90 + shearY) * degRad;
|
||||||
float lc = sinDeg(shearX) * scaleX;
|
float la = cos(shearX) * scaleX;
|
||||||
float ld = sinDeg(90 + shearY) * scaleY;
|
float lb = cos(shearY) * scaleY;
|
||||||
|
float lc = sin(shearX) * scaleX;
|
||||||
|
float ld = sin(shearY) * scaleY;
|
||||||
a = za * la + zb * lc;
|
a = za * la + zb * lc;
|
||||||
b = za * lb + zb * ld;
|
b = za * lb + zb * ld;
|
||||||
c = zc * la + zd * lc;
|
c = zc * la + zd * lc;
|
||||||
@ -398,11 +405,11 @@ public class Bone implements Updatable {
|
|||||||
ax = worldX - skeleton.x;
|
ax = worldX - skeleton.x;
|
||||||
ay = worldY - skeleton.y;
|
ay = worldY - skeleton.y;
|
||||||
float a = this.a, b = this.b, c = this.c, d = this.d;
|
float a = this.a, b = this.b, c = this.c, d = this.d;
|
||||||
arotation = atan2(c, a) * radDeg;
|
arotation = atan2Deg(c, a);
|
||||||
ascaleX = (float)Math.sqrt(a * a + c * c);
|
ascaleX = (float)Math.sqrt(a * a + c * c);
|
||||||
ascaleY = (float)Math.sqrt(b * b + d * d);
|
ascaleY = (float)Math.sqrt(b * b + d * d);
|
||||||
ashearX = 0;
|
ashearX = 0;
|
||||||
ashearY = atan2(a * b + c * d, a * d - b * c) * radDeg;
|
ashearY = atan2Deg(a * b + c * d, a * d - b * c);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -434,7 +441,7 @@ public class Bone implements Updatable {
|
|||||||
}
|
}
|
||||||
case noScale:
|
case noScale:
|
||||||
case noScaleOrReflection:
|
case noScaleOrReflection:
|
||||||
float cos = cosDeg(rotation), sin = sinDeg(rotation);
|
float r = rotation * degRad, cos = cos(r), sin = sin(r);
|
||||||
pa = (pa * cos + pb * sin) / skeleton.scaleX;
|
pa = (pa * cos + pb * sin) / skeleton.scaleX;
|
||||||
pc = (pc * cos + pd * sin) / skeleton.scaleY;
|
pc = (pc * cos + pd * sin) / skeleton.scaleY;
|
||||||
float s = (float)Math.sqrt(pa * pa + pc * pc);
|
float s = (float)Math.sqrt(pa * pa + pc * pc);
|
||||||
@ -443,7 +450,7 @@ public class Bone implements Updatable {
|
|||||||
pc *= s;
|
pc *= s;
|
||||||
s = (float)Math.sqrt(pa * pa + pc * pc);
|
s = (float)Math.sqrt(pa * pa + pc * pc);
|
||||||
if (data.transformMode == TransformMode.noScale && pid < 0 != (skeleton.scaleX < 0 != skeleton.scaleY < 0)) s = -s;
|
if (data.transformMode == TransformMode.noScale && pid < 0 != (skeleton.scaleX < 0 != skeleton.scaleY < 0)) s = -s;
|
||||||
float r = PI / 2 + atan2(pc, pa);
|
r = PI / 2 + atan2(pc, pa);
|
||||||
pb = cos(r) * s;
|
pb = cos(r) * s;
|
||||||
pd = sin(r) * s;
|
pd = sin(r) * s;
|
||||||
pid = 1 / (pa * pd - pb * pc);
|
pid = 1 / (pa * pd - pb * pc);
|
||||||
@ -463,13 +470,13 @@ public class Bone implements Updatable {
|
|||||||
if (ascaleX > 0.0001f) {
|
if (ascaleX > 0.0001f) {
|
||||||
float det = ra * rd - rb * rc;
|
float det = ra * rd - rb * rc;
|
||||||
ascaleY = det / ascaleX;
|
ascaleY = det / ascaleX;
|
||||||
ashearY = -atan2(ra * rb + rc * rd, det) * radDeg;
|
ashearY = -atan2Deg(ra * rb + rc * rd, det);
|
||||||
arotation = atan2(rc, ra) * radDeg;
|
arotation = atan2Deg(rc, ra);
|
||||||
} else {
|
} else {
|
||||||
ascaleX = 0;
|
ascaleX = 0;
|
||||||
ascaleY = (float)Math.sqrt(rb * rb + rd * rd);
|
ascaleY = (float)Math.sqrt(rb * rb + rd * rd);
|
||||||
ashearY = 0;
|
ashearY = 0;
|
||||||
arotation = 90 - atan2(rd, rb) * radDeg;
|
arotation = 90 - atan2Deg(rd, rb);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -531,12 +538,12 @@ public class Bone implements Updatable {
|
|||||||
|
|
||||||
/** The world rotation for the X axis, calculated using {@link #a} and {@link #c}. */
|
/** The world rotation for the X axis, calculated using {@link #a} and {@link #c}. */
|
||||||
public float getWorldRotationX () {
|
public float getWorldRotationX () {
|
||||||
return atan2(c, a) * radDeg;
|
return atan2Deg(c, a);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The world rotation for the Y axis, calculated using {@link #b} and {@link #d}. */
|
/** The world rotation for the Y axis, calculated using {@link #b} and {@link #d}. */
|
||||||
public float getWorldRotationY () {
|
public float getWorldRotationY () {
|
||||||
return atan2(d, b) * radDeg;
|
return atan2Deg(d, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** The magnitude (always positive) of the world scale X, calculated using {@link #a} and {@link #c}. */
|
/** The magnitude (always positive) of the world scale X, calculated using {@link #a} and {@link #c}. */
|
||||||
@ -585,15 +592,16 @@ public class Bone implements Updatable {
|
|||||||
|
|
||||||
/** Transforms a world rotation to a local rotation. */
|
/** Transforms a world rotation to a local rotation. */
|
||||||
public float worldToLocalRotation (float worldRotation) {
|
public float worldToLocalRotation (float worldRotation) {
|
||||||
float sin = sinDeg(worldRotation), cos = cosDeg(worldRotation);
|
worldRotation *= degRad;
|
||||||
return atan2(a * sin - c * cos, d * cos - b * sin) * radDeg + rotation - shearX;
|
float sin = sin(worldRotation), cos = cos(worldRotation);
|
||||||
|
return atan2Deg(a * sin - c * cos, d * cos - b * sin) + rotation - shearX;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Transforms a local rotation to a world rotation. */
|
/** Transforms a local rotation to a world rotation. */
|
||||||
public float localToWorldRotation (float localRotation) {
|
public float localToWorldRotation (float localRotation) {
|
||||||
localRotation -= rotation - shearX;
|
localRotation = (localRotation - rotation - shearX) * degRad;
|
||||||
float sin = sinDeg(localRotation), cos = cosDeg(localRotation);
|
float sin = sin(localRotation), cos = cos(localRotation);
|
||||||
return atan2(cos * c + sin * d, cos * a + sin * b) * radDeg;
|
return atan2Deg(cos * c + sin * d, cos * a + sin * b);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Rotates the world transform the specified amount.
|
/** Rotates the world transform the specified amount.
|
||||||
@ -601,7 +609,8 @@ public class Bone implements Updatable {
|
|||||||
* After changes are made to the world transform, {@link #updateAppliedTransform()} should be called and {@link #update()} will
|
* After changes are made to the world transform, {@link #updateAppliedTransform()} should be called and {@link #update()} will
|
||||||
* need to be called on any child bones, recursively. */
|
* need to be called on any child bones, recursively. */
|
||||||
public void rotateWorld (float degrees) {
|
public void rotateWorld (float degrees) {
|
||||||
float cos = cosDeg(degrees), sin = sinDeg(degrees);
|
degrees *= degRad;
|
||||||
|
float sin = sin(degrees), cos = cos(degrees);
|
||||||
a = cos * a - sin * c;
|
a = cos * a - sin * c;
|
||||||
b = cos * b - sin * d;
|
b = cos * b - sin * d;
|
||||||
c = sin * a + cos * c;
|
c = sin * a + cos * c;
|
||||||
|
|||||||
@ -200,7 +200,7 @@ public class IkConstraint implements Updatable {
|
|||||||
float sc = pc / bone.skeleton.scaleY;
|
float sc = pc / bone.skeleton.scaleY;
|
||||||
pb = -sc * s * bone.skeleton.scaleX;
|
pb = -sc * s * bone.skeleton.scaleX;
|
||||||
pd = sa * s * bone.skeleton.scaleY;
|
pd = sa * s * bone.skeleton.scaleY;
|
||||||
rotationIK += atan2(sc, sa) * radDeg;
|
rotationIK += atan2Deg(sc, sa);
|
||||||
// Fall through.
|
// Fall through.
|
||||||
default:
|
default:
|
||||||
float x = targetX - p.worldX, y = targetY - p.worldY;
|
float x = targetX - p.worldX, y = targetY - p.worldY;
|
||||||
@ -208,7 +208,7 @@ public class IkConstraint implements Updatable {
|
|||||||
tx = (x * pd - y * pb) / d - bone.ax;
|
tx = (x * pd - y * pb) / d - bone.ax;
|
||||||
ty = (y * pa - x * pc) / d - bone.ay;
|
ty = (y * pa - x * pc) / d - bone.ay;
|
||||||
}
|
}
|
||||||
rotationIK += atan2(ty, tx) * radDeg;
|
rotationIK += atan2Deg(ty, tx);
|
||||||
if (bone.ascaleX < 0) rotationIK += 180;
|
if (bone.ascaleX < 0) rotationIK += 180;
|
||||||
if (rotationIK > 180)
|
if (rotationIK > 180)
|
||||||
rotationIK -= 360;
|
rotationIK -= 360;
|
||||||
|
|||||||
@ -203,11 +203,11 @@ public class PathConstraint implements Updatable {
|
|||||||
else if (spaces[i + 1] < epsilon)
|
else if (spaces[i + 1] < epsilon)
|
||||||
r = positions[p + 2];
|
r = positions[p + 2];
|
||||||
else
|
else
|
||||||
r = (float)Math.atan2(dy, dx);
|
r = atan2(dy, dx);
|
||||||
r -= (float)Math.atan2(c, a);
|
r -= atan2(c, a);
|
||||||
if (tip) {
|
if (tip) {
|
||||||
cos = (float)Math.cos(r);
|
cos = cos(r);
|
||||||
sin = (float)Math.sin(r);
|
sin = sin(r);
|
||||||
float length = bone.data.length;
|
float length = bone.data.length;
|
||||||
boneX += (length * (cos * a - sin * c) - dx) * mixRotate;
|
boneX += (length * (cos * a - sin * c) - dx) * mixRotate;
|
||||||
boneY += (length * (sin * a + cos * c) - dy) * mixRotate;
|
boneY += (length * (sin * a + cos * c) - dy) * mixRotate;
|
||||||
@ -218,8 +218,8 @@ public class PathConstraint implements Updatable {
|
|||||||
else if (r < -PI) //
|
else if (r < -PI) //
|
||||||
r += PI2;
|
r += PI2;
|
||||||
r *= mixRotate;
|
r *= mixRotate;
|
||||||
cos = (float)Math.cos(r);
|
cos = cos(r);
|
||||||
sin = (float)Math.sin(r);
|
sin = sin(r);
|
||||||
bone.a = cos * a - sin * c;
|
bone.a = cos * a - sin * c;
|
||||||
bone.b = cos * b - sin * d;
|
bone.b = cos * b - sin * d;
|
||||||
bone.c = sin * a + cos * c;
|
bone.c = sin * a + cos * c;
|
||||||
@ -465,16 +465,16 @@ public class PathConstraint implements Updatable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void addBeforePosition (float p, float[] temp, int i, float[] out, int o) {
|
private void addBeforePosition (float p, float[] temp, int i, float[] out, int o) {
|
||||||
float x1 = temp[i], y1 = temp[i + 1], dx = temp[i + 2] - x1, dy = temp[i + 3] - y1, r = (float)Math.atan2(dy, dx);
|
float x1 = temp[i], y1 = temp[i + 1], dx = temp[i + 2] - x1, dy = temp[i + 3] - y1, r = atan2(dy, dx);
|
||||||
out[o] = x1 + p * (float)Math.cos(r);
|
out[o] = x1 + p * cos(r);
|
||||||
out[o + 1] = y1 + p * (float)Math.sin(r);
|
out[o + 1] = y1 + p * sin(r);
|
||||||
out[o + 2] = r;
|
out[o + 2] = r;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addAfterPosition (float p, float[] temp, int i, float[] out, int o) {
|
private void addAfterPosition (float p, float[] temp, int i, float[] out, int o) {
|
||||||
float x1 = temp[i + 2], y1 = temp[i + 3], dx = x1 - temp[i], dy = y1 - temp[i + 1], r = (float)Math.atan2(dy, dx);
|
float x1 = temp[i + 2], y1 = temp[i + 3], dx = x1 - temp[i], dy = y1 - temp[i + 1], r = atan2(dy, dx);
|
||||||
out[o] = x1 + p * (float)Math.cos(r);
|
out[o] = x1 + p * cos(r);
|
||||||
out[o + 1] = y1 + p * (float)Math.sin(r);
|
out[o + 1] = y1 + p * sin(r);
|
||||||
out[o + 2] = r;
|
out[o + 2] = r;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -483,7 +483,7 @@ public class PathConstraint implements Updatable {
|
|||||||
if (p < epsilon || Float.isNaN(p)) {
|
if (p < epsilon || Float.isNaN(p)) {
|
||||||
out[o] = x1;
|
out[o] = x1;
|
||||||
out[o + 1] = y1;
|
out[o + 1] = y1;
|
||||||
out[o + 2] = (float)Math.atan2(cy1 - y1, cx1 - x1);
|
out[o + 2] = atan2(cy1 - y1, cx1 - x1);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
float tt = p * p, ttt = tt * p, u = 1 - p, uu = u * u, uuu = uu * u;
|
float tt = p * p, ttt = tt * p, u = 1 - p, uu = u * u, uuu = uu * u;
|
||||||
@ -493,9 +493,9 @@ public class PathConstraint implements Updatable {
|
|||||||
out[o + 1] = y;
|
out[o + 1] = y;
|
||||||
if (tangents) {
|
if (tangents) {
|
||||||
if (p < 0.001f)
|
if (p < 0.001f)
|
||||||
out[o + 2] = (float)Math.atan2(cy1 - y1, cx1 - x1);
|
out[o + 2] = atan2(cy1 - y1, cx1 - x1);
|
||||||
else
|
else
|
||||||
out[o + 2] = (float)Math.atan2(y - (y1 * uu + cy1 * ut * 2 + cy2 * tt), x - (x1 * uu + cx1 * ut * 2 + cx2 * tt));
|
out[o + 2] = atan2(y - (y1 * uu + cy1 * ut * 2 + cy2 * tt), x - (x1 * uu + cx1 * ut * 2 + cx2 * tt));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -371,7 +371,7 @@ public class PhysicsConstraint implements Updatable {
|
|||||||
float s = (float)Math.sqrt(dx * dx + dy * dy) / length, r = atan2(dy, dx), sin = sin(r), cos = cos(r);
|
float s = (float)Math.sqrt(dx * dx + dy * dy) / length, r = atan2(dy, dx), sin = sin(r), cos = cos(r);
|
||||||
if (constraint.mix == 1) {
|
if (constraint.mix == 1) {
|
||||||
bone.updateWorldTransform(bone.ax, bone.ay,
|
bone.updateWorldTransform(bone.ax, bone.ay,
|
||||||
atan2(bone.a * sin - bone.c * cos, bone.d * cos - bone.b * sin) * radDeg + bone.arotation - bone.ashearX,
|
atan2Deg(bone.a * sin - bone.c * cos, bone.d * cos - bone.b * sin) + bone.arotation - bone.ashearX,
|
||||||
bone.ascaleX * s, bone.ascaleY, bone.ashearX, bone.ashearY);
|
bone.ascaleX * s, bone.ascaleY, bone.ashearX, bone.ashearY);
|
||||||
} else {
|
} else {
|
||||||
// BOZO
|
// BOZO
|
||||||
|
|||||||
@ -444,11 +444,12 @@ public class Skeleton {
|
|||||||
rootBone.worldX = pa * x + pb * y + parent.worldX;
|
rootBone.worldX = pa * x + pb * y + parent.worldX;
|
||||||
rootBone.worldY = pc * x + pd * y + parent.worldY;
|
rootBone.worldY = pc * x + pd * y + parent.worldY;
|
||||||
|
|
||||||
float rotationY = rootBone.rotation + 90 + rootBone.shearY;
|
float rx = (rootBone.rotation + rootBone.shearX) * degRad;
|
||||||
float la = cosDeg(rootBone.rotation + rootBone.shearX) * rootBone.scaleX;
|
float ry = (rootBone.rotation + 90 + rootBone.shearY) * degRad;
|
||||||
float lb = cosDeg(rotationY) * rootBone.scaleY;
|
float la = cos(rx) * rootBone.scaleX;
|
||||||
float lc = sinDeg(rootBone.rotation + rootBone.shearX) * rootBone.scaleX;
|
float lb = cos(ry) * rootBone.scaleY;
|
||||||
float ld = sinDeg(rotationY) * rootBone.scaleY;
|
float lc = sin(rx) * rootBone.scaleX;
|
||||||
|
float ld = sin(ry) * rootBone.scaleY;
|
||||||
rootBone.a = (pa * la + pb * lc) * scaleX;
|
rootBone.a = (pa * la + pb * lc) * scaleX;
|
||||||
rootBone.b = (pa * lb + pb * ld) * scaleX;
|
rootBone.b = (pa * lb + pb * ld) * scaleX;
|
||||||
rootBone.c = (pc * la + pd * lc) * scaleY;
|
rootBone.c = (pc * la + pd * lc) * scaleY;
|
||||||
|
|||||||
@ -29,7 +29,7 @@
|
|||||||
|
|
||||||
package com.esotericsoftware.spine.attachments;
|
package com.esotericsoftware.spine.attachments;
|
||||||
|
|
||||||
import static com.badlogic.gdx.math.MathUtils.*;
|
import static com.esotericsoftware.spine.utils.SpineUtils.*;
|
||||||
|
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
@ -97,10 +97,10 @@ public class PointAttachment extends Attachment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public float computeWorldRotation (Bone bone) {
|
public float computeWorldRotation (Bone bone) {
|
||||||
float cos = cosDeg(rotation), sin = sinDeg(rotation);
|
float r = rotation * degRad, cos = cos(r), sin = sin(r);
|
||||||
float x = cos * bone.getA() + sin * bone.getB();
|
float x = cos * bone.getA() + sin * bone.getB();
|
||||||
float y = cos * bone.getC() + sin * bone.getD();
|
float y = cos * bone.getC() + sin * bone.getD();
|
||||||
return (float)Math.atan2(y, x) * radDeg;
|
return atan2Deg(y, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
public PointAttachment copy () {
|
public PointAttachment copy () {
|
||||||
|
|||||||
@ -93,8 +93,7 @@ public class RegionAttachment extends Attachment implements HasTextureRegion {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
float width = getWidth();
|
float width = getWidth(), height = getHeight();
|
||||||
float height = getHeight();
|
|
||||||
float localX2 = width / 2;
|
float localX2 = width / 2;
|
||||||
float localY2 = height / 2;
|
float localY2 = height / 2;
|
||||||
float localX = -localX2;
|
float localX = -localX2;
|
||||||
@ -113,17 +112,13 @@ public class RegionAttachment extends Attachment implements HasTextureRegion {
|
|||||||
localY2 -= (region.originalHeight - region.offsetY - region.packedHeight) / region.originalHeight * height;
|
localY2 -= (region.originalHeight - region.offsetY - region.packedHeight) / region.originalHeight * height;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
float scaleX = getScaleX();
|
float scaleX = getScaleX(), scaleY = getScaleY();
|
||||||
float scaleY = getScaleY();
|
|
||||||
localX *= scaleX;
|
localX *= scaleX;
|
||||||
localY *= scaleY;
|
localY *= scaleY;
|
||||||
localX2 *= scaleX;
|
localX2 *= scaleX;
|
||||||
localY2 *= scaleY;
|
localY2 *= scaleY;
|
||||||
float rotation = getRotation();
|
float r = getRotation() * degRad, cos = cos(r), sin = sin(r);
|
||||||
float cos = (float)Math.cos(degRad * rotation);
|
float x = getX(), y = getY();
|
||||||
float sin = (float)Math.sin(degRad * rotation);
|
|
||||||
float x = getX();
|
|
||||||
float y = getY();
|
|
||||||
float localXCos = localX * cos + x;
|
float localXCos = localX * cos + x;
|
||||||
float localXSin = localX * sin;
|
float localXSin = localX * sin;
|
||||||
float localYCos = localY * cos + y;
|
float localYCos = localY * cos + y;
|
||||||
|
|||||||
@ -37,23 +37,27 @@ public class SpineUtils {
|
|||||||
static public final float degreesToRadians = PI / 180;
|
static public final float degreesToRadians = PI / 180;
|
||||||
static public final float degRad = degreesToRadians;
|
static public final float degRad = degreesToRadians;
|
||||||
|
|
||||||
public static float cosDeg (float degrees) {
|
static public float cosDeg (float degrees) {
|
||||||
return (float)Math.cos(degrees * degRad);
|
return (float)Math.cos(degrees * degRad);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float sinDeg (float degrees) {
|
static public float sinDeg (float degrees) {
|
||||||
return (float)Math.sin(degrees * degRad);
|
return (float)Math.sin(degrees * degRad);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float cos (float radians) {
|
static public float cos (float radians) {
|
||||||
return (float)Math.cos(radians);
|
return (float)Math.cos(radians);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float sin (float radians) {
|
static public float sin (float radians) {
|
||||||
return (float)Math.sin(radians);
|
return (float)Math.sin(radians);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static float atan2 (float y, float x) {
|
static public float atan2Deg (float y, float x) {
|
||||||
|
return (float)Math.atan2(y, x) * radDeg;
|
||||||
|
}
|
||||||
|
|
||||||
|
static public float atan2 (float y, float x) {
|
||||||
return (float)Math.atan2(y, x);
|
return (float)Math.atan2(y, x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user