![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Cutting Edge Direct 3D Programming
Constructing ScenesAt this point, weve initialized the standard Direct3D interfaces. The steps weve discussed are performed by RMApp and RMWin. The next step is to create a scene. The CreateScene() FunctionWhen we were looking at the CreateDevice() function, we learned that one of the last things that CreateDevice() does is call the CreateScene() function. The CreateScene() function is declared as a pure virtual member function in the RMWin class. This means that classes derived from RMWin must provide a version of CreateScene(). The CreateScene() member is responsible for the creation of any meshes, light sources, and frame hierarchies that the application will display. Before we present the CreateScene() function, we should mention that the SampleWin class inherits several important data members from the RMWin class. The CreateScene() function has access to these data members because they are declared as protected data members. These data members are:
Listing 4.3 is the CreateScene() function from our sample application. Listing 4.3 The SampleWin::CreateScene() function. BOOL SampleWin::CreateScene() { HRESULT r; // ------MESH-------- d3drm->CreateMeshBuilder( &meshbuilder ); r=meshbuilder->Load( meshname, NULL, D3DRMLOAD_FROMFILE, NULL, NULL ); if (r!=D3DRM_OK) { CString msg; msg.Format( "Failed to load file '%s'\n", meshname ); AfxMessageBox( msg ); return FALSE; } ScaleMesh( meshbuilder, D3DVALUE(25) ); LPDIRECT3DRMFRAME meshframe; d3drm->CreateFrame( scene, &meshframe ); meshframe->AddVisual( meshbuilder ); meshframe->SetRotation( scene, D3DVALUE(0), D3DVALUE(1), D3DVALUE(0), D3DVALUE(.1) ); meshframe->Release(); meshframe=0; // --------SPOT LIGHT-------- LPDIRECT3DRMLIGHT slight; d3drm->CreateLightRGB( D3DRMLIGHT_SPOT, D3DVALUE(1.00), D3DVALUE(1.00), D3DVALUE(1.00), &slight); LPDIRECT3DRMFRAME slightframe; d3drm->CreateFrame( scene, &slightframe ); slightframe->AddLight( slight ); slightframe->SetPosition ( scene, D3DVALUE(0),D3DVALUE(20),D3DVALUE(-20) ); slightframe->SetOrientation( scene, D3DVALUE(0), D3DVALUE(-20), D3DVALUE(20), D3DVALUE(0), D3DVALUE(1), D3DVALUE(0)); slightframe->AddMoveCallback( MoveLight, NULL ); slight->Release(); slight=0; slightframe->Release(); slightframe=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; } The CreateScene() function shown in Listing 4.3 performs three steps:
Creating A Mesh The first step requires that a pointer to the Direct3DRMMeshBuilder interface is created. The Direct3DRMMeshBuilder Load() member function is used to load a mesh from a file. If the Load() function fails (if the file doesnt exist or if it is not a valid file), a message box is displayed and the function returns FALSE, signaling the application to terminate. Lets take another look at this code: d3drm->CreateMeshBuilder( &meshbuilder ); r=meshbuilder->Load( meshname, NULL, D3DRMLOAD_FROMFILE, NULL, NULL ); if (r!=D3DRM_OK) { CString msg; msg.Format( "Failed to load file '%s'\n", meshname ); AfxMessageBox( msg ); return FALSE; } ScaleMesh( meshbuilder, D3DVALUE(25) ); If the mesh loads successfully, the meshbuilder is scaled with the ScaleMesh() function. ScaleMesh() is a convenience function provided by the RMWin class. We use it here to scale the mesh to insure that it appears properly, regardless of the meshs original dimensions. Well look at the ScaleMesh() function later in this chapter. Next, the meshbuilder is added to a frame. This portion of code appears as follows: LPDIRECT3DRMFRAME meshframe; d3drm->CreateFrame( scene, &meshframe ); meshframe->AddVisual( meshbuilder ); meshframe->SetRotation( scene, D3DVALUE(0), D3DVALUE(1), D3DVALUE(0), D3DVALUE(0.1) ); 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. |