[lua] Fix modulo usage in AnimationState, closes #798

This commit is contained in:
badlogic 2016-12-08 13:24:39 +01:00
parent e2d76037d8
commit 168186f170
2 changed files with 12 additions and 1 deletions

View File

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

View File

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