![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Cutting Edge Direct 3D Programming
The fifth step is the creation of two frames that we will use to animate the light source and the spherical mesh: LPDIRECT3DRMFRAME dummyframe; d3drm->CreateFrame( scene, &dummyframe ); dummyframe->SetRotation( scene, D3DVALUE(0), D3DVALUE(1), D3DVALUE(0), D3DVALUE(.08) ); LPDIRECT3DRMFRAME lightframe; d3drm->CreateFrame( dummyframe, &lightframe ); lightframe->SetPosition( dummyframe, D3DVAL(15), D3DVAL(6), D3DVAL(0) ); lightframe->AddLight( pointlight ); lightframe->AddVisual( flybuilder ); flybuilder->Release(); flybuilder=0; lightframe->Release(); lightframe=0; dummyframe->Release(); dummyframe=0; pointlight->Release(); pointlight=0; The dummyframe pointer is initialized with the Direct3DRM CreateFrame() function and is a child of the scenes root frame (scene). The new frame is given a rotation around the Y axis. This will cause any child frames (such as the frame that is created next) to rotate around the Y axis. The second frame (lightframe) is created as a child of dummyframe. Then, the SetPosition() function is used to move the frame away from the origin. If we didnt move this frame away from the origin, the frame would rotate in place instead of orbiting the dummy frame. Next, both the fly mesh and the point light are attached to the lightframe frame. This ensures that both the firefly mesh and the point light will be in the same location at all times. Finally, all four of the pointers (two frame pointers, the flybuilder pointer, and the pointlight pointer) are released and assigned zero. The remainder of the FireflyWin::CreateScene() function (Listing 6.2) creates the demos viewport. Well study viewports in detail in Chapter 9. Directional LightsDirectional lights are the opposite of point lights. While a point light has a location but no orientation, a directional light has orientation but no location. Directional lights produce light rays that are parallel, so there is no single point where the light originates. Directional lights are useful for representing distant light sources such as the sun. Because all of the rays in a directional light are parallel, less calculation is necessary to render scenes that contain directional lights. Directional lights are more efficient than point lights because all of the light rays travel in the same direction. The SpaceStation DemoBecause directional lights are best suited for representing distant light sources, well use space as the setting for our next demo. The SpaceStation demo displays a space station and illuminates it with a directional light. The SpaceStation demo appears in Figure 6.5.
The SpaceStation demo demonstrates the following techniques:
The SpaceStationWin ClassThe bulk of the SpaceStation demos functionality is provided by the SpaceStationWin class. The class definition looks like this: class SpaceStationWin : public RMWin { public: SpaceStationWin(); BOOL CreateScene(); protected: //{{AFX_MSG(SpaceStationWin) 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 meshbuilder; }; The SpaceStationWin class declares two public member functions: a constructor and the CreateScene() function. The constructor assigns zero to the meshbuilder data member: SpaceStationWin::SpaceStationWin() { meshbuilder=0; } The six protected member functions provide support for the SpaceStation demos Render menu. The private meshbuilder pointer is used by the protected member functions to modify the meshs settings.
|
![]() |
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. |