![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Cutting Edge Direct 3D Programming
The CreateScene() function performs seven steps:
The first portion of the CreateScene() function is straightforward (and tedious). The 15 textures are loaded, and a pointer to each texture is stored in the texture array. Next, a cube mesh is loaded using the Direct3DRMMeshBuilder interface. The cube is scaled using the Scale() function: D3DRMLOADRESOURCE resinfo; resinfo.hModule=NULL; resinfo.lpName=MAKEINTRESOURCE( IDR_BOXMESH ); resinfo.lpType="MESH"; LPDIRECT3DRMMESHBUILDER meshbuilder; d3drm->CreateMeshBuilder( &meshbuilder ); meshbuilder->Load( &resinfo, NULL, D3DRMLOAD_FROMRESOURCE, NULL, NULL ); meshbuilder->Scale( D3DVALUE(1), D3DVALUE(1), D3DVALUE(.1) ); ScaleMesh( meshbuilder, D3DVALUE(20) ); meshbuilder->SetPerspective( TRUE ); meshbuilder->SetQuality( D3DRMRENDER_FLAT ); meshbuilder->SetTexture( texture[0] ); This is done because we want a nearly flat rectangular mesh to which we can apply the textures. Rather than create a rectangular mesh, we can use a cube with its Z dimension scaled to one-tenth its original size. The new mesh is then configured to use perspective correction and the flat rendering mode. The first texture in the texture array is associated with the new mesh. Step 3 is the creation and application of a texture wrap: D3DRMBOX box; meshbuilder->GetBox(&box); D3DVALUE width=box.max.x-box.min.x; D3DVALUE height=box.max.y-box.min.y; LPDIRECT3DRMWRAP wrap; d3drm->CreateWrap( D3DRMWRAP_FLAT, NULL, D3DVALUE(0.0), D3DVALUE(0.0), D3DVALUE(0.0), // wrap origin D3DVALUE(0.0), D3DVALUE(0.0), D3DVALUE(1.0), // z axis D3DVALUE(0.0), D3DVALUE(1.0), D3DVALUE(0.0), // y axis D3DVALUE(0.5), D3DVALUE(0.5), // origin D3DDivide(1,width),D3DDivide(1,height), // scale &wrap ); wrap->Apply( meshbuilder ); wrap->Release(); wrap=0; A flat texture wrap is created that sizes the texture to fit snugly on the mesh. The texture wrap is applied to the meshbuilder with the Apply() function. Next, the previously loaded meshbuilder is used to initialize a pointer to the Direct3DRMMesh interface: meshbuilder->CreateMesh( &mesh ); meshbuilder->Release(); meshbuilder=0; The new mesh is created with all of the settings of the meshbuilder. Next, a frame is created and the mesh is attached: LPDIRECT3DRMFRAME meshframe; d3drm->CreateFrame( scene, &meshframe ); meshframe->AddVisual( mesh ); meshframe->SetRotation( scene, D3DVALUE(0), D3DVALUE(1), D3DVALUE(0), D3DVALUE(0.05) ); meshframe->AddMoveCallback( UpdateTexture, NULL ); meshframe->Release(); meshframe=0; The new frame is given a rotation attribute around the Y axis. Also, the UpdateTexture() callback function is installed. The ShowRoom::UpdateTexture() FunctionThe UpdateTexture() callback function is responsible for installing a new texture for each screen update. The UpdateTexture() function looks like this: void ShowRoomWin::UpdateTexture(LPDIRECT3DRMFRAME frame, void*, D3DVALUE) { static UINT count; int curtex=count%15; frame->DeleteVisual( mesh ); mesh->SetGroupTexture( 0, texture[curtex] ); frame->AddVisual( mesh ); count++; } A static counter variable is used to determine which texture is to be applied to the mesh. The new texture is applied with the Direct3DRMMesh SetGroupTexture() function, but the meshbuilder must be removed from the frame and added after the SetGroupTexture() function is called. This is because the SetGroupTexture() function has no effect once a meshbuilder has been added to a frame. The Direct3DRMMesh SetGroupTexture() function is similar to the Direct3DRMMeshBuilder SetTexture() function that we used in the previous demos. The difference is that the Direct3DRMMesh interface supports groups, and the Direct3DRMMeshBuilder interface does not. A group is a set of faces than can be manipulated as a single entity. Well talk about the Direct3DRMMesh interface in more detail in Chapter 8. ConclusionThe ShowRoom demo concludes our discussion of texture mapping. As usual, you are strongly encouraged to experiment with the demosthats what theyre for. When you are finished experimenting, youll be ready to move on to the next chapter and learn all about light sources and shadows.
|
![]() |
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. |