Box2D Forums

It is currently Tue May 21, 2013 11:51 pm

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Tue Jun 12, 2012 5:31 am 
Offline

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
Screen Shot 2012-06-12 at 14.21.45.png [ 54.58 KiB | Viewed 648 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
Screen Shot 2012-06-12 at 14.21.50.png [ 44.78 KiB | Viewed 648 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
Screen Shot 2012-06-12 at 14.22.02.png [ 18.46 KiB | Viewed 648 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
 Profile  
 
PostPosted: Tue Jun 12, 2012 6:01 am 
Offline

Joined: Tue Jun 24, 2008 8:25 pm
Posts: 1515
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/ChaosReef/videos
http://www.youtube.com/user/TomorrowPlusX/videos
http://www.youtube.com/user/slembcke/videos (this is chipmunk, but the principle is the same)


Top
 Profile  
 
PostPosted: Tue Jun 12, 2012 6:14 am 
Offline

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
 Profile  
 
PostPosted: Sat Aug 11, 2012 5:56 pm 
Offline

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
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 3 guests


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

Search for:
Powered by phpBB® Forum Software © phpBB Group