[lua] Fixed Path/TransformConstraint handling of reflection

This commit is contained in:
badlogic 2016-11-07 14:07:56 +01:00
parent 3666e7125a
commit dbcc54fac4
3 changed files with 25 additions and 4 deletions

View File

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

View File

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

View File

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