![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Cutting Edge Direct 3D Programming
The ZoomWin::CreateScene() FunctionThe Zoom demos scene is constructed by the CreateScene() function. The function appears in Listing 9.1. Listing 9.1 The ZoomWin::CreateScene() function. BOOL ZoomWin::CreateScene() { // ------- MESH -------- D3DRMLOADRESOURCE resinfo; resinfo.hModule=NULL; resinfo.lpName=MAKEINTRESOURCE( IDR_Z_MESH ); resinfo.lpType="MESH"; d3drm->CreateMeshBuilder( &meshbuilder ); meshbuilder->Load( &resinfo, NULL, D3DRMLOAD_FROMRESOURCE, NULL, NULL ); meshbuilder->SetColorRGB(D3DVALUE(.67), D3DVALUE(.82), D3DVALUE(.94) ); ScaleMesh( meshbuilder, D3DVALUE(25) ); // ------- MATERIAL ---------- LPDIRECT3DRMMATERIAL material; d3drm->CreateMaterial( D3DVALUE(10), &material ); meshbuilder->SetMaterial( material ); material->Release(); material=0; // ------ MESH FRAME ------ LPDIRECT3DRMFRAME meshframe; d3drm->CreateFrame( scene, &meshframe ); meshframe->SetRotation( scene, D3DVALUE(1), D3DVALUE(.4), D3DVALUE(0), D3DVALUE(.1) ); meshframe->AddVisual( meshbuilder ); meshframe->Release(); meshframe=0; // ------- ANIMATION -------- d3drm->CreateAnimation( &animation ); animation->SetOptions( D3DRMANIMATION_SPLINEPOSITION | D3DRMANIMATION_CLOSED | D3DRMANIMATION_POSITION ); animation->AddPositionKey( D3DVALUE(0), D3DVALUE(.4), D3DVALUE(0), D3DVALUE(0) ); animation->AddPositionKey( D3DVALUE(24), D3DVALUE(5), D3DVALUE(0), D3DVALUE(0) ); animation->AddPositionKey( D3DVALUE(49), D3DVALUE(1), D3DVALUE(0), D3DVALUE(0) ); animation->AddPositionKey( D3DVALUE(74), D3DVALUE(5), D3DVALUE(0), D3DVALUE(0) ); animation->AddPositionKey( D3DVALUE(99), D3DVALUE(.4), D3DVALUE(0), D3DVALUE(0) ); d3drm->CreateFrame( scene, &zoomframe ); animation->SetFrame( zoomframe ); // --------- LIGHT -------- LPDIRECT3DRMLIGHT dlight; d3drm->CreateLightRGB( D3DRMLIGHT_DIRECTIONAL, D3DVALUE(1.00), D3DVALUE(1.00), D3DVALUE(1.00), &dlight ); LPDIRECT3DRMLIGHT alight; d3drm->CreateLightRGB( D3DRMLIGHT_AMBIENT, D3DVALUE(.40), D3DVALUE(.40), D3DVALUE(.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; //------ 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 ); camera->AddMoveCallback( AdjustField, NULL ); return TRUE; } The CreateScene() function performs six steps:
The first step uses the Direct3DRMMeshBuilder interface to load a mesh from a file. Lets take a closer look: D3DRMLOADRESOURCE resinfo; resinfo.hModule=NULL; resinfo.lpName=MAKEINTRESOURCE( IDR_Z_MESH ); resinfo.lpType="MESH"; meshbuilder->Load( &resinfo, NULL, D3DRMLOAD_FROMRESOURCE, NULL, NULL ); meshbuilder->SetColorRGB(D3DVALUE(.67), D3DVALUE(.82), D3DVALUE(.94) ); ScaleMesh( meshbuilder, D3DVALUE(25) ); A D3DRMLOADRESOURCE is used to identify the resource entry that contains the mesh. The meshbuilder data member is initialized with the Direct3DRM CreateMeshBuilder() function. The Load() function is then used to load the mesh. The color of the mesh is assigned with the SetColorRGB() function. Finally, the mesh is scaled to 25 units with the ScaleMesh() function. Next, a material is applied to the mesh: LPDIRECT3DRMMATERIAL material; d3drm->CreateMaterial( D3DVALUE(10), &material ); meshbuilder->SetMaterial( material ); material->Release(); material=0; Materials allow us to fine-tune the meshs appearance by changing the behavior and color of specular highlights. In this case, we are using a material to give the mesh a shiny appearance.
The Direct3DRM CreateMaterial() function is used to create the material. The new material is applied to the mesh with the Direct3DRMMeshBuilder SetMaterial() member function. The local material pointer is then released. Step 3 is the creation of a frame for the mesh: LPDIRECT3DRMFRAME meshframe; d3drm->CreateFrame( scene, &meshframe ); meshframe->SetRotation( scene, D3DVALUE(1), D3DVALUE(.4), D3DVALUE(0), D3DVALUE(.1) ); meshframe->AddVisual( meshbuilder ); meshframe->Release(); meshframe=0;
|
![]() |
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. |