Game Development Reference
In-Depth Information
Tip
As an interesting side note, Bullet uses a concept called Single Instruction,
Multiple Data ( SIMD ) on some platforms, which makes the ability to run the
same instruction on multiple pieces of data very rapid. In order to use this, the
objects must be aligned in memory in steps of 16 bytes, and an STL vector does
not naturally do this.
However, there is a built-in object type in Bullet called btAlignedObjectAr-
ray , which functions similarly to an STL vector and is worth exploring if you
wish to make use of performance enhancements like SIMD in the future. Iterating
through a large list of game objects and performing updates on them is a perfect
situation to apply this technique.
Creating our objects
With our new system in place, we can introduce a new function to handle the creation
of a GameObject for us. This function can be examined in the chapter's source
code, but to summarize, it gathers the shape, mass, color, position, and rotation of
the object we want to create, generates a new GameObject for it, and adds it to our
dynamic array. As long as GameObject remains in the array, it will be automatically
rendered in each step, greatly simplifying the act of adding new objects.
With this new function, we easily create our original box with the following call:
CreateGameObject(new
btBoxShape(btVector3(1,1,1)), 1.0,
btVector3(1.0f, 0.2f, 0.2f), btVector3(0.0f,
10.0f, 0.0f));
But, we can create two new objects with two more calls, and the majority of the work
is taken care of by GameObject , RenderScene() , and DrawShape() .
// create a ground plane
CreateGameObject(new
Search WWH ::




Custom Search