Polygon made from mouse clicks
Posted: Thu Aug 09, 2012 6:13 am
Hello, im trying to make a polygon from the user clicks, but i cant figure out how to do it correctly.
Here is what i did.
Here is what i did.
Code: Select all
function love.mousepressed(x, y, button)
if button == 'l' then
if(first == true) then
first = false
fx = x
fy = y
end
table.insert(points,{px = x-fx,py = y-fy})
elseif button == 'r' then
local pol = {}
for i=0,# points,2 do
pol[i] = points[i].px
pol[i+1] = points[i].py
end
-- pol is the table with the array to draw the polygon
points = {}
end