Game Development Reference
Rendering from transform data
We still have the problem that our DrawBox() function always draws a box at ( 0 , 0 , 0 )
in world space. Before we can make use of the data from our object's motion state,
we will have to modify our rendering system to draw our object at a given location in-
stead. In order to do this, we'll need to introduce a few more OpenGL commands.
glPushMatrix() and glPopMatrix() are another pair of OpenGL delimiter func-
tions that work together in much the same way as glBegin() and glEnd() do.
They are used to control the matrix stack , which is very helpful while drawing multiple
objects, and objects that are meant to be connected together. As mentioned previ-
ously, transformation matrices can be combined to get a resultant transformation, and
if we have multiple objects that share a similar transformation, we can optimize our
processing time by sharing information through the matrix stack, instead of recalcu-
lating the same value over and over again.
This feature is particularly useful when we have object hierarchies such as a knight
riding on top of a steed, or moons orbiting planets, which themselves orbit stars. This
is the basic concept of a Scene Graph in 3D rendering (which is beyond the scope
of this topic). The function to multiply the current matrix stack by a given matrix is
In this project, DrawBox() has been changed to collect an array of btScalars for
the transform, and uses the methods explained previously to manipulate the matrix
stack by surrounding the previous rendering code with calls to push and pop the
Note that the /*REM*/ comment tags in the source code represent code that has
been removed and/or replaced since the previous section.