Game Development Reference
In-Depth Information
can push them onto and pop them from a stack. The ID3DXMatrixStack helps us
do exactly that as the scene graph is being traversed.
The next data member is the actor map. This is an STL map that relates unique actor
IDs (really just a plain old unsigned integer) with a particular scene node. This is
necessary when the scene graph needs to change a scene node based on an ActorId .
A good example of this is when the physics system bounces something around. Since
the physics system doesn
t know or care anything about a pointer to a scene node, it
will inform game subsystems of the bouncing via an event with an ActorId . When
the scene graph hears about it, it uses the ActorId to find the right scene node to
manipulate.
The final data member is for a light manager to manage a list of lights that illuminate
the scene. These lights inherit from SceneNode to add information about how the
light illuminates objects. You ' ll learn about the LightNode class a little later in the
'
Putting Lights in Your Scene
section of this chapter.
Here
'
s the implementation of the Scene class:
Scene::Scene()
{
m_Root.reset(GCC_NEW RootNode());
m_LightManager = GCC_NEW LightManager;
D3DXCreateMatrixStack(0, &m_MatrixStack);
}
Scene::~Scene()
{
SAFE_RELEASE(m_MatrixStack);
SAFE_DELETE(m_LightManager);
}
The constructor and destructor are simple enough. They simply manage the creation
and release of the root node, the DirectX matrix stack object, and the LightMana-
ger . The other data structures have default constructors and are managed by smart
pointers, so there is a little more happening here behind the scene. Yes, that was a
terrible pun, but I
'
m not sorry.
Let
'
s now look at OnRender() , OnRestore() , and OnUpdate() :
HRESULT Scene::OnRender()
{
if (m_Root && m_Camera)
{
// The scene root could be anything, but it
 
Search WWH ::




Custom Search