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 WrapsWin Class

The bulk to the Wraps demo’s functionality is provided by the WrapsWin class. The class definition look like this:

class WrapsWin : public RMWin
{
public:
    WrapsWin();
    BOOL CreateScene();
protected:
    //{{AFX_MSG(WrapsWin)
    afx_msg void OnWrapsFlat();
    afx_msg void OnWrapsCylinder();
    afx_msg void OnWrapsSphere();
    afx_msg void OnWrapsReset();
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
private:
    BOOL LoadMeshes();
    BOOL LoadTexture();
    void ApplyWraps();
    void ApplyFlat( LPDIRECT3DRMMESHBUILDER );
    void ApplyCylinder( LPDIRECT3DRMMESHBUILDER );
    void ApplySphere( LPDIRECT3DRMMESHBUILDER );
private:
    LPDIRECT3DRMMESHBUILDER box;
    LPDIRECT3DRMMESHBUILDER cyl;
    LPDIRECT3DRMMESHBUILDER sphere;
    D3DRMWRAPTYPE boxwraptype;
    D3DRMWRAPTYPE cylwraptype;
    D3DRMWRAPTYPE spherewraptype;
};

Like the JadeWin class, the WrapsWin class provides two public member functions: a constructor and a CreateScene() function. The constructor is used to initialize the class’s data members. The CreateScene() function constructs the demo’s scene. We’ll look at the CreateScene() function soon.

The Wraps demo doesn’t support a Render menu, but it does support a Wraps menu. The Wraps menu lets the user select what type of texture wrap methods that are to be used. Four protected member functions are declared by the WrapsWin class to support the Wraps menu functionality: OnWrapsFlat(), OnWrapsCylinder(), OnWrapsSphere(), and OnWrapsReset().

Six private member functions are declared. The LoadMeshes() and LoadTexture() functions are used to simplify the CreateScene() function. The remaining four functions are used to change the texture wrap settings during the demo’s execution.

Finally six private data members are declared. The box, cyl, and sphere data members are pointers to the Direct3DRMMeshBuilder interface. They will be used to access the three meshes in the scene. The remaining three data members are used to indicate which texture wrap method is to be used on each of the three meshes.

The WrapsWin::CreateScene() Function

Let’s look at the code for the Wraps demo. As with all the demos in this book, the demo uses the RMWin class as a base class and adds functionality by overriding the CreateScene() function. The Wraps demo declares the WrapsWin class, and the CreateScene() function is responsible for loading the three meshes that appear in the demo. Because this demo is a little more complicated than the code we’ve looked at previously, CreateScene() doles out much is its work to “helper” functions. The CreateScene() function for the Wraps demo appears below.

BOOL WrapsWin::CreateScene()
{
    //-------- MESHES AND TEXTURES --------
    if (LoadMeshes()==FALSE)
        return FALSE;
    if (LoadWrapsTexture()==FALSE)
        return FALSE;

    OnWrapsReset();

    //--------- LIGHT ----------
    LPDIRECT3DRMFRAME lightframe;
    LPDIRECT3DRMLIGHT light;
    d3drm->CreateLightRGB(D3DRMLIGHT_AMBIENT,
            D3DVALUE(1),D3DVALUE(1), D3DVALUE(1),
            &light);
    d3drm->CreateFrame( scene, &lightframe );
    lightframe->AddLight( light );
    lightframe->Release();
    lightframe=0;
    light->Release();
    light=0;

    //---------- CAMERA ------------
    d3drm->CreateFrame( scene, &camera );
    camera->SetPosition(scene,
            D3DVALUE(0.0), D3DVALUE(0.0), D3DVALUE(-50));
    d3drm->CreateViewport( device, camera, 0, 0,
            device->GetWidth(), device->GetHeight(),
            &viewport );

    return TRUE;
}

The CreateScene() function performs three steps:

1.  Creation and configuration of the meshes, textures, and texture wraps
2.  Creation and configuration of a light source
3.  Creation and placement of the program’s viewport

The CreateScene() function creates and initializes the meshes, textures, and texture wraps by calling the LoadMeshes(), LoadWrapsTexture(), and OnWrapsReset() functions. As the name implies, the LoadMeshes() function loads the three meshes that the demo uses. LoadMeshes() is also responsible for the creation and placement of the frames to which the meshes will be attached. The LoadWrapsTexture() function loads the texture that will be applied to all three meshes.

The OnWrapsReset() function serves two purposes. It is used here in the CreateScene() function to initialize the program’s settings, and it is an event handler that gets called whenever you select the Reset option from the Wraps menu.

The LoadMeshes(), LoadWrapsTexture(), and OnWrapsReset() functions do most of the work for the Wraps demo and deserve a closer look.


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.