![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Cutting Edge Direct 3D Programming
The DecalWin::CreateScene() FunctionIn contrast to the Wraps demo, all of the Decal demo functionality is provided in the CreateScene() function. The CreateScene() function creates and configures the decals, a light source, and a viewport. Because the animation in the Decal demo is accomplished with motion attributes, no callback functions are necessary. The CreateScene() function appears as Listing 5.3. Listing 5.3 The DecalWin::CreateScene() function. BOOL DecalWin::CreateScene() { //------ DECALS -------- LPDIRECT3DRMTEXTURE texture1, texture2; HRSRC texture_id; texture_id=FindResource( NULL, MAKEINTRESOURCE(IDR_TEXTURE1), "TEXTURE" ); d3drm->LoadTextureFromResource( texture_id, &texture1 ); texture1->SetDecalOrigin( 64, 64 ); texture_id=FindResource( NULL, MAKEINTRESOURCE(IDR_TEXTURE2), "TEXTURE" ); d3drm->LoadTextureFromResource( texture_id, &texture2 ); texture2->SetDecalOrigin( 64, 64 ); //-------- FRAMES -------- LPDIRECT3DRMFRAME dummyframe1; d3drm->CreateFrame( scene, &dummyframe1 ); dummyframe1->SetRotation( scene, D3DVALUE(0), D3DVALUE(1), D3DVALUE(0), D3DVALUE(0.05) ); LPDIRECT3DRMFRAME dummyframe2; d3drm->CreateFrame( scene, &dummyframe2 ); dummyframe2->SetRotation(scene, D3DVALUE(1), D3DVALUE(0), D3DVALUE(0), D3DVALUE(-0.05) ); LPDIRECT3DRMFRAME orbitframe1; d3drm->CreateFrame( dummyframe1, &orbitframe1 ); orbitframe1->SetPosition( dummyframe1, D3DVALUE(2), D3DVALUE(0), D3DVALUE(0) ); orbitframe1->AddVisual( texture1 ); LPDIRECT3DRMFRAME orbitframe2; d3drm->CreateFrame( dummyframe2, &orbitframe2 ); orbitframe2->SetPosition( dummyframe2, D3DVALUE(0), D3DVALUE(-2), D3DVALUE(0) ); orbitframe2->AddVisual( texture2 ); texture1->Release(); texture1=0; texture2->Release(); texture2=0; dummyframe1->Release(); dummyframe1=0; dummyframe2->Release(); dummyframe2=0; orbitframe1->Release(); orbitframe1=0; orbitframe2->Release(); orbitframe2=0; //--------- LIGHT -------- LPDIRECT3DRMLIGHT light; d3drm->CreateLightRGB( D3DRMLIGHT_AMBIENT, D3DVALUE(1.0),D3DVALUE(1.0), D3DVALUE(1.0), &light ); scene->AddLight( light ); light->Release(); light=0; //--------- VIEWPORT -------- d3drm->CreateFrame( scene, &camera ); camera->SetPosition( scene, D3DVALUE(0.0), D3DVALUE(0.0), D3DVALUE(-6.0) ); d3drm->CreateViewport( device, camera, 0, 0, device->GetWidth(), device->GetHeight(), &viewport ); return TRUE; } The CreateScene() function performs four steps:
The first step is loading two textures. As with most of the demos, the textures are stored as resources in the demos EXE file: LPDIRECT3DRMTEXTURE texture1, texture2; HRSRC texture_id; texture_id=FindResource( NULL, MAKEINTRESOURCE(IDR_TEXTURE1), "TEXTURE" ); d3drm->LoadTextureFromResource( texture_id, &texture1 ); texture1->SetDecalOrigin( 64, 64 ); texture_id=FindResource( NULL, MAKEINTRESOURCE(IDR_TEXTURE2), "TEXTURE" ); d3drm->LoadTextureFromResource( texture_id, &texture2 ); texture2->SetDecalOrigin( 64, 64 ); After the each texture is loaded, the SetDecalOrigin() function is called. The SetDecalOrigin() function is used to determine the location within the texture that will serve as the textures origin. By default, a textures upper-left-hand corner is the origin (x=0, y=0), meaning that when a texture is attached to a frame, the upper-left-hand corner of the texture appears at the frames location. The size of the two textures that the Decal demo uses is 128 by 128. Using the value 64 as arguments to the SetDecalOrigin() function places the textures origin in the center of the texture. Next, the demos frames (both dummy and non-dummy) are created: LPDIRECT3DRMFRAME dummyframe1; d3drm->CreateFrame( scene, &dummyframe1 ); dummyframe1->SetRotation( scene, D3DVALUE(0), D3DVALUE(1), D3DVALUE(0), D3DVALUE(0.05) ); LPDIRECT3DRMFRAME dummyframe2; d3drm->CreateFrame( scene, &dummyframe2 ); dummyframe2->SetRotation(scene, D3DVALUE(1), D3DVALUE(0), D3DVALUE(0), D3DVALUE(-0.05) ); LPDIRECT3DRMFRAME orbitframe1; d3drm->CreateFrame( dummyframe1, &orbitframe1 ); orbitframe1->SetPosition( dummyframe1, D3DVALUE(2), D3DVALUE(0), D3DVALUE(0) ); orbitframe1->AddVisual( texture1 ); LPDIRECT3DRMFRAME orbitframe2; d3drm->CreateFrame( dummyframe2, &orbitframe2 ); orbitframe2->SetPosition( dummyframe2, D3DVALUE(0), D3DVALUE(-2), D3DVALUE(0) ); orbitframe2->AddVisual( texture2 ); Each dummy frame is given a rotation with the SetRotation() function but is not moved from its original location (the origin). The orbiting frames are positioned away from the dummy frames with the SetPosition() function. Notice that the dummy frames are children of the scene frame (the root of the frame hierarchy), and the orbiting frames are children of the dummy frames. The previously created textures are attached to the orbiting frames with the AddVisual() function. The fact that the textures are attached directly to the frames is what makes them decals. Steps 3 and 4 create a light source and viewport for the Decal demo. The code is very similar to the code that we saw in the Jade demo. Youll learn more about light sources and viewports later in this book.
|
![]() |
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. |