In the previous chapter you learned something about how to draw 3D geometry, but there's a lot more to a 3D game than drawing a few triangles. Even a relatively boring 3D game has characters, interesting environments, dynamic objects, and a few special effects here and there.
In a way, this chapter brings many concepts and source code that you've seen throughout the book together in one piece. I'm not going to fool you into thinking that by the end of this chapter you'll have the beginnings of a game that will beat the pants off of Bungie's Halo—one of my favorite games by the way. You will, however, develop the knowledge on how a prototype for a 3D game engine gets its start. With any luck you'll end this chapter with a healthy respect for the programmers that build 3D engines.
If you haven't done it already, create a new Direct X 9 Visual C++ project, and if you want your code to look just like mine, call the project SceneGraph. The code I'll be presenting in this chapter will plug straight into the project the DirectX 9 wizard spits out. When you create the project, make sure you create a single document window, and clear the checkboxes for everything except Direct3D. The project will be a little cleaner and we can concentrate on Direct3D.
When the project is created, follow these steps:
Open SceneGraph.h, and delete all references to m_UserInput, m_fWorldRotX, m_fWorldRotY, m_pD3DXMesh and void UpdateInput( UserInput* pUserInput ).
Recompile and fix all the errors. When you run your project you should see nothing but a blank blue field with yellow text.
Using your favorite paint program and the DirectX Texture Tool; create a Grid.dds file into a new Textures directory. It should be a 128x128 texture, with a black outline and a white background.
Use the smart pointer class described in Chapter 3. Put it in a SmartPtr.h file.
Now you are ready to create a scene graph based 3D engine, using the DirectX renderer.