A Tale of Three Modules
Box2D has three modules, the Common Module, which contains some low-
level code and data structures, the Collision Module, which contains code
and data structures for collision detection and response, and the Dynamics
Module, which contains code and data structures for the Physics World.
The body of this chapter is divided into three sections, one per module.
Section 6.1 will delve fairly deeply into the Common Module, since (in
addition to its use throughout Box2D) it is a useful toolkit that can save
you lots of programming time reinventing the wheel. Section 6.3 contains
an introduction to the Collision Module at a deep enough level for you to
get started writing a game. More details are available later in Chapter 8 if
you need them. Section 6.5 introduces the Dynamics Module.
The Box2D source-code folder contains, among other things, three fold-
ers corresponding to the three modules, conveniently named Common, Colli
sion,andDynamics. After poking about for a while, you will ﬁnd that the
overall structure of the ﬁles and folders in Box2D is as shown in Figure 6.1.
Fortunately, there is more structure here than meets the eye. Each mod-
ule is made up of various components, as illustrated in Figure 6.2. This
chapter and the next one will focus on the light gray components.
• 6.1 The Common Module
The Common Module contains code for some low-level things such as mem-
ory allocation and a math library. My ﬁrst thought when I saw this was
“Oh no! Not another math library!” but there is a good reason for this
one. Box2D is designed to be cross-platform, spanning devices that are