Examples and tutorials » Box2D

A simple example using the Box2D physics library.

Image

Builds a pyramid out of cubes and allows you to expand or destroy it by adding more. Uses the SceneGraph library directly with Box2D and renders everything in a single draw call using instanced Shaders::FlatGL.

Key controls

  • mouse click adds a cube to cursor position

Credits

This example was originally contributed by Michal Mikula.

Source

Full source code is linked below and also available in the magnum-examples GitHub repository. This example depends on the Box2D library which you need to install separately; additionally you need to put FindBox2D.cmake into your modules/ directory.

The ports branch contains additional patches for Emscripten support that aren't present in master in order to keep the example code as simple as possible.