Box2D C++ tutorials - Setting up (Mac OSX)
Last edited: July 14 2013Chinese version -> 中文
Building the testbed (Mac OSX)
Let's look at the process of setting up the default 'testbed' which is part of the Box2d source code base. The testbed is a very useful tool which contains examples of various features which you can interact with using the mouse, adjust parameters, pause and step the simulation etc.
The simplest way to build the Box2D library is to use the cmake file which is included in the source code download. For this you will need the cmake tool, which you can download from here, and XCode which you can download from Apple's developer site (developer.apple.com) after you have registered. When installing cmake be sure to choose the 'Install command line links' option so you can use the tool in a terminal. Since we'll be using cmake, all we really need for compiling is the gcc compiler itself, but apparently it is not distributed as a single tool so you'll need to get the whole XCode package (somebody let me know if I'm wrong about that). XCode is also available on the Snow Leopard DVD if you have one.
After installing XCode and cmake, download the Box2D source code archive from here. The rest of the process is the same as for linux:
unzip Box2D_v2.1.2.zipAfter this you should see that some new folders have been created, one of which is 'Testbed' and this in turn contains an executable file called 'Testbed', so the app can be started like this:
cd Box2D_v2.1.2/Box2D/Build
cmake ..
make
cd TestbedYou should see the testbed window showing like this:
./Testbed

Testbed features
Apart from the obvious features visible in the right hand control panel, the testbed also allows you to:
- Move the view around - arrow keys or drag with right mouse button
- Zoom the view - z,x keys
- Grab objects in the scene - left mouse button
- Launch a bomb into the scene from a random location - space bar
- Launch a bullet into the scene - drag left mouse button while holding shift, then let go