your-own-drum/mousecontrols.lua

25 lines
492 B
Lua
Raw Normal View History

local mouseControl = {}
local love = love
local t = love.timer.getTime()
function mouseControl.Reset()
t = love.timer.getTime()
end
function mouseControl.mousemoved( dx, dy )
local dt = love.timer.getTime()
if dt - t < 1 / 1000.0 then return end
dt, t = dt - t, dt
dx, dy = dx * dt, -dy * dt
local norm = math.sqrt( dx * dx + dy * dy )
if norm > 1 then dx, dy = dx / norm, dy / norm end
if norm < 0.01 then return 0, 0 end
return dx, dy
end
return mouseControl