![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Cutting Edge Direct 3D Programming
The ShadowWin::CreateScene() FunctionThe scene is created by the CreateScene() function, which appears in Listing 6.6. Listing 6.6 The ShadowWin::CreateScene() function. //------------- FLOOR MESH -------- D3DRMLOADRESOURCE resinfo;resinfo.hModule=NULL; resinfo.lpName=MAKEINTRESOURCE( IDR_CUBEMESH ); resinfo.lpType="MESH"; d3drm->CreateMeshBuilder( &floorbuilder ); floorbuilder->Load( &resinfo, NULL, D3DRMLOAD_FROMRESOURCE, NULL, NULL ); floorbuilder->Scale( D3DVALUE(5), D3DVALUE(.05), D3DVALUE(5) ); floorbuilder->SetPerspective( TRUE ); floorbuilder->SetQuality( D3DRMRENDER_FLAT ); //------------ FLOOR TEXTURE -------------- LPDIRECT3DRMTEXTURE texture; HRSRC texture_id = FindResource( NULL, MAKEINTRESOURCE(IDR_FLOORTEXTURE), "TEXTURE" ); d3drm->LoadTextureFromResource( texture_id, &texture ); floorbuilder->SetTexture( texture ); texture->Release(); texture=0; //------------ FLOOR WRAP ------------ D3DRMBOX box; floorbuilder->GetBox( &box ); D3DVALUE w=box.max.x-box.min.x; D3DVALUE h=box.max.z-box.min.z; LPDIRECT3DRMWRAP wrap; d3drm->CreateWrap( D3DRMWRAP_FLAT, NULL, D3DVALUE(0.0), D3DVALUE(0.0), D3DVALUE(0.0), // wrap origin D3DVALUE(0.0), D3DVALUE(1.0), D3DVALUE(0.0), // wrap z axis D3DVALUE(0.0), D3DVALUE(0.0), D3DVALUE(1.0), // wrap y axis D3DVALUE(.5) ,D3DVALUE(0.5), // texture origin D3DDivide(1,w), D3DDivide(1,h), // texture scale &wrap ); wrap->Apply( floorbuilder ); wrap->Release(); wrap=0; //------------- FLOOR FRAME ---------- LPDIRECT3DRMFRAME floorframe; d3drm->CreateFrame( scene, &floorframe ); floorframe->AddVisual( floorbuilder ); floorframe->Release(); floorframe=0; //---------------- FORK MESH -------- resinfo.hModule=NULL; resinfo.lpName=MAKEINTRESOURCE( IDR_FORKMESH ); resinfo.lpType="MESH"; d3drm->CreateMeshBuilder( &forkbuilder ); forkbuilder->Load( &resinfo, NULL, D3DRMLOAD_FROMRESOURCE, NULL, NULL ); forkbuilder->SetQuality( D3DRMRENDER_FLAT ); //--------------- FORK FRAME ---------- LPDIRECT3DRMFRAME forkframe; d3drm->CreateFrame( scene, &forkframe ); forkframe->SetRotation( scene, D3DVALUE(1), D3DVALUE(1), D3DVALUE(1), D3DVALUE(0.4) ); forkframe->SetPosition( scene, D3DVALUE(0), D3DVALUE(6), D3DVALUE(0) ); forkframe->AddVisual( forkbuilder ); forkframe->AddMoveCallback( AdjustSpin, NULL ); //-------------- AMBIENT LIGHT -------- LPDIRECT3DRMLIGHT ambientlight; d3drm->CreateLightRGB( D3DRMLIGHT_AMBIENT, D3DVALUE(1),D3DVALUE(1), D3DVALUE(1), &ambientlight ); scene->AddLight( ambientlight ); ambientlight->Release(); ambientlight=0; //-------------- POINT LIGHT ---------- LPDIRECT3DRMLIGHT pointlight; d3drm->CreateLightRGB( D3DRMLIGHT_POINT, D3DVALUE(1),D3DVALUE(1), D3DVALUE(1), &pointlight ); LPDIRECT3DRMFRAME lightframe; d3drm->CreateFrame( scene, &lightframe ); lightframe->SetPosition( scene, D3DVALUE(0), D3DVALUE(30), D3DVALUE(0) ); lightframe->AddLight( pointlight ); lightframe->Release(); lightframe=0; //-------------- SHADOW ---------- LPDIRECT3DRMVISUAL shadow; d3drm->CreateShadow( forkbuilder, pointlight, D3DVALUE(0), box.max.y+D3DVALUE(0.1), D3DVALUE(0), D3DVALUE(0), box.max.y+D3DVALUE(1.0), D3DVALUE(0), (LPDIRECT3DRMVISUAL*)&shadow ); forkframe->AddVisual( shadow ); shadow->Release(); shadow=0; forkframe->Release(); forkframe=0; pointlight->Release(); pointlight=0; //------------- VIEWPORT -------- d3drm->CreateFrame( scene, &camera ); camera->SetPosition( scene, D3DVALUE(0.0), D3DVALUE(25.0), D3DVALUE(-20.0) ); camera->SetOrientation( scene, D3DVALUE(0), D3DVALUE(-25), D3DVALUE(20), D3DVALUE(.1), D3DVALUE(1), D3DVALUE(0) ); d3drm->CreateViewport( device, camera, 0, 0, device->GetWidth(), device->GetHeight(), &viewport ); return TRUE; } The CreateScene() function constructs the scene in 10 short steps:
Lets start with Step 1, creating the floor mesh: D3DRMLOADRESOURCE resinfo; resinfo.hModule=NULL; resinfo.lpName=MAKEINTRESOURCE( IDR_CUBEMESH ); resinfo.lpType="MESH"; d3drm->CreateMeshBuilder( &floorbuilder ); floorbuilder->Load( &resinfo, NULL, D3DRMLOAD_FROMRESOURCE, NULL, NULL ); floorbuilder->Scale( D3DVALUE(5), D3DVALUE(.05), D3DVALUE(5) ); floorbuilder->SetPerspective( TRUE ); floorbuilder->SetQuality( D3DRMRENDER_FLAT ); A cube shaped mesh is used to represent the floor. The mesh is loaded with the Direct3DRMMeshBuilder Load() function, and then the mesh is flattened out with the Scale() function. Perspective correction is enabled for the mesh, and the meshs rendering method is specified as flat. The next step is the loading of a texture that will be applied to the floor mesh: LPDIRECT3DRMTEXTURE texture; HRSRC texture_id = FindResource( NULL, MAKEINTRESOURCE(IDR_FLOORTEXTURE), "TEXTURE" ); d3drm->LoadTextureFromResource( texture_id, &texture ); floorbuilder->SetTexture( texture ); texture->Release(); texture=0; A value that identifies the mesh is created with the Win32 FindResource() function. The texture is then loaded with the LoadTextureFromResource() function and associated with the previously created meshbuilder using the SetTexture() function. The texture pointer is released after it has been used.
|
![]() |
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. |