Platform SDK: DirectX |
The information in this section pertains only to applications written in C and C++. See Direct3D Immediate Mode Visual Basic Tutorials.
To prepare the geometry for a cone, you only need to declare a position vector and a normal vector. Therefore, the cone object in the DrawPrims application is defined with the following programmer-defined structure:
struct MyFlexibleVertex { D3DVECTOR vPosition; D3DVECTOR vNormal; };
You define the tip of the cone with the following code fragment:
g_pvCone[0].vPosition = D3DVECTOR( 0, CONE_HEIGHT/2, 0 ); g_pvCone[0].vNormal = Normalize( D3DVECTOR( 0, 1, 0 ) );
You compute each side of the cone with the following trigonometric functions:
for( i=0; i<NUM_CONE_SIDES; i++ ) { FLOAT x = (FLOAT)sin( 2*g_PI*i/(NUM_CONE_SIDES-1) ); FLOAT y = -CONE_HEIGHT/2; FLOAT z = (FLOAT)cos( 2*g_PI*i/(NUM_CONE_SIDES-1) ); g_pvCone[i+1].vPosition = CONE_RADIUS * D3DVECTOR( x, y, z );
You calculate the position vector of each side of the cone with the following code fragment:
g_pvCone[i+1].vNormal = Normalize( D3DVECTOR( x, 0.5f, z ) ); }
After defining the wall segments and the cone in geometric space, you can move on to preparing the cube. This process is described in Step 1.3: Prepare the Cube.