![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Cutting Edge Direct 3D Programming
The AmbientLight Demo Render FunctionsOne 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 meshs rendering method to be changed during the programs 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 meshs current rendering methods. The rendering method is then used to determine if the menu selections 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 LightsA 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 lights orientation is meaningless because light is cast in all directions). Unfortunately, the point lights 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 DemoThe 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.
If you run the Firefly demo, youll be able to see that the lights 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:
Well talk about each of these techniques as we walk through the Firefly code. The FireflyWin ClassThe majority of the Firefly demos 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 demos Render menu.
|
![]() |
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. |