An attempt at breakable bodies.

Well, I don't know how to start this. This was a rather quick attempt at creating breakable bodies, without using joints, or having to specify places where the object can break. Rather, whenever the object is struck by another object hard enough in some specific place, the object is broken at that place.

WASD pans the camera, left click allows objects to be dragged around, right click fires a bullet which should break the breakable body (which is the dark red one), mouse wheel zooms in and out.

The file test.poly allows any polygon to be used, if edited, provided it has at most 1 hole. Self intersecting polygons are allowed. The format is as specified on this page: http://www.cs.man.ac.uk/~toby/alan/software/gpc.html

You may need to add
Code:
#include <cstring>

to b2Settings.h for it to compile (as memcpy is included in there), I did.
And you may need to add
Code:
#include <cstdio>

to b2Polygon.h (from convex decomposition).

You'll need cmake, Box2D, OpenGL and the SFML libraries to compile it. CMakeLists.txt looks for Box2D in breakable/box2d, and looks for the box2d library in box2d/Box2D/Build/Box2D, so you might have to modify CMakeLists.txt.

I haven't compiled this on Windows, but it should work on it. If anyone really wants, I might be able to build a windows executable.

Additionally, Erin Catto et al., thanks for all your hard work on Box2D.

*EDIT: You may occassionally an error along the lines of "Assertion failed, m_I > 0.0f". I don't know how to fix this, however, I think it may have something to do with numerical inaccuracy for very small polygons.

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