vrld / HC

General purpose collision detection library for the use with LÖVE.
http://hc.readthedocs.org/
404 stars 48 forks source link

Pass table to addPolygon rather than list of points #32

Closed codinghands closed 10 years ago

codinghands commented 10 years ago

Is it possible to modify HC so that addPolygon takes a table of points, rather than a long list of numbers? I'm trying to create a polygon with > 100 points and the values are contained within a table.

camoy commented 10 years ago

You can always flatten the table and then unpack it into addPolygon.

local pts = {{1, 2}, {3, 4}, ...}
local pts_ = {}
for i,v in ipairs(pts) do
    table.insert(pts_, v[1])
    table.insert(pts_, v[2])
end
local shape = HC:addPolygon(unpack(pts_))
codinghands commented 10 years ago

I completely forgot about

unpack

Thanks!

vrld commented 10 years ago

Yes, unpack() is the way to go. However, 100 vertices sounds like an awful lot for a collision shape and will probably slow down the detection. Do you really need all of those points or can the shape be simplified?

codinghands commented 10 years ago

It's to represent an arc, like http://imgur.com/6GygUrl. I've tried to simplify it as much as possible (in game it's represented by a LOVE 'Mesh', with a Polygon shape used for collision detection, and this seemed to me to be the best way. Though if you have any thoughts on other methods I'd be very interested to hear them :)