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:
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?
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!
I think Dax Phyz has both 2D and soft bodies.
If you are only looking for deformation, I would suggest to use a polygon model (trimesh) where I would catch collisions callbacks to the rigidbody that represents that shape. Upon the colliding point I would determine the amount of deformation caused to one or several vertices.
For un-deformation I would suggest that each timestep you should iterate through your deformed points and try to push them outwards. I guess the query could be done through very small sphere-queries in your collision world. That would also require that you keep a "maximum" undeformed position.
This method would be fairly simple to implement although it wouldn't be a "soft body" which could be what you are looking for. http://chriscavanagh.wordpress.com/2008/06/24/silverlight-soft-body-physics/ seems to be an implementation that gives out source code that you might want to look into.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With