your-own-drum/mousecontrols.lua

37 lines
740 B
Lua

local mouseControl = { isActive = false }
local love = love
local x, y = 0, 0
local DECAY = 0.8
local SENSITIVITY = 0.8
function mouseControl.Reset()
x, y = 0, 0
end
function mouseControl.mousemoved( dx, dy )
dx, dy = SENSITIVITY * dx, SENSITIVITY * dy
dx, dy = dx * dx * dx , dy * dy * dy
x, y = dx + x, y - dy
return mouseControl.getAcceleration()
end
function mouseControl.update()
local norm = math.sqrt( x * x + y * y )
local decay = DECAY * norm / ( norm + 1 )
x, y = decay * x, decay * y
end
function mouseControl.getAcceleration()
local norm = math.sqrt( x * x + y * y )
if norm > 1 then return x / norm, y / norm end
if norm < 0.001 then return 0, 0 end
return x, y
end
return mouseControl