diff --git a/spine-lua/PathConstraint.lua b/spine-lua/PathConstraint.lua index 296f849c8..cf23000b5 100644 --- a/spine-lua/PathConstraint.lua +++ b/spine-lua/PathConstraint.lua @@ -137,7 +137,19 @@ function PathConstraint:update () local boneX = positions[1] local boneY = positions[2] local offsetRotation = data.offsetRotation - local tip = rotateMode == PathConstraintData.RotateMode.chain and offsetRotation == 0 + local tip = false; + if offsetRotation == 0 then + tip = rotateMode == PathConstraintData.RotateMode.chain + else + tip = false; + local p = self.target.bone; + if p.a * p.d - p.b * p.c > 0 then + offsetRotation = offsetRotation * utils.degRad + else + offsetRotation = offsetRotation * -utils.degRad + end + end + local i = 0 local p = 3 while i < boneCount do @@ -173,13 +185,15 @@ function PathConstraint:update () else r = math_atan2(dy, dx) end - r = r - (math_atan2(c, a) - math_rad(offsetRotation)) + r = r - math_atan2(c, a) if tip then cos = math_cos(r) sin = math_sin(r) local length = bone.data.length boneX = boneX + (length * (cos * a - sin * c) - dx) * rotateMix; boneY = boneY + (length * (sin * a + cos * c) - dy) * rotateMix; + else + r = r + offsetRotation end if r > math_pi then r = r - math_pi2 diff --git a/spine-lua/TransformConstraint.lua b/spine-lua/TransformConstraint.lua index a7f000f94..7ae6efcdf 100644 --- a/spine-lua/TransformConstraint.lua +++ b/spine-lua/TransformConstraint.lua @@ -29,6 +29,7 @@ ------------------------------------------------------------------------------- local setmetatable = setmetatable +local utils = require "spine-lua.utils" local math_pi = math.pi local math_pi2 = math.pi * 2 local math_atan2 = math.atan2 @@ -79,6 +80,10 @@ function TransformConstraint:update () local tb = target.b local tc = target.c local td = target.d + local degRadReflect = 0; + if ta * td - tb * tc > 0 then degRadReflect = utils.degRad else degRadReflect = -utils.degRad end + local offsetRotation = self.data.offsetRotation * degRadReflect + local offsetShearY = self.data.offsetShearY * degRadReflect local bones = self.bones for i, bone in ipairs(bones) do local modified = false @@ -87,7 +92,7 @@ function TransformConstraint:update () local b = bone.b local c = bone.c local d = bone.d - local r = math_atan2(tc, ta) - math_atan2(c, a) + math_rad(self.data.offsetRotation); + local r = math_atan2(tc, ta) - math_atan2(c, a) + offsetRotation if r > math_pi then r = r - math_pi2 elseif r < -math_pi then @@ -143,7 +148,7 @@ function TransformConstraint:update () elseif r < -math_pi then r = r + math_pi2 end - r = by + (r + math_rad(self.data.offsetShearY)) * shearMix + r = by + (r + offsetShearY) * shearMix local s = math_sqrt(b * b + d * d) bone.b = math_cos(r) * s bone.d = math_sin(r) * s diff --git a/spine-lua/utils.lua b/spine-lua/utils.lua index e4d0fec5f..ef8447c23 100644 --- a/spine-lua/utils.lua +++ b/spine-lua/utils.lua @@ -30,6 +30,8 @@ local utils = {} +utils.degRad = math.pi / 180 + function tablePrint (tt, indent, done) done = done or {} for key, value in pairs(tt) do