Game Development Reference
In-Depth Information
use to store the objects such as our GameObject . A simple STL vector should be
sufficient for this task:
typedef std::vector<GameObject*> GameObjects;
GameObjects m_objects;
This allows us to refer to our vector using a custom GameObjects type, instead of
using the ugly namespace/template combination each time.
Consequently this allows us to replace our main rendering code with the following:
void BulletOpenGLApplication::RenderScene() {
// create an array of 16 floats (representing
a 4x4 matrix)
btScalar transform[16];
// iterate through all of the objects in our
world
for(GameObjects::iterator i =
m_objects.begin(); i != m_objects.end(); ++i) {
// get the object from the iterator
GameObject* pObj = *i;
// read the transform
pObj->GetTransform(transform);
// get data from the object and draw it
DrawShape(transform, pObj->GetShape(),
pObj->GetColor());
}
}
Having our objects stored in a data structure like this provides a lot more flexibility to
add new objects to our scene without undue effort.
Search WWH ::




Custom Search