Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Cutting Edge Direct 3D Programming
(Publisher: The Coriolis Group)
Author(s): Stan Trujillo
ISBN: 1576100502
Publication Date: 11/01/96

Bookmark It

Search this book:
 
Previous Table of Contents Next


The OnFileSave() function also uses the CFileDialog class, but uses different constants with the dialog class constructor. The OFN_HIDEREADONLY constant indicates that the “Open as Read Only” check box should not be displayed. The OFN_OVERWRITEPROMPT constant causes the dialog to require a confirmation when overwriting existing files.

The DoModal() function is used to execute the dialog. If the IDOK constant is returned, the current mesh is saved. The CWaitCursor class is used to display the hourglass mouse cursor during the save operation. The name of the file that is to be created or overwritten is retrieved with the GetPathName() function. Next, the mesh is returned to its original size. The restorescale value is calculated so that it negates the scale operation that the mesh underwent when it was loaded. The Direct3DRMMeshBuilder Scale() function is used to scale the mesh according to the restorescale value. The mesh is saved using the Save() member function. Then, the mesh is returned to its previous size. Skipping this last step might cause the displayed mesh to become huge or microscopic following a save operation.

Using Multiple Viewports

All of the demos that we’ve looked at in this book have used a single viewport to view a scene. This works fine for most applications, but multiple viewports can be used to view a single scene from multiple vantage points.

The MultiView Demo

The MultiView demo displays a single rotating mesh, but three viewports are used to view the mesh. The demo provides menus that allow you to configure and disable each viewport. The demo also allows external meshes to be loaded. The MultiView demo appears in Figure 9.4.


Figure 9.4  The MultiView demo.

The MultiView demo demonstrates the following techniques:

  Using multiple viewports in a single application
  Using menu options to configure a viewport’s position
  Using MFC’s CFileDialog class to implement File|Open functionality

The MultiView Code

The MultiView demo is written differently than the other demos on the CD-ROM. All of the demos use RMWin as a base class for an application specific class. Most of the demos use identical versions of RMWin, but the MultiView demo uses a modified version.

The version of the RMWin class that is used by the MultiView demo contains support for three viewports. This requires that many of the RMWin member functions be modified. Our discussion of the MultiView code will, therefore, involve both the RMWin class and the MultiViewWin class.

The MultiViewWin Class

Some (but not all) of the MultiView demo’s functionality is provided by the MultiViewWin class:

class MultiViewWin : public RMWin
{
public:
    MultiViewWin();
    BOOL CreateScene();
protected:
    //{{AFX_MSG(MultiViewWin)
    afx_msg void OnRenderWireframe();
    afx_msg void OnRenderFlat();
    afx_msg void OnRenderGouraud();
    afx_msg void OnUpdateRenderFlat(CCmdUI* pCmdUI);
    afx_msg void OnUpdateRenderGouraud(CCmdUI* pCmdUI);
    afx_msg void OnUpdateRenderWireframe(CCmdUI* pCmdUI);
    afx_msg void OnFileOpen();
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
private:
    LPDIRECT3DRMMESHBUILDER meshbuilder;
    LPDIRECT3DRMFRAME meshframe;
};

The class declares two public member functions: a constructor and the CreateScene() function. The constructor initializes the class’s two data members. The CreateScene() function constructs the demo’s scene but differs from the other demos on the CD-ROM because it does not create any viewports. We’ll look at CreateScene() soon.

Seven protected member functions are declared. Six are the Render menu message handlers that appear in many of the demos. The seventh is a message handler for the File|Open menu selection. We’ll use this function to display a file dialog and load selected meshes from disk.

The two data members are pointers that will be used to access the demo’s single mesh and the frame to which it is attached.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited.