ShapeEditor

About ShapeEditor

Type: External tool
License: BSD License
Supported platforms:

   

Categories:
  • Graphics
  • Level design
  • Physics
  • Utilities and Tools

ShapeEditor is an app for create collision shapes.

Code example:

--[[ manual:
- click on vertice - select it;
- double click on vertice - delete it. 
]]

-- settings:
-- init.lua
-- anchor point of image
apx = 0.5
apy = 0.5
-- patterns for data output
pattern1 = "{x = %.5f, y = %.5f}," -- for polygon
pattern2 = "{{x = %.5f, y = %.5f}, {x = %.5f, y = %.5f}, {x = %.5f, y = %.5f},}," -- for triangles

-- using (hit test point with polygon):
function inPolygon(p, v)
	local c = 0
	local x0 = v[#v].x - p.x
	local y0 = v[#v].y - p.y
	for i = 1, #v do
		local x1 = v[i].x - p.x
		local y1 = v[i].y - p.y
		if (y0 > 0 and y1 <= 0 and x1 * y0 > y1 * x0) or (y1 > 0 and y0 <= 0 and x0 * y1 > y0 * x1) then
			c = c + 1
		end
		x0 = x1
		y0 = y1
	end
	return (c % 2) == 1
end