![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Cutting Edge Direct 3D Programming
The MorphPlayWin::CreateScene() FunctionThe MorphPlayWin::CreateScene() function looks like this: BOOL MorphPlayWin::CreateScene() { // --------DIRECTIONAL 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->AddLight( dlight ); lightframe->AddLight( alight ); lightframe->SetOrientation( scene, D3DVALUE(0), D3DVALUE(-1), D3DVALUE(1), D3DVALUE(0), D3DVALUE(1), D3DVALUE(0)); alight->Release(); alight=0; dlight->Release(); dlight=0; lightframe->Release(); lightframe=0; //------ CAMERA---------- d3drm->CreateFrame( scene, &camera ); camera->SetPosition( scene, D3DVALUE(0), D3DVALUE(0), D3DVALUE(-50)); d3drm->CreateViewport( device, camera, 0, 0, device->GetWidth(), device->GetHeight(), &viewport); return TRUE; } Unlike most of the other CreateScene() functions that weve looked at in this book, the MorphPlayWin version performs just two steps. The first step is creating two light sources. The second step is creating a viewport. Because we havent added any visual objects to the scene, the demo displays an empty window when it is first executed. The File|Open menu command must be used to load a morph sequence. The MorphPlayWin::OnFileOpen() FunctionSelecting the File|Open menu entry causes MFC to invoke the OnFileOpen() function. The function looks like this: void MorphPlayWin::OnFileOpen() { static char BASED_CODE filter[] = "Morph Files (*.mrf)|*.mrf|X Files (*.x)|*.x||"; CFileDialog opendialog( TRUE, 0, 0, OFN_FILEMUSTEXIST, filter, this ); if ( opendialog.DoModal() == IDOK ) { CString filename = opendialog.GetPathName(); CWaitCursor cur; InitMorphSequence( filename ); } } The function uses the MFC CFileDialog class to present a file selection dialog that lists only MRF and X files. If the user selects or enters a file name, the InitMorphSequence() function is called with the file name as an argument. The MorphPlayWin::InitMorphSequence() FunctionThe InitMorphSequence() function uses member functions inherited from the MorphWin class to initiate a new morph sequence: BOOL MorphPlayWin::InitMorphSequence( const CString& filename ) { if (frame) frame->DeleteVisual( mesh ); else { d3drm->CreateFrame( scene, &frame ); frame->AddMoveCallback( UpdateDrag, NULL ); frame->AddMoveCallback( UpdateMorph, this ); } if (LoadMorphSequence( filename )==FALSE) return FALSE; DWORD targets=GetNumMorphTargets(); for (DWORD i=0;i<targets;i++) AddMorphKey( i, D3DVALUE(i) ); maxmorphtime=D3DVALUE(targets-1); morphtime=D3DVALUE(0.0); mesh=GetMorphMesh(); mesh->SetGroupColorRGB( 0, D3DVALUE(.67), D3DVALUE(.82), D3DVALUE(.94) ); frame->AddVisual( mesh ); return TRUE; } The function first checks the frame data member. If the frame pointer is not initialized, the function creates a new frame and installs two callback functions: UpdateDrag() and UpdateMorph(). If the frame pointer was initialized by a previous call, the current mesh is removed from the scene with the Direct3DRMFrame DeleteVisual() function. Next, the LoadMorphSequence() function is called. If the LoadMorphSequence() function fails (returns FALSE), the InitMorphSequence function returns immediately. Next, a loop is used to install a morph key for each morph target. Also, the maxmorphtime and morphtime data members are initialized. Finally, a pointer to the newly created morph mesh is retrieved with the MorphWin::GetMorphMesh() function. The color of the mesh is modified, and the mesh is added to the scene.
|
![]() |
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. |