# Box2D Forums

 It is currently Fri May 24, 2013 8:25 pm

 All times are UTC - 8 hours [ DST ]

 Page 1 of 1 [ 4 posts ]
 Print view Previous topic | Next topic
Author Message
 Post subject: Deformable shapes - polygon subtraction? Or... ?Posted: Tue Jun 12, 2012 5:31 am

Joined: Tue May 01, 2012 10:41 pm
Posts: 11
Hi,

I'm looking for a way to deform the physic shapes.

Say I have a game character standing on a very simple b2body, consisting of one fixture made of edges:
Attachment:
File comment: Digging the ground

Screen Shot 2012-06-12 at 14.21.45.png [ 54.58 KiB | Viewed 654 times ]

The player wants to dig a hole (like in Lemmings, Lode Runner, etc.). I imagined substracting a "dig" round shape from the ground shape:
Attachment:
File comment: Dig shape

Screen Shot 2012-06-12 at 14.21.50.png [ 44.78 KiB | Viewed 654 times ]

The childish formulation of this would be "substract the circle from the rectangle and keep the resulting polygon":
Attachment:
File comment: Resulting polygon

Screen Shot 2012-06-12 at 14.22.02.png [ 18.46 KiB | Viewed 654 times ]

Two questions now...
- Is there anything like this in Box2D?
- (if not) am I making any sense imagining this would be a great solution?

Of course, if you know about a method to accomplish the same result as pictured in my (splendid) drawings... I'll be very glad to hear about it!

edit: I see the following on Wikipedia: http://en.wikipedia.org/wiki/Constructi ... d_geometry seems what I'm trying to achieve has a name Actually willing to get the red box minus blue sphere result. In 2D. And in Box2D

Thanks a lot,
J.

Top

 Post subject: Re: Deformable shapes - polygon subtraction? Or... ?Posted: Tue Jun 12, 2012 6:01 am

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1517
Location: Tokyo
I think the typical way to handle this would be to make the ground from a chain shape. That way, you can just move/add vertices in the chain. These people have done a fine job of it, maybe you could get some inspiration or advice from them:
http://www.youtube.com/user/slembcke/videos (this is chipmunk, but the principle is the same)

Top

 Post subject: Re: Deformable shapes - polygon subtraction? Or... ?Posted: Tue Jun 12, 2012 6:14 am

Joined: Tue May 01, 2012 10:41 pm
Posts: 11
Hey thanks for the hints. All three examples are very impressive out there... Had seen Slembcke's works earlier today... I want to stick with Box2D though

I'll begin with the source code Slembcke made available... Will share anything useful I'll make out of it!

Top

 Post subject: Re: Deformable shapes - polygon subtraction? Or... ?Posted: Sat Aug 11, 2012 5:56 pm

Joined: Sat Aug 11, 2012 5:48 pm
Posts: 1
I've had very good results with Clipper: http://www.angusj.com/delphi/clipper.php

Took me less than a day to create destructible 2d terrain. Here is what I did:
- Represent your terrain with polygons
- Triangulate them for rendering (http://code.google.com/p/poly2tri/)
- Build a box2d edge shape for collision detection using those polygons
- Subtract from your terrain with Clipper library (clip type of 'Difference') -> results in a new list of polygons
- Re-triangulate and rebuild the edge shape with the new polygons

Hope that helps!

- Shlomo

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 1 [ 4 posts ]

 All times are UTC - 8 hours [ DST ]

#### Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 1 guest

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

 Search for: