Game Development Reference
In-Depth Information
Figure 13-2 . Convex and concave shapes
Defining the vertices of a convex shape in a counterclockwise fashion can be illustrated
by drawing a convex shape in your mind. You place one vertex anywhere and then go
left to place another. Then go down and to the right, and you will have drawn a rect-
angle in a counterclockwise fashion. Or place another vertex and then go right, up, and
then left, and you will have drawn a counterclockwise shape. It doesn't matter where
you start with the first vertex, but it's very important to follow the counterclockwise
orientation of vertices.
Fortunately, if you're working with PhysicsEditor, you don't have to care about poly-
gon vertex order (orientation) or whether the polygon is convex or concave. PhysicsEd-
itor automatically takes care of that for you transparently. PhysicsEditor splits concave
shapes into one or more convex shapes. The physics objects loader shipped with Phys-
icsEditor then assigns all the shapes to a single Box2D body. It's still good practice to
try to avoid shapes being split in order to have as few collision shapes per body as pos-
sible to get the best performance.
Tip How do you know if you made a mistake and accidentally created a
clockwise-oriented or concave collision shape? Well, every physics engine re-
acts differently. Some will tell you up front by throwing an error. But in the
case of Box2D, if a moving body hits a collision shape that is not well formed,
the moving body will simply stop moving when it gets close to that shape. If
you ever see that effect happening in your Box2D game, check the nearby colli-
sion polygons.
Working with PhysicsEditor
Search Nedrilad ::

Custom Search