Game Development Reference
In-Depth Information
When a box is detected, through the BOX_SHAPE_PROXYTYPE enumerator, it gets
the appropriate size for the box, by typecasting to btBoxShape and calling
getHalfExtentsWithMargin() . This function returns the box's half size, or half
the size in each direction. This value is convenient for collision-response mathemat-
ics, and since boxes are symmetrical shapes, physics engines typically define boxes
this way.
Storing our objects
Picking the correct data structure for our needs is a matter of determining our re-
quirements and matching them to the properties of the various kinds of data struc-
tures available. Tasks such as updating/rendering require quick iteration, since there
could be a very long list of world objects we need to check through. Meanwhile, we're
not particularly worried about tasks such as random access, or insertion and deletion
since these will be fairly rare tasks to perform.
For quick iteration, you can't do much better than one of the array based data struc-
tures (of which there are many). A dynamic array or vector (not to be confused with
the 3D math variety of vector) should suit us well for our game objects. Although,
keep in mind that dynamic arrays are not the most efficient at random access, inser-
tion, or deletion.
Tip
There's a common saying in software engineering that preoptimization is the root
of all evil . Don't spend too much time thinking about the perfect data structure to
use (or heaven forbid, building it all from scratch). It's wise to just get your applic-
ation working first, then go back and optimize if and only if you find out that they
turn out to be a significant bottleneck once you begin profiling. You may find that
your choice of data structure doesn't matter at all, because there could be bigger
optimization problems popping up in areas you never even considered.
The Standard Template Library ( STL ) is a library that comes standard with most
C++ compilers, particularly Visual Studio. This library is enormous and contains
classes and tools to handle many different, common problems that C++ program-
mers come across. It also contains a collection of useful data structures that we can
Search WWH ::




Custom Search