Upcoming Events
Unite 2010
11/10 - 11/12 @ Montréal, Canada

GDC China
12/5 - 12/7 @ Shanghai, China

Asia Game Show 2010
12/24 - 12/27  

GDC 2011
2/28 - 3/4 @ San Francisco, CA

More events...
Quick Stats
38 people currently visiting GDNet.
2406 articles in the reference section.

Help us fight cancer!
Join SETI Team GDNet!
Link to us Events 4 Gamers
Intel sponsors gamedev.net search:

Contents
 Introduction
 Getting Started
 Viewport Classes
 Taking Control
 Creating the
 Document


 Source and Demo
 Printable version
 Discuss this article
 in the forums


Creating the Document

So now we have a flashy little app that doesn’t really do anything. If we were making a commercial product we’d be laughing our way to the bank by this time, but unfortunately we plan on using this tool so it’s going to have to do something. Up until this point we’ve dealt with views to a great extent, but now it’s time to put the "document" back into "document/view architecture". We’ll be looking at YourProjectNameDoc.cpp and YourProjectNameDoc.h from this point on.

Adding Data to the Document

The first (and most obvious step) is to add our data to our document class. In our case we’ll just add a model object, which will contain all the info the application needs to draw the *.md3 file. We also add some code to the constructor and destructor to handle memory allocation for the model:

Where:

CMd3Model *m_currentModel;

Is a member variable of CYourProjectNameDoc:

CYourProjectNameDoc:: CYourProjectNameDoc ()
{
  // No model has been loaded yet.
  m_currentModel = NULL;
}

CYourProjectNameDoc::~ CYourProjectNameDoc ()
{
  // If a model is currently loaded
  // delete it.
  if ( m_currentModel != NULL )
    delete m_currentModel;
}

Loading the Model

This step is fairly simple because all the message maps you need have already been created by the wizard. Simply add your loading code to the serialize method. This is also where you add code for saving, however we won’t be covering that here. The CArchive object that is passed to the method will be the file that the user is asking to load:

void CYourProjectNameDoc::Serialize(CArchive& ar)
{
  if (ar.IsStoring())
  {
    // TODO: add storing code here
  }
  else
  {
    // Load the MD3 file.

    if ( m_currentModel != NULL )
      delete m_currentModel;

    m_currentModel = new CMd3Model;
    if ( !LoadMd3( ar, m_currentModel ) )
    {
      MessageBox( NULL, "Not a valid md3 file!", "File Error!",
        MB_OK | MB_ICONERROR );
      return;
    }
  }
}

And that’s it. You can further customize this process by intersecting the menu message and applying file filters to the file dialog, etc. Refer to the accompanying source for more information on how to do this. At this point you can simply add your draw code to the RenderScene method of each of your viewports. The application document can be accessed by any of its child views with the function GetDocument. Note that I used a rather cryptic method for rendering scenes in the accompanying source. I find that method works best for me, so I included it for advanced users - however I won’t explain it here as it looks like voodoo chicken scratch ( void SetRenderFunc(void (*func) (CViewerDoc* )) { m_RenderScene = func; } ).


Everything you’ve always wanted in an *.md3 viewer, and less!

Conclusion

Despite popular opinion, creating proprietary tools for game development doesn’t have to be time consuming, tedious, or intimidating, (like writing articles on creating proprietary tools for game development). Through experience and code reuse new applications can be written in mere hours (my first MFC app took about two days to complete, my second took about two hours). Hobbyists and professionals alike no longer have an excuse to hack about, now that they have the proper tools.

Joe Houston

jhouston@agilitycom.com

If you’re interested in seeing other articles relating to this subject (picking objects/verts in 3D space, drawing marquees in 3D, etc) please let me know. I’m always interested in feedback, and I welcome all comments and corrections.