[csharp] Fixed Path/TransformConstraint handling of reflection

This commit is contained in:
pharan 2016-11-07 21:27:33 +08:00
parent badcb9c44a
commit 6c72dfa8b4
2 changed files with 15 additions and 4 deletions

View File

@ -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;

View File

@ -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;