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


Spotlights

Spotlights produce light in the shape of a cone. The light’s position decides the location of the tip of the cone, and the light’s orientation decides the location of the base of the cone.

Actually, the light that a spotlight produces is better described in terms of two cones: an outer cone and an inner cone. The outer cone determines the area that the spotlight is capable of illuminating. No light falls outside of the outer cone. The inner cone determines the area that receives the light’s full illumination. The area between these two cones experiences a gradually fading illumination—from full illumination near the inner cone, to no illumination near the outer cone.

The inner cone is called the umbra cone. The umbra cone size is determined by the umbra angle. The outer cone is called the penumbra cone. The penumbra cone size is determined by the penumbra angle. The umbra and penumbra cones are illustrated in Figure 6.8.


Figure 6.8  The anatomy of a spotlight.

The Direct3DRMLight interface provides these member functions for the adjustment and inspection of the umbra and penumbra angles:

  GetPenumbra()
  GetUmbra()
  SetPenumbra()
  SetUmbra()

The Spotlight Demo

The Spotlight demo animates a spotlight over three spherical meshes. The spotlight’s umbra and penumbra angles can be adjusted with the Spotlight demo’s Beam menu. The Spotlight demo appears in Figure 6.9.


Figure 6.9  The Spotlight demo.

The Spotlight demo demonstrates the following techniques:

  Using the spotlight light source type
  Using a callback to animate a light source
  Using the Direct3DRMMesh interface to avoid extra overhead associated with the Direct3DRMMeshBuilder interface
  Changing Direct3DRMMesh rendering quality settings at runtime
  Changing spotlight umbra and penumbra settings at runtime

The Spotlight demo uses the Direct3DRMMesh interface instead of the Direct3DRMMeshBuilder interface to demonstrate alternatives to the way that the other demos are written. There is nothing exceptional about the Spotlight demo that requires the added performance benefits that come with the Direct3DRMMesh interface.

The SpotlightWin Class

The Spotlight demo uses the RMWin class as a base class for its SpotlightWin class:

class SpotlightWin : public RMWin
{
public:
    SpotlightWin();
    BOOL CreateScene();
protected:
    //{{AFX_MSG(SpotlightWin)
    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 OnBeamNormal();
    afx_msg void OnBeamNarrow();
    afx_msg void OnBeamWide();
    afx_msg void OnUpdateBeamNormal(CCmdUI* pCmdUI);
    afx_msg void OnUpdateBeamNarrow(CCmdUI* pCmdUI);
    afx_msg void OnUpdateBeamWide(CCmdUI* pCmdUI);
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
private:
    static void MoveLight(LPDIRECT3DRMFRAME frame, void* arg,
        D3DVALUE delta);
private:
    LPDIRECT3DRMMESH mesh1, mesh2, mesh3;
    LPDIRECT3DRMLIGHT spotlight;
    int beamwidth;
};

The SpotlightWin class definition looks quite a bit different than the class definitions for the other demos that we’ve looked at in this chapter. The first and most obvious difference is that there are more protected member functions. The first six protected functions are familiar from the other demos and are used to implement the demo’s Render menu. The new functions are used to implement the demo’s Beam menu. We’ll look at these functions later.

Another difference is the presence of the MoveLight() function declaration. MoveLight() is a callback function that we will use to animate the spotlight.

The class’s data members are also different. The previous class definitions used a single Direct3DRMMeshBuilder pointer. The SpotlightWin class declares three pointers to the Direct3DRMMesh interface. These pointers are used to access the three sphere meshes used in the demo.

The class also declares a Direct3DRMLight pointer. This pointer is used by the member functions that implement the Beam menu. These functions also use the beamwidth data member to store the current spotlight settings.


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.