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 JadeWin::MoveFrame() Function

The MoveFrame() function is a callback function that manages the mesh’s animation. The function appears below:

void JadeWin::MoveFrame(LPDIRECT3DRMFRAME frame, void*, D3DVALUE)
{
    static int x;
    static int y;
    static int xi=7;
    static int yi=13;
    if (x<-31 || x>31)
        xi=-xi;
    if (y<-35 || y>35)
        yi=-yi;
    x+=xi;
    y+=yi;
    frame->SetOrientation( NULL,
            D3DVALUE(x), D3DVALUE(y), D3DVALUE(50),
            D3DVALUE(0), D3DVALUE(1), D3DVALUE(0) );
}

The MoveFrame() function uses a simple “bouncing ball” algorithm to reorient the frame that the mesh is attached to for each screen update. The static integers are used to track the frame’s position, and calculate new positions. Once a new position has been calculated, it is assigned to the frame with the Direct3DRMFrame SetOrientation() function.

The JadeWin Render Functions

The Jade demo (like most of the demos on the CD-ROM) allows the mesh’s render method to be changed during the program’s execution. This functionality is provided by the OnRenderWireframe(), OnRenderFlat(), and OnRenderGouraud() functions are invoked by MFC when the Render menu entries are selected. These three functions look like this:

void JadeWin::OnRenderWireframe()
{
    if (meshbuilder)
        meshbuilder->SetQuality( D3DRMRENDER_WIREFRAME );
}

void JadeWin::OnRenderFlat()
{
    if (meshbuilder)
        meshbuilder->SetQuality( D3DRMRENDER_FLAT );
}

void JadeWin::OnRenderGouraud()
{
    if (meshbuilder)
        meshbuilder->SetQuality( D3DRMRENDER_GOURAUD );
}

Each function uses the Direct3DRMMeshBuilder SetQuality() to specify a rendering method. Three more functions are required to properly enable and disable the check marks that appear to the left of the currently active rendering method on the Render menu. The OnUpdateRenderFlat(), OnUpdateRenderGouraud(), and OnUpdateRenderWireframe() functions look this way:

void JadeWin::OnUpdateRenderWireframe(CCmdUI* pCmdUI)
{
    if (meshbuilder)
    {
        D3DRMRENDERQUALITY meshquality = meshbuilder->GetQuality();
        pCmdUI->SetCheck( meshquality==D3DRMRENDER_WIREFRAME );
    }
}

void JadeWin::OnUpdateRenderFlat(CCmdUI* pCmdUI)
{
    if (meshbuilder)
    {
        D3DRMRENDERQUALITY meshquality = meshbuilder->GetQuality();
        pCmdUI->SetCheck( meshquality==D3DRMRENDER_FLAT );
    }
}

void JadeWin::OnUpdateRenderGouraud(CCmdUI* pCmdUI)
{
    if (meshbuilder)
    {
        D3DRMRENDERQUALITY meshquality = meshbuilder->GetQuality();
        pCmdUI->SetCheck( meshquality==D3DRMRENDER_GOURAUD );
    }
}

MFC calls all three of these functions whenever it is about to display the Render menu. Each function checks the mesh’s current settings and indicates to MFC whether the check mark for a particular menu entry should be enabled.

Almost all of the demos on the CD-ROM support menus such as the Render menu. Menu support functions such as these can be added and removed from projects with the Visual C++ ClassWizard.

Texture Wraps

The Jade demo uses a flat texture wrap. Direct3D supports two additional wrap methods: cylindrical and spherical. A cylindrical texture wrap method attempts to bend the texture in one direction, bringing two opposite edges of the texture together. A spherical texture wrap method attempts to bend a texture in such a way that the texture forms a sphere. The use of the word “attempt” is appropriate here because, as you will see, these wrapping methods are only approximations.

The Wraps Demo

The Wraps demo displays three meshes: a cube, a cylinder, and a sphere. A single texture is applied to each mesh, but the texture wrapping method is adjustable. By default, a flat wrap is used on the cube, a cylindrical wrap is used on the cylinder, and a spherical wrap is used on the sphere. The demo provides menu options that let you specify which wrap type is used on the meshes. The Wraps demo is shown in Figure 5.5.


Figure 5.5  The Wraps demo.

The Wraps demo uses a modified version of the texture used by the Jade demo. Lines have been drawn across the texture to illustrate the manner in which the texture has been applied. The modified texture is shown in Figure 5.6.


Figure 5.6  The texture used by the Wraps demo.

The Wraps demo demonstrates the following techniques:

  Loading and displaying multiple meshes.
  Applying arbitrary wraps to a mesh at runtime. The Wraps menu lets you change the texture wrapping method for the objects during the program’s execution.


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.