Page 1 of 1

Inside out shape

Posted: Thu Oct 13, 2011 2:48 pm
by kae
Hi.
I'm trying to make a shape which are solid on the inside. Small balls inside one big one (like a lottery ball). Circle shape is obviously not working. And the polygon shape can only have 8 vertices ? Besides, that wouldn't work either or would it? I've searched around and se people talk about edge shape, but that isnt available to love2d yet or?

Thanks,
kae.

Re: Inside out shape

Posted: Thu Oct 13, 2011 3:35 pm
by adrix89
That is because all physics libs choke on concave surfaces.
The only way I see to get it work is to have an array of rectangles in the shape of a circle but I'm not sure if it would stick together properly.

Re: Inside out shape

Posted: Thu Oct 13, 2011 3:44 pm
by slime
You generally make concave shapes by using multiple convex ones attached to the same body.

Re: Inside out shape

Posted: Thu Oct 13, 2011 5:12 pm
by ivan
Small balls inside one big one (like a lottery ball). Circle shape is obviously not working
Are you aware that a body can have multiple shapes?
kae wrote:And the polygon shape can only have 8 vertices ? Besides, that wouldn't work either or would it? I've searched around and se people talk about edge shape, but that isnt available to love2d yet or?
By default, Box2D only supports (counter-clockwise) convex shapes.
adrix89 wrote:That is because all physics libs choke on concave surfaces.
The only way I see to get it work is to have an array of rectangles in the shape of a circle but I'm not sure if it would stick together properly.
Hmm, what do you mean by "all physics libs"?
As people have mentioned, the way to simulate concave shapes is to decompose them into triangles and attach them to the same body.
This can be done algorithmically using "triangulation".

Re: Inside out shape

Posted: Thu Oct 13, 2011 5:35 pm
by TechnoCat
ivan wrote:Hmm, what do you mean by "all physics libs"?
As people have mentioned, the way to simulate concave shapes is to decompose them into triangles and attach them to the same body.
This can be done algorithmically using "triangulation".
https://github.com/vrld/HardonCollider/ ... n.lua#L300
vrld's Hardon Collider does concave shapes. (by splitting them into convex shapes with triangulation)

Re: Inside out shape

Posted: Thu Oct 13, 2011 5:57 pm
by The Burrito
kae wrote:Small balls inside one big one (like a lottery ball).
Like others said the best method is to make a ring of simple shapes with a single body (probably at the center). Then if you want to move the ball in any way you can just apply forces to the body and you can "open" it by deleting or turning off collision on one of the segments. It's not perfect but in most cases 16 or 32 segments should be smooth enough. Just depends on what else you want to do with it.

Re: Inside out shape

Posted: Thu Oct 13, 2011 11:33 pm
by bmelts
In LÖVE 0.8.0, you'll have access to Box2D 2.2.1, which adds ChainShape, which might well be what you're looking for - a series of EdgeShapes. Create a looped ChainShape in a circle (or something approximating it), then have smaller CircleShapes inside. ChainShapes handle collision on both sides, so this should work to keep the smaller shapes trapped inside the larger.

Re: Inside out shape

Posted: Fri Oct 14, 2011 8:36 am
by kae
Thanks for all the input. Seems like triangles is the way to go. Won't be too hard to setup either.

Looking forward to Love 0.8.0. Have been playing with Love2D, and Lua, for only two days now and find it very intuitive and fun to work with. Coming from a C/Obj-C world I've been looking at Lua from distance for a while. Glad I finally took the step :)