![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Cutting Edge Direct 3D Programming
The MultiViewWin::CreateScene() FunctionThe MultiView demos scene is constructed by the CreateScene() function as shown in Listing 9.4. Listing 9.4 The MultiViewWin::CreateScene() function. BOOL MultiViewWin::CreateScene() { // ------- MESH -------- D3DRMLOADRESOURCE resinfo; resinfo.hModule=NULL; resinfo.lpName=MAKEINTRESOURCE( IDR_MESH ); resinfo.lpType="MESH"; d3drm->CreateMeshBuilder( &meshbuilder ); meshbuilder->Load( &resinfo, NULL, D3DRMLOAD_FROMRESOURCE, NULL, NULL ); ScaleMesh( meshbuilder, D3DVALUE(30) ); //------- MESH FRAME ------ d3drm->CreateFrame( scene, &meshframe ); meshframe->SetRotation( scene, D3DVALUE(0), D3DVALUE(1), D3DVALUE(0), D3DVALUE(.1) ); meshframe->AddVisual( meshbuilder ); meshframe->Release(); // --------- LIGHT -------- LPDIRECT3DRMLIGHT dlight; d3drm->CreateLightRGB( D3DRMLIGHT_DIRECTIONAL, D3DVALUE(1.00), D3DVALUE(1.00), D3DVALUE(1.00), &dlight ); LPDIRECT3DRMLIGHT alight; d3drm->CreateLightRGB( D3DRMLIGHT_AMBIENT, D3DVALUE(0.40), D3DVALUE(0.40), D3DVALUE(0.40), &alight ); LPDIRECT3DRMFRAME lightframe; d3drm->CreateFrame( scene, &lightframe ); lightframe->SetOrientation( scene, D3DVALUE(0), D3DVALUE(-1), D3DVALUE(1), D3DVALUE(0), D3DVALUE(1), D3DVALUE(0) ); lightframe->AddLight( dlight ); lightframe->AddLight( alight ); dlight->Release(); dlight=0; alight->Release(); alight=0; lightframe->Release(); lightframe=0; return TRUE; } The CreateScene() function performs these three steps:
Notice that no viewport is created. As youll see, weve moved all of the viewport-related code to the RMWin class. The CreateScene() function prepares a scene, but doesnt specify how the scene is to be viewed. The first step is the creation of a mesh. The Direct3DRMMeshBuilder interface is used to load a mesh from the demos resources. The ScaleMesh() function is used to resize the mesh if necessary. The next step is the creation of a frame for the mesh. The frame is given a rotation attribute with the SetRotation() function and attached to the previously created mesh with the AddVisual() function. Finally, two light sources are created and added to a frame of their own. The Modified RMWin ClassThe version of the RMWin class that is employed by the MultiView demo is defined as shown in Listing 9.5. Listing 9.5 The RMWin class definition. class RMWin : public CFrameWnd { public: RMWin(); RMWin(int w,int h); BOOL Create(const CString& sTitle,int icon,int menu); void SetColorModel( D3DCOLORMODEL cm ) { colormodel=cm; } inline COLORREF D3DCOLOR_2_COLORREF(D3DCOLOR d3dclr); inline D3DCOLOR COLORREF_2_D3DCOLOR(COLORREF cref); void Render(); protected: static int GetMouseX() { return mousex; } static int GetMouseY() { return mousey; } void ScaleMesh( LPDIRECT3DRMMESHBUILDER, D3DVALUE ); protected: //{{AFX_MSG(RMWin) afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct); afx_msg void OnDestroy(); afx_msg void OnActivate(UINT state, CWnd* other, BOOL minimize); afx_msg void OnPaint(); afx_msg void OnSize(UINT type, int cx, int cy); afx_msg void OnMouseMove(UINT state, CPoint point); afx_msg BOOL OnEraseBkgnd(CDC* pDC); afx_msg void OnViewport1Disabled(); afx_msg void OnViewport1Front(); afx_msg void OnViewport1Left(); afx_msg void OnViewport1Right(); afx_msg void OnViewport1Top(); afx_msg void OnViewport2Disabled(); afx_msg void OnViewport2Front(); afx_msg void OnViewport2Left(); afx_msg void OnViewport2Right(); afx_msg void OnViewport2Top(); afx_msg void OnViewport3Disabled(); afx_msg void OnViewport3Front(); afx_msg void OnViewport3Left(); afx_msg void OnViewport3Right(); afx_msg void OnViewport3Top(); afx_msg void OnUpdateViewport1Disabled(CCmdUI* pCmdUI); afx_msg void OnUpdateViewport1Front(CCmdUI* pCmdUI); afx_msg void OnUpdateViewport1Left(CCmdUI* pCmdUI); afx_msg void OnUpdateViewport1Right(CCmdUI* pCmdUI); afx_msg void OnUpdateViewport1Top(CCmdUI* pCmdUI); afx_msg void OnUpdateViewport2Disabled(CCmdUI* pCmdUI); afx_msg void OnUpdateViewport2Front(CCmdUI* pCmdUI); afx_msg void OnUpdateViewport2Left(CCmdUI* pCmdUI); afx_msg void OnUpdateViewport2Right(CCmdUI* pCmdUI); afx_msg void OnUpdateViewport2Top(CCmdUI* pCmdUI); afx_msg void OnUpdateViewport3Disabled(CCmdUI* pCmdUI); afx_msg void OnUpdateViewport3Front(CCmdUI* pCmdUI); afx_msg void OnUpdateViewport3Left(CCmdUI* pCmdUI); afx_msg void OnUpdateViewport3Right(CCmdUI* pCmdUI); afx_msg void OnUpdateViewport3Top(CCmdUI* pCmdUI); //}}AFX_MSG DECLARE_MESSAGE_MAP() private: void Initvars(); virtual BOOL CreateScene() = 0; BOOL CreateDevice(); GUID* GetGUID(); void ConfigViewport(LPDIRECT3DRMFRAME camera, int view); void CreateViewports(); protected: static LPDIRECT3DRM d3drm; LPDIRECT3DRMFRAME scene; LPDIRECT3DRMDEVICE device; D3DCOLORMODEL colormodel; private: LPDIRECT3DRMFRAME camera1, camera2, camera3; LPDIRECT3DRMVIEWPORT viewport1, viewport2, viewport3; int view1setting, view2setting, view3setting; CRect winrect; LPDIRECTDRAWCLIPPER clipper; static int mousex; static int mousey; static UINT mousestate; friend class RMApp; }; Obviously, this is a complex class, and we wont be discussing all of the member functions in this section. Well concentrate on the portions of the class that are different from the original RMWin class. See Chapter 4 for a complete discussion of the RMWin class. Three data members have been added: camera1, camera2, and camera3. These are Direct3DRMFrame pointers that will be used to create and move the demos three viewports. The fact that these data members are declared as private tells us that classes derived from RMWin will not be expected to manipulate these pointers. This task is left solely to the RMWin class. The viewport1, viewport2, and viewport3 data members will be used to access the demos three viewports. These data members are also private, so we can expect the RMWin member functions to initialize them.
|
![]() |
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. |