DirectX SDK

Step 1.1: Prepare the Wall Segments

[Visual Basic]

The information in this section pertains only to applications written in C and C++. See Direct3D Immediate Mode Visual Basic Tutorials.

[C++]

The Using Alternate Primitive Styles tutorial describes the wall segments in your scene with D3DVERTEX structures, which are untransformed and unlit vertices. When you use untransformed and unlit vertices, you effectively request that Direct3D use its own internal algorithms to perform transformation and lighting operations.

You can define each wall segment in 3-D space by calculating and saving the information for a pair of vertices, as demonstrated in the following code from the DrawPrims application:

HRESULT App_InitDeviceObjects( LPDIRECT3DDEVICE7 pd3dDevice )
{
    DWORD i;
 
    for( i=0; i<NUM_WALL_SIDES; i++ )
    {
        FLOAT x = (FLOAT)sin( 2*g_PI*i/(NUM_WALL_SIDES-1) );
        FLOAT z = (FLOAT)cos( 2*g_PI*i/(NUM_WALL_SIDES-1) );
 
        g_pvWall[2*i+0] = D3DVERTEX( 10.0f * D3DVECTOR( x, -0.1f, z ),
                          D3DVECTOR( -x, 0, -z ), 0, 0 );
        g_pvWall[2*i+1] = D3DVERTEX( 10.0f * D3DVECTOR( x, 0.1f, z ),
                          D3DVECTOR( -x, 0, -z ), 0, 0 );
 
    }

The preceding code fills an array of D3DVERTEX structures, g_pvWall., with vertex component data. The code locates the x- and z- coordinates of the vertex by using trigonometric functions. The D3DVERTEX structure requires that you specify your coordinates in model coordinates. Since we have used untransformed and unlit vertices, the system will apply world, view, and projection transformations to the model coordinates to properly position them within your scene. Also, the x-, y-, and z-coordinates of the vertex are scaled by a value of ten to properly size the wall segments.

After defining the geometry for the wall segments in the scene, you can move on to preparing another geometric primitive for your scene, a cone. Again, note that the order in which specific objects are defined is not critical.

Defining a cone in 3-D space is demonstrated in Step 1.2: Prepare the Cone.