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 AmbientLight Demo Render Functions

One of the features that the Direct3D AppWizard puts into a project (whether you ask for it or not) is a Render menu that allows the mesh’s rendering method to be changed during the program’s execution. When we looked at the AmbientLightWin class definition, we saw declarations for the six member functions that provide this functionality. The OnRenderWireframe(), OnRenderFlat(), and OnRenderGouraud() functions are message handlers that are called when one of the Render menu entries are selected. The functions look like this:

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

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

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

The value of the meshbuilder pointer is checked in case the meshbuilder pointer has not been initialized. If it has, the Direct3DRMMeshBuilder SetQuality() function changes the render method (or quality) of the mesh.

The remaining three member functions, OnUpdateRenderFlat(), OnUpdateRenderGouraud(), and OnUpdateRenderWireframe(), are called whenever Windows is about to display the Render menu. These functions are used to activate the check mark that appears to the left of the currently active menu entry. The functions look like this:

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

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

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

Each of these three functions uses the Direct3DRMMeshBuilder GetQuality() function to retrieve the mesh’s current rendering methods. The rendering method is then used to determine if the menu selection’s check mark should be enabled. Using a comparison that is TRUE as an argument to the SetCheck() function enables the check mark.

These six member functions are present, in some form, in most of the demos on the CD-ROM.

Point Lights

A point light is a light source that emits light in all directions from a single location. Point lights are similar to the light sources that we are accustomed to in the real world, such as light bulbs. The familiar behavior of point lights make them a natural choice for many situations. Point lights are affected by their location but ignore orientation (a point light’s orientation is meaningless because light is cast in all directions).

Unfortunately, the point light’s ease of use and familiar behavior is offset by a performance hit. Because point lights cast light in every conceivable direction, more calculation is necessary to render scenes that contain point lights.

The Firefly Demo

The Firefly demo uses a point light to illuminate a chalice. The chalice is placed at the origin, and the point light is animated around the chalice. For visual effect, a small spherical mesh is animated along with the light source, creating the illusion that the sphere (the firefly) is emitting light and illuminating the chalice. Remember that the sphere is added only for visual effect. You cannot see a point light (or any other light source)—you can only see the light that it emits. The Firefly demo appears in Figure 6.4.


Figure 6.4  The Firefly demo.

If you run the Firefly demo, you’ll be able to see that the light’s position affects the way that the chalice is illuminated. Use the Render menu to change the rendering method. Notice that in wireframe mode, the light has no effect.

The Firefly demo demonstrates the following techniques:

  Using a point light
  Representing a light source with a mesh
  Using multiple rendering methods in the same scene
  Performing animation with dummy frames

We’ll talk about each of these techniques as we walk through the Firefly code.

The FireflyWin Class

The majority of the Firefly demo’s functionality is provided by the FireflyWin class. The FireflyWin class is derived from the RMWin class and is defined as follows:

class FireflyWin : public RMWin
{
public:
    FireflyWin();
    BOOL CreateScene();
protected:
    //{{AFX_MSG(FireflyWin)
    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
    DECLARE_MESSAGE_MAP()
private:
    LPDIRECT3DRMMESHBUILDER chalicebuilder;
};

The FireflyWin class declared two public member functions: a constructor and the CreateScene() function. The constructor assigns zero to the chalicebuilder data member:

FireflyWin::FireflyWin()
{
    chalicebuilder=0;
}

The six protected member functions provide support for the Firefly demo’s Render menu.


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.