How can I build a ellipse shape by Chipmunk?

Discuss new features and future development.
Post Reply
hugozerken
Posts: 1
Joined: Thu Feb 24, 2011 8:10 am
Contact:

How can I build a ellipse shape by Chipmunk?

Post by hugozerken »

I am new to Chipmunk :)
ndizazzo
Posts: 15
Joined: Thu Feb 10, 2011 7:53 pm
Contact:

Re: How can I build a ellipse shape by Chipmunk?

Post by ndizazzo »

Approximate it with segments
corin
Posts: 4
Joined: Sat Mar 26, 2011 10:44 am
Contact:

Re: How can I build a ellipse shape by Chipmunk?

Post by corin »

Would it be better to use a polygon instead of line segments? What are the pros and cons?
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: How can I build a ellipse shape by Chipmunk?

Post by slembcke »

If the ellipse is static, line segments will probably be more efficient and allow you to make a smother shape. Because line segments don't collide with other line segments, it's better to make an ellipse using a polygon if you want it to be active.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Baxnie
Posts: 9
Joined: Fri May 10, 2013 7:54 pm
Contact:

Re: How can I build a ellipse shape by Chipmunk?

Post by Baxnie »

Sorry to up such an old topic, but i couldn't find it anywhere.
Will ellipses be supported by chipmunk's further versions?
I'm tempted to try to add it, however i've got absolutely no idea about its complexity.
Is it worth to give it a try?

Thanks
LegoCylon
Posts: 29
Joined: Wed May 09, 2012 12:06 am
Contact:

Re: How can I build a ellipse shape by Chipmunk?

Post by LegoCylon »

I think line segment or polygon approximation is still your best bet unless you're constructing a really large number of them. You can also do beveled line segments with semi-circular endcaps (just define a line segment with a radius > 0).

If your shapes are small or fast moving the approximation shouldn't really be noticeable. I'd suggest trying it out at least before you plow forward with what could be quite a lot of work.

FYI segment-to-segment collisions are now detectable (I believe by default). If you use them, you may also want to call cpSegmentShapeSetNeighbors to ignore collisions in the "cracks" between segments.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: How can I build a ellipse shape by Chipmunk?

Post by slembcke »

Analytic collisions between ellipses isn't so bad, but colliding them with other shapes gets more tricky. AFAIK, there isn't a good way to do a collision between an elipse and a polygon without doing it approximately. The new GJK based collision code could handle that ok with a bunch of tweaks, but it would still probably be almost as slow as using a polygon shape. All you would be saving is memory since the shape would be sampled as needed. It would add a lot of extra complexity though, which is why I've never been keen on implementing it.

The next best thing then is just to make a rough polygon approximation of it (6-10 verts is probably good) and use the beveling radius to smooth out the vertexes. You'll be able to get pretty close really.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests