/// <summary>Computes the world SRT using the parent bone and the specified local SRT.</summary> public void UpdateWorldTransform(float x, float y, float rotation, float scaleX, float scaleY) { appliedRotation = rotation; appliedScaleX = scaleX; appliedScaleY = scaleY; 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. { Skeleton skeleton = this.skeleton; if (skeleton.flipX) { x = -x; la = -la; lb = -lb; } if (skeleton.flipY != yDown) { y = -y; lc = -lc; ld = -ld; } a = la; b = lb; c = lc; d = ld; worldX = x; worldY = y; worldSignX = Math.Sign(scaleX); worldSignY = Math.Sign(scaleY); return; } float pa = parent.a, pb = parent.b, pc = parent.c, pd = parent.d; worldX = pa * x + pb * y + parent.worldX; worldY = pc * x + pd * y + parent.worldY; worldSignX = parent.worldSignX * Math.Sign(scaleX); worldSignY = parent.worldSignY * Math.Sign(scaleY); if (data.inheritRotation && data.inheritScale) { a = pa * la + pb * lc; b = pa * lb + pb * ld; c = pc * la + pd * lc; d = pc * lb + pd * ld; } else { if (data.inheritRotation) // No scale inheritance. { pa = 1; pb = 0; pc = 0; pd = 1; do { cos = MathUtils.CosDeg(parent.appliedRotation); sin = MathUtils.SinDeg(parent.appliedRotation); float temp = pa * cos + pb * sin; pb = pa * -sin + pb * cos; pa = temp; temp = pc * cos + pd * sin; pd = pc * -sin + pd * cos; 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; } else if (data.inheritScale) // No rotation inheritance. { pa = 1; pb = 0; pc = 0; pd = 1; do { float r = parent.rotation; 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; pb = pa * zb + pb * zd; pa = temp; temp = pc * za + pd * zc; pd = pc * zb + pd * zd; pc = temp; 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; temp = pc * cos + pd * sin; pd = pc * -sin + pd * cos; pc = temp; if (!parent.data.inheritScale) { 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; } else { a = la; b = lb; c = lc; d = ld; } if (skeleton.flipX) { a = -a; b = -b; } if (skeleton.flipY != yDown) { c = -c; d = -d; } } }