Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Cutting Edge Direct 3D Programming
(Publisher: The Coriolis Group)
Author(s): Stan Trujillo
ISBN: 1576100502
Publication Date: 11/01/96

Bookmark It

Search this book:
 
Previous Table of Contents Next


The CreateScene() Function

The CreateScene() function is shown in Listing 10.10.

Listing 10.10 The CreateScene() function.

BOOL FullScreenWin::CreateScene()
{
    //-------- MENU AND FPS SURFACES --------
    selectmode=GetCurDisplayMode();

    CreateMenuSurface();
    UpdateMenuSurface();

    CreateFPSSurface();

    // ------- MESH --------
    D3DRMLOADRESOURCE resinfo;
    resinfo.hModule=0;
    resinfo.lpName=MAKEINTRESOURCE( IDR_SWIRLMESH );
    resinfo.lpType="MESH";
    d3drm->CreateMeshBuilder( &meshbuilder );
    meshbuilder->Load( &resinfo, 0, D3DRMLOAD_FROMRESOURCE, 0, 0 );
    ScaleMesh( meshbuilder, D3DVALUE(15) );

    //------- MESH FRAME --------
    LPDIRECT3DRMFRAME meshframe;
    d3drm->CreateFrame( scene, &meshframe );
    meshframe->AddVisual( meshbuilder );
    meshframe->SetRotation( scene,
            D3DVALUE(0), D3DVALUE(1), D3DVALUE(0),
            D3DVALUE(.1) );
    meshframe->AddMoveCallback( UpdateAnimation, 0 );

    //-------- ANIMATION --------
    d3drm->CreateAnimation( &animation );

    for (int i=0; i<11; i++)
    {
        D3DRMQUATERNION    quat;
        D3DRMQuaternionFromRotation( &quat, &vect[i], rot[i] );
        animation->AddRotateKey( D3DVALUE(i), &quat );
        animation->AddPositionKey( D3DVALUE(i),
                trans[i].x, trans[i].y, trans[i].z  );
    }

    animation->SetOptions( D3DRMANIMATION_SPLINEPOSITION |
            D3DRMANIMATION_CLOSED |
            D3DRMANIMATION_POSITION |
            D3DRMANIMATION_SCALEANDROTATION );
    animation->SetFrame( meshframe );

    meshframe->Release();
    meshframe=0;

    // --------DIRECTIONAL LIGHT--------
    LPDIRECT3DRMFRAME dlightframe;
    LPDIRECT3DRMLIGHT dlight;

    d3drm->CreateLightRGB(D3DRMLIGHT_DIRECTIONAL,
            D3DVALUE(1.00), D3DVALUE(1.00), D3DVALUE(1.00),
            &dlight );

    d3drm->CreateFrame( scene, &dlightframe );
    dlightframe->SetOrientation( scene,
            D3DVALUE(0), D3DVALUE(-1), D3DVALUE(1),
            D3DVALUE(0), D3DVALUE(1), D3DVALUE(0) );
    dlightframe->AddLight( dlight );

    dlightframe->Release();
    dlightframe=0;
    dlight->Release();
    dlight=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 performs six steps:

1.  Initializes the display menu and FPS readout surfaces
2.  Creates and loads a mesh
3.  Creates a frame for the mesh
4.  Creates and configures an animation sequence using the Direct3DRMAnimation interface
5.  Creates a light source
6.  Creates a viewport

We’ll forgo a discussion of steps 2 through 6. These steps have been covered by previous chapters. Step 1, however, is of interest because this is where the display mode menu and FPS read-out surfaces are initialized. The surfaces are initialized with these function calls:

selectmode=GetCurDisplayMode();
CreateMenuSurface();
UpdateMenuSurface();

CreateFPSSurface();

The GetCurDisplayMode() function is used to initialize the selectmode integer. This is done so the display mode menu can highlight the current display mode. The CreateMenuSurface() function creates the surface that will be used to display the display mode menu. The UpdateMenuSurface() function creates the menu surface contents. The CreateFPSSurface() function creates the FPS readout surface, but no FPS values are calculated because no frames have been displayed at this point in the demo’s execution.

The CreateMenuSurface() Function

The CreateMenuSurface() function appears like this:

BOOL FullScreenWin::CreateMenuSurface()
{
    menusurf=CreateSurface( menuwidth, menuheight );

    menurect.left=0;
    menurect.top=0;
    menurect.right=menuwidth;
    menurect.bottom=menuheight;

    DDCOLORKEY  ddck;
    ddck.dwColorSpaceLowValue = 0;
    ddck.dwColorSpaceHighValue = 0;
    menusurf->SetColorKey( DDCKEY_SRCBLT, &ddck );

    return TRUE;
}

First, the RMWin::CreateSurface() function is used to create the surface. The menuwidth and menuheight constants are used as arguments. The CreateSurface() function returns a pointer to the new surface.

The menurect structure is initialized. The rectangle doesn’t contain the surface’s location, only its dimensions.

Next, a color key is assigned to the surface. Color keys indicate which pixel value or values should be treated as transparent. In this case, we are specifying that display menu surface pixels that have the value zero should be transparent. If you watch the FullScreen demo in action, you can see that except for the text the menu surface is transparent. This is because all of the surface’s pixels are assigned to zero before the text is drawn.

While we are on the subject of surface contents, it should be pointed out that the surface we just created has random contents. The surface creation claims memory to represent the surface, but does not initialize the memory itself.


Previous Table of Contents Next


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.