Created: January 28 2013

Combustion engine


I have often wondered whether it would be possible to simulate an internal combustion engine in Box2D, right down to the individual gas molecules burning inside the cylinder, but obviously creating such a complex beast like that in C++ code would be a time-consuming nightmare. Now that the R.U.B.E editor is on the scene, ideas like this which were previously only daydreams can step into reality.

As it turns out, it is possible. You can see the general overview in the video below, and source code is available for those interested in the nitty gritty. Fuel burning is simulated by giving small particles a very large density and velocity for a brief time. If they collide with unburned particles during this time, the unburned particles will also ignite. Other than this, there are no extra forces or impulses used to keep the engine running.

The designs in the video use a gear joint to connect the flywheel and camshaft, but it was actually possible to make this connection using fully modelled gear cogs (with meshing teeth, as in the pendulum clock) to change the rotation direction and ratio. While the engine would still run like this, it could not reach such a high rpm and the force of explosions would occasionally make the gear teeth skip a notch. Unlike the pendulum clock, keeping the gear teeth in their correct notches is critical, so when this happened the problem was unrecoverable.

Source code: iforce2d_combustionEngine-src.zip
(This uses the new motor joint so you'll need the latest version of Box2D from svn)

Binaries for Win32, Mac, Linux32 and Linux64:
iforce2d_combustionEngine-bin.zip

See the video for more details: