From 6c72dfa8b44251687c5a807507b00390825e033f Mon Sep 17 00:00:00 2001 From: pharan Date: Mon, 7 Nov 2016 21:27:33 +0800 Subject: [PATCH] [csharp] Fixed Path/TransformConstraint handling of reflection --- spine-csharp/src/PathConstraint.cs | 13 +++++++++++-- spine-csharp/src/TransformConstraint.cs | 6 ++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/spine-csharp/src/PathConstraint.cs b/spine-csharp/src/PathConstraint.cs index e8a4f3c13..240085ef7 100644 --- a/spine-csharp/src/PathConstraint.cs +++ b/spine-csharp/src/PathConstraint.cs @@ -104,7 +104,14 @@ namespace Spine { float[] positions = ComputeWorldPositions(attachment, spacesCount, tangents, data.positionMode == PositionMode.Percent, spacingMode == SpacingMode.Percent); float boneX = positions[0], boneY = positions[1], offsetRotation = data.offsetRotation; - bool tip = rotateMode == RotateMode.Chain && offsetRotation == 0; + bool tip; + if (offsetRotation == 0) { + tip = rotateMode == RotateMode.Chain; + } else { + tip = false; + Bone p = target.bone; + offsetRotation *= p.a * p.d - p.b * p.c > 0 ? MathUtils.DegRad : -MathUtils.DegRad; + } for (int i = 0, p = 3; i < boneCount; i++, p += 3) { Bone bone = (Bone)bones[i]; bone.worldX += (boneX - bone.worldX) * translateMix; @@ -128,13 +135,15 @@ namespace Spine { r = positions[p + 2]; else r = MathUtils.Atan2(dy, dx); - r -= MathUtils.Atan2(c, a) - offsetRotation * MathUtils.DegRad; + r -= MathUtils.Atan2(c, a); if (tip) { cos = MathUtils.Cos(r); sin = MathUtils.Sin(r); float length = bone.data.length; boneX += (length * (cos * a - sin * c) - dx) * rotateMix; boneY += (length * (sin * a + cos * c) - dy) * rotateMix; + } else { + r += offsetRotation; } if (r > MathUtils.PI) r -= MathUtils.PI2; diff --git a/spine-csharp/src/TransformConstraint.cs b/spine-csharp/src/TransformConstraint.cs index cc94d5d05..3e368f14c 100644 --- a/spine-csharp/src/TransformConstraint.cs +++ b/spine-csharp/src/TransformConstraint.cs @@ -70,6 +70,8 @@ namespace Spine { float rotateMix = this.rotateMix, translateMix = this.translateMix, scaleMix = this.scaleMix, shearMix = this.shearMix; Bone target = this.target; float ta = target.a, tb = target.b, tc = target.c, td = target.d; + float degRadReflect = (ta * td - tb * tc > 0) ? MathUtils.DegRad : -MathUtils.DegRad; + float offsetRotation = data.offsetRotation * degRadReflect, offsetShearY = data.offsetShearY * degRadReflect; var bones = this.bones; var bonesItems = bones.Items; for (int i = 0, n = bones.Count; i < n; i++) { @@ -78,7 +80,7 @@ namespace Spine { if (rotateMix != 0) { float a = bone.a, b = bone.b, c = bone.c, d = bone.d; - float r = MathUtils.Atan2(tc, ta) - MathUtils.Atan2(c, a) + data.offsetRotation * MathUtils.DegRad; + float r = MathUtils.Atan2(tc, ta) - MathUtils.Atan2(c, a) + offsetRotation; if (r > MathUtils.PI) r -= MathUtils.PI2; else if (r < -MathUtils.PI) r += MathUtils.PI2; @@ -120,7 +122,7 @@ namespace Spine { if (r > MathUtils.PI) r -= MathUtils.PI2; else if (r < -MathUtils.PI) r += MathUtils.PI2; - r = by + (r + data.offsetShearY * MathUtils.DegRad) * shearMix; + r = by + (r + offsetShearY) * shearMix; float s = (float)Math.Sqrt(b * b + d * d); bone.b = MathUtils.Cos(r) * s; bone.d = MathUtils.Sin(r) * s;