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 Spotlight Demo Beam Functions

The Spotlight demo provides a Beam menu which allows the spotlight’s umbra and penumbra angles to be modified. The six member functions that provide this functionality follow:

void SpotlightWin::OnBeamNormal()
{
    spotlight->SetUmbra( D3DVALUE(0.2) );
    spotlight->SetPenumbra( D3DVALUE(0.4) );
    beamwidth=BEAM_NORMAL;
}

void SpotlightWin::OnBeamNarrow()
{
    spotlight->SetUmbra( D3DVALUE(0.1) );
    spotlight->SetPenumbra( D3DVALUE(0.2) );
    beamwidth=BEAM_NARROW;
}

void SpotlightWin::OnBeamWide()
{
    spotlight->SetUmbra( D3DVALUE(0.4) );
    spotlight->SetPenumbra( D3DVALUE(0.8) );
    beamwidth=BEAM_WIDE;
}

void SpotlightWin::OnUpdateBeamNormal(CCmdUI* pCmdUI)
{
    pCmdUI->SetCheck( beamwidth==BEAM_NORMAL );
}

void SpotlightWin::OnUpdateBeamNarrow(CCmdUI* pCmdUI)
{
    pCmdUI->SetCheck( beamwidth==BEAM_NARROW );
}

void SpotlightWin::OnUpdateBeamWide(CCmdUI* pCmdUI)
{
    pCmdUI->SetCheck( beamwidth==BEAM_WIDE );
}

One of the first three member functions is called when an entry on the Beam menu is selected. The SetUmbra() and SetPenumbra() functions are used to modify the spotlight’s characteristics. Also, the beamwidth data member is assigned according to which set of spotlight settings is currently in effect. This data member is used by the second three member functions to activate a check mark for the current spotlight settings.

Multiple Light Sources

The demos that we’ve looked at so far in this chapter are each intended to familiarize you with a specific light source type. Each demo uses one light source to clearly illustrate the light source’s qualities.

This does not mean, however, that you can’t use more than one light source in your programs. Light sources can be used in any combination, and programs can use multiple instances of the same light source type as well.

Shadows

This chapter is titled Light Sources And Shadows, and we’ve talked about the five light source types that Direct3D supports, so it’s time to talk about shadows.

Before we begin, however, it should be pointed out that in Direct3D, light sources and shadows have little to do with each other. In Direct3D, a shadow is an object that can be inserted into a scene to approximate the behavior of a real shadow.

The Shadow Demo

The Shadow demo creates a scene where a fork is hovering above a rectangular platform. A light source illuminates the fork and the platform, and the fork’s shadow is cast onto the platform (or seems to be). The Shadow demo appears in Figure 6.10.


Figure 6.10  The Shadow demo.

The Shadow demo demonstrates the following techniques:

  Using the Direct3DRMShadow interface
  Using a callback function to modify the characteristics of an animation during program execution
  Generating random vectors with the D3DRMVectorRandom() function

The ShadowWin Class

The bulk of the Shadow demo’s functionality is provided by the ShadowWin class:

class ShadowWin : public RMWin
{
public:
    ShadowWin();
    BOOL CreateScene();
protected:
    //{{AFX_MSG(ShadowWin)
    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:
    static void AdjustSpin(LPDIRECT3DRMFRAME frame, void*, D3DVALUE);
private:
    LPDIRECT3DRMMESHBUILDER floorbuilder;
    LPDIRECT3DRMMESHBUILDER forkbuilder;
};

The class provides two public member functions: a constructor and the CreateScene() function. It also declares the six Render menu functions that appear in the other demos.

The AdjustSpin() function is a callback function that will be used to change the fork’s movement as the demo executes. The callback function is installed by the CreateScene() function.

Finally, two data members are declared. Both data members are pointers to the Direct3DRMMeshBuilder interface. The pointers will be used during scene creation and by the Render menu message handler functions.


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.