mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2025-12-21 17:56:04 +08:00
[lua] Fixed Path/TransformConstraint handling of reflection
This commit is contained in:
parent
3666e7125a
commit
dbcc54fac4
@ -137,7 +137,19 @@ function PathConstraint:update ()
|
|||||||
local boneX = positions[1]
|
local boneX = positions[1]
|
||||||
local boneY = positions[2]
|
local boneY = positions[2]
|
||||||
local offsetRotation = data.offsetRotation
|
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 i = 0
|
||||||
local p = 3
|
local p = 3
|
||||||
while i < boneCount do
|
while i < boneCount do
|
||||||
@ -173,13 +185,15 @@ function PathConstraint:update ()
|
|||||||
else
|
else
|
||||||
r = math_atan2(dy, dx)
|
r = math_atan2(dy, dx)
|
||||||
end
|
end
|
||||||
r = r - (math_atan2(c, a) - math_rad(offsetRotation))
|
r = r - math_atan2(c, a)
|
||||||
if tip then
|
if tip then
|
||||||
cos = math_cos(r)
|
cos = math_cos(r)
|
||||||
sin = math_sin(r)
|
sin = math_sin(r)
|
||||||
local length = bone.data.length
|
local length = bone.data.length
|
||||||
boneX = boneX + (length * (cos * a - sin * c) - dx) * rotateMix;
|
boneX = boneX + (length * (cos * a - sin * c) - dx) * rotateMix;
|
||||||
boneY = boneY + (length * (sin * a + cos * c) - dy) * rotateMix;
|
boneY = boneY + (length * (sin * a + cos * c) - dy) * rotateMix;
|
||||||
|
else
|
||||||
|
r = r + offsetRotation
|
||||||
end
|
end
|
||||||
if r > math_pi then
|
if r > math_pi then
|
||||||
r = r - math_pi2
|
r = r - math_pi2
|
||||||
|
|||||||
@ -29,6 +29,7 @@
|
|||||||
-------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------
|
||||||
|
|
||||||
local setmetatable = setmetatable
|
local setmetatable = setmetatable
|
||||||
|
local utils = require "spine-lua.utils"
|
||||||
local math_pi = math.pi
|
local math_pi = math.pi
|
||||||
local math_pi2 = math.pi * 2
|
local math_pi2 = math.pi * 2
|
||||||
local math_atan2 = math.atan2
|
local math_atan2 = math.atan2
|
||||||
@ -79,6 +80,10 @@ function TransformConstraint:update ()
|
|||||||
local tb = target.b
|
local tb = target.b
|
||||||
local tc = target.c
|
local tc = target.c
|
||||||
local td = target.d
|
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
|
local bones = self.bones
|
||||||
for i, bone in ipairs(bones) do
|
for i, bone in ipairs(bones) do
|
||||||
local modified = false
|
local modified = false
|
||||||
@ -87,7 +92,7 @@ function TransformConstraint:update ()
|
|||||||
local b = bone.b
|
local b = bone.b
|
||||||
local c = bone.c
|
local c = bone.c
|
||||||
local d = bone.d
|
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
|
if r > math_pi then
|
||||||
r = r - math_pi2
|
r = r - math_pi2
|
||||||
elseif r < -math_pi then
|
elseif r < -math_pi then
|
||||||
@ -143,7 +148,7 @@ function TransformConstraint:update ()
|
|||||||
elseif r < -math_pi then
|
elseif r < -math_pi then
|
||||||
r = r + math_pi2
|
r = r + math_pi2
|
||||||
end
|
end
|
||||||
r = by + (r + math_rad(self.data.offsetShearY)) * shearMix
|
r = by + (r + offsetShearY) * shearMix
|
||||||
local s = math_sqrt(b * b + d * d)
|
local s = math_sqrt(b * b + d * d)
|
||||||
bone.b = math_cos(r) * s
|
bone.b = math_cos(r) * s
|
||||||
bone.d = math_sin(r) * s
|
bone.d = math_sin(r) * s
|
||||||
|
|||||||
@ -30,6 +30,8 @@
|
|||||||
|
|
||||||
local utils = {}
|
local utils = {}
|
||||||
|
|
||||||
|
utils.degRad = math.pi / 180
|
||||||
|
|
||||||
function tablePrint (tt, indent, done)
|
function tablePrint (tt, indent, done)
|
||||||
done = done or {}
|
done = done or {}
|
||||||
for key, value in pairs(tt) do
|
for key, value in pairs(tt) do
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user