diff --git a/spine-lua/AnimationState.lua b/spine-lua/AnimationState.lua index bb144a2f7..d4e1bc0fd 100644 --- a/spine-lua/AnimationState.lua +++ b/spine-lua/AnimationState.lua @@ -38,6 +38,7 @@ local math_abs = math.abs local math_signum = utils.signum local math_floor = math.floor local math_ceil = math.ceil +local math_mod = utils.mod local function zlen(array) return #array + 1 @@ -442,7 +443,7 @@ function AnimationState:applyRotateTimeline (timeline, skeleton, time, alpha, se if math_abs(lastTotal) > 180 then lastTotal = lastTotal + 360 * math_signum(lastTotal) end dir = current end - total = diff + lastTotal - math_ceil(lastTotal / 360 - 0.5) * 360 -- FIXME used to be %360, store loops as part of lastTotal. + total = diff + lastTotal - math_mod(lastTotal, 360) -- FIXME used to be %360, store loops as part of lastTotal. if dir ~= current then total = total + 360 * math_signum(lastTotal) end timelinesRotation[i] = total end diff --git a/spine-lua/utils.lua b/spine-lua/utils.lua index ef8447c23..ba1e84111 100644 --- a/spine-lua/utils.lua +++ b/spine-lua/utils.lua @@ -138,4 +138,14 @@ function utils.signum (value) end end +-- Implements Java float modulo +function utils.mod(a, b) + if b < 0 then b = -b end + if a < 0 then + return -(-a % b) + else + return a % b + end +end + return utils