Box2D 3 Released For Easy Powerful Physics
Written by Harry Fairhead   
Wednesday, 21 August 2024

Box2D is a 2D physics engine and if that sounds boring you just need to look at some examples to see that it isn't. It can be the basis of impressive graphics demos and the heart of many a sophisticated game. And it's fun. So what more do you want?

Box2D is a well regarded physics engine created by Erin Catto back in 2006 and released under an MIT licence. It is featured in many games, but perhaps the best known is Angry Birds. In 2008 version 2.0 was launched. By 2020, it had reached version 2.4 and now in 2024 we have version 3 with lots of improvements.

One of the paths not taken is that the engine is still in good old C, C11 to be precise.  Catto considered the pros and cons of moving to  C++ or another language and came down on the side of sticking with C. I agree that C is the best choice for this sort of high performance computation. It would be easy to waste a lot of time trying to figure out how to divide up the library into classes and very easy to make the whole thing less efficient. It also makes intergrating with other languages easier - everything interworks with C. This said, the new version makes use of threading and SIMD so you are going to need to take care in porting it to another enviroment.

Another interesting change is the dropping of raw pointers for  ids, probably what would be called a handle in other applications:

b2BodyDef bodyDef = b2DefaultBodyDef();
bodyDef.position = (b2Vec2){10.0f, 5.0f};
b2BodyId myBodyId = b2CreateBody(myWorldId, &bodyDef);

The idea is that this reduces the chance of trying to free a freed pointer, etc. Well I guess its cheaper than moving to Rust.

Other improvments include: a better solver, improved precision, updated joint support, and its twice as fast as v2.4.

To see what Box2D can do see the video:

Well I'm impressed and really want to give it a try. If you feel the same way then to get started you simply download the C code from GitHub. To save some disappointment, I should point out that Box2D is a physics engine and not a render engine. What this means is that, as far as Box2D is concerned, an object is just coordinates and it will work out how these move in relation to gravity, forces, collsions and so on, but it is up to you to draw the object at the location it provides. The demos and samples are not just Box2D. In general, they draw the objects to make things look nice.

box2dicon

More Information

https://github.com/erincatto/box2d

Releasing Box2D 3.0

Related Articles

Getting Started with Box2D in JavaScript

Box2D Benchmarks Show Everything Is Getting Faster

Dart Does Physics - Just To Prove It Can!

JavaScript Physics Playground       

Tearable Cloth In JavaScript

PhysicsJS - Physics In Pure JavaScript

Google's LiquidFun For Fluid Simulation

To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.

 

Banner


Second Gen Robot Dog On Kickstarter
15/09/2024

We covered Mini-Pupper's launch back in 2021 and now there is an even better, second generation, of this low-cost and capable quadruped robot. If you want to see what AI can bring to a small robot, th [ ... ]



MariaDB Introduces Vector Search
22/08/2024

The MariaDB Foundation has announced a preview version of MariaDB 11.6 Vector. The new functionality is described as being a result of collaborative work by employees of MariaDB plc, MariaDB Foundatio [ ... ]


More News

kotlin book

 

Comments




or email your comment to: comments@i-programmer.info

Last Updated ( Wednesday, 21 August 2024 )