Deformable and breakable body - sample

breakable updated for svn 170,
see 1.post for download http://www.box2d.org/forum/viewtopic.php?p=4757#p4757
(all 3 files)

added
- some checks when drawing points, so shouldnt crash too fast 🙂
(>0.25 segmentlengts, and tmO_CHECKINTERSECTION)
- check if GetProxyCount()+InsideTriangles < b2_maxProxies


cheers nimodo

ps:i was asked (pn) to attach a win release executable here, so here testbed svn170 as rar compressed
This looks very interesting. Are there any plans to port this over to the Flash version?
Actually, I have no plans for porting, maybe others ?

I have no idea how to program in flash 😉, is it similar to java/c++ ?
Are there free development tools for flash ?
Similar, yes. But, there are enough differences to make it a bit of a chore to port over if you've never used Flash before.

There are plenty of open source tools out there for Flash, but, as far as I know (don't quote me), not a complete end-to-end open source work flow for AS3.
Uh-oh, sounds like it's time for... Flash Evangelist Man!

The Flex SDK contains the official command-line compiler for ActionScript 3, called MXMLC. It is free. If you want an IDE, you'll need to pay for Flex Builder, or get FlashDevelop, a free IDE for Windows (it only lacks some debugging features). At a high level, the ActionScript language is a lot like Java, though the libraries are different and the compilation process is different and the way you interact with the screen, mouse, keyboard, internet, and other devices is simplified. The online Flash library reference is terrific if you know more or less what you're looking for. There are various tutorials online to help you get started.

It is my opinion that, as long as you're not trying to push the limits of the hardware or earn any money, Flash is the best 2D game development platform for PC/Mac/Linux today.

What you CAN'T do for free is make tweening vector animations... which are what Flash is known for, actually, but those aren't really important for many Box2D projects anyway. You are still able to import bitmaps and put them on the screen, and you can programmatically draw arbitrary polygons and circles and lines, so the Flash CS3 animation authoring tool isn't useful if you're not an artist.

Some Flash programs use an additional language called MXML that is a sort of super-set of ActionScript with a separate syntax designed for GUI development. MXML is very useful, but it is not necessary if you don't want to learn it. All of the core features of the Flash platform are exposed to ActionScript. The example programs that come with Box2DFlashAS3 do not use MXML. The free MXMLC compiler that comes with the Flex SDK is what you use to compile pure ActionScript.

The example programs that come with Box2DFlashAS3 include a ".fla" project file that can only be compiled with the commercial Flash CS3 authoring tool, but it turns out you can also compile these programs just by running this on the command line:

Code: Select all

mxmlc Main.as
Thx for the flash intro - flash evangelist man 🙂

%FLEX_HOME%\bin\mxmlc Main.as gives me an swf 56317 Bytes (instead of PhysTest.swf 56369 Bytes) and some warnings (return value for function 'XYZ' has no type declaration).

%FLEX_HOME%\runtimes\player\win\FlashPlayer.exe & opening above created Main.swf
does not work, the examples are like in 'Pause' mode (nothing is going on, but example-switching) (Original PhysTest.swf works fine with FlashPlayer.exe, like in your webpage)

Idea, what I'm forgeting ? Some environmental vars ?

regards, nimodo
The .fla project contains some additional parameters that are missing when you compile straight from the source, such as the desired width and height of the program, background color, and framerate, but you can insert that information into the source of the main class as demonstrated here:
http://blog.madebyderek.com/archives/20 ... adata-tag/
I'm not sure what the problem is, but it sounds like your main loop (Main.update) isn't getting called, or isn't getting called very often. Try explicitly setting the framerate, I guess.
yes, it seems, metatags are useful if using command line compiler
For box2d [SWF(width='640', height='400', backgroundColor='#000000')] after last import statement in Main.as.

To get it work, I found changing in Test.as the floating point var
public var m_timeStep:Number = 1.0/30.0; instead of 1/30.
Seems, that the win flash compiler makes m_timeStep:Number = 1/30 = 0

- it works now 🙂
I might be missing something here, but is there a way to use this to make bodies which are breakable but solid up until they break? The breakable joints stuff seems to work well (and the triangulation seems very cool), but the fact that all the shapes in the testbed example sag as they land isn't quite what I want. I'd like to make something with crates (or whatever) that just seem like regular boxes under normal circumstances, but that can break apart or have things chipped off them when enough force is applied.

- Is there a way to construct the joints such that they'll hold everything in place properly but register how much force is being applied and can still break?

- Is it better to have bodies just be a single polygon shape initially, to be deleted and replaced with a number of smaller bodies attached by breakable joints when enough force is applied?

- Is this a suitable method for arbitrarily carving up simple shapes into a number of more complex ones on the fly, or am I better of using a method like this one (although I'm working in C++)?
ElectroDruid wrote:...is there a way to use this to make bodies which are breakable but solid up until they break?...
Yes.

An advantage breaking a body into smaller (box2d-)bodies - instead of shapes - is, that the physics engine makes the whole work for these broken parts for you.
To have something like glass (e.g. 'non'-deformable), you have to prevent relative motion between the connected parts (here triangles from the mesh) of your body, with box2d you have a lot of possibilities to achieve that.
- using combination of joints
- b2DistanceJoint with the same anchor point, turning off frequency / damping coefficients
- prevent rotation of bodies
.....

A disadvantage might be performance, depending on what you want to to.

Original thread: https://box2d.org/forum/viewtopic.php?t=836