perhaps something like this?
http://www.blackpawn.com/texts/pointinpoly/default.html
here’s an untested solution for the Barycentric Technique in Lua:
[lua]-- triangle coordinates
local x1, y1 = 3,4
local x2, y2 = 6,0
local x3, y3 = 0,0
function isPointInsideTriangle(x, y)
if (fAB()*fBC()>0 and fBC()*fCA()>0) then
return true
else
return false
end
end
function fAB()
return ((y-y1) * (x2-x1) - (x-x1) * (y2-y1))
end
function fBC()
return ((y-y2) *(x3-x2) - (x-x2) * (y3-y2))
end
function fCA()
return ((y-y3) * (x1-x3) - (x-x3) * (y1-y3))
end
– onTouch listener for your circle
local function onTouch(event)
if event.phase == “began” then
display.getCurrentStage():setFocus( event.target, event.id )
event.target.isFocus = true
elseif event.phase == “moved” and event.target.isFocus then
– this is where you do the actual check
if(isPointInsideTriangle(event.x, event.y)then
event.target.x = event.x
event.target.y = event.y
end
elseif event.target.isFocus then
if event.phase == “ended” or event.phase == “cancelled” then
display.getCurrentStage():setFocus( nil, event.id )
event.target.isFocus = false
end
end
return true
end[/lua]
If I wasn’t getting ready for work in a little bit, I’d throw together a more complete Lua example. But that should def. get you started. [import]uid: 49447 topic_id: 17752 reply_id: 67717[/import]