c++physicsbox2dpointphysics-engine

Non-Rigid Body 2D Physics Engines in C++


I'm trying to experiment with 2D physics engines in C++. So far, it seems the most popular is Box2D. Unfortunately, Box2D is a rigid body physics engine and that's not really going to help me with what I want to try.

I want to be able to define a shape which has a number of vertices joined by springs, such that when this shape collides with rigid or other non-rigid shapes its shape will be flexible.

Now I've tried to think of ways of doing this in Box2D using only rigid bodies, but there always seems to be flaws:

  1. Use rectangles or line segments for the outer edges of the flexible shape. These will collide with other shapes. Unfortunately, they are not springy, so the desired effect would not be seen.
  2. Each vertex of the shape could be a body with its own small circular shape. These bodies can then be joined together by springs. This would work great in terms of the deformation of the shape, but imagine if the shape landed on a rigid spike and the spike just passed between the vertices. Then the shape would become stuck on the spike.

So what is the best way to do this kind of physics in C++? Preferably without having to write an entire physics engine. Maybe I'm just missing a feature of Box2D. Maybe it's just not the right choice. Then what is the right choice?


Solution

  • There are several packages/engines out there that support deformable/soft bodies. If you want something free you can for example check out Phyz, SOFA or Bullet.

    There is a detailed listing on wikipedia. Most of these are 3D-based but you can adapt them to a 2D model by setting up the scene as a plane.

    Happy coding!