DirectX SDK

Step 1.2: Prepare the Cone

[C++]

This section pertains only to application development in Visual Basic. See Direct3D Immediate Mode C/C++ Tutorials.

[Visual Basic]

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 type:

Private Type MyFlexibleVertex
    vPosition As D3DVECTOR
    vNormal As D3DVECTOR
End Type

You can define the tip of the cone with the following code fragment:

    Dim vectorNorm As D3DVECTOR
    
    g_vCone(0).vPosition = MakeVector(0, CONE_HEIGHT / 2, 0)
        
    vectorNorm = MakeVector(0, 1, 0)
    Call g_dx.vectorNormalize(vectorNorm)
    g_vCone(0).vNormal = vectorNorm

You can compute each side of the cone with the following trigonometric functions:

    For i = 0 To NUM_CONE_SIDES - 1
        x = Sin(2 * pi * i / (NUM_CONE_SIDES - 1))
        y = -CONE_HEIGHT / 2
        z = Cos(2 * pi * i / (NUM_CONE_SIDES - 1))
        
        g_vCone(i + 1).vPosition = MakeVector(x * CONE_RADIUS, y * CONE_RADIUS, z * CONE_RADIUS)

You can calculate the position vector of each side of the cone with the following code fragment:

        vectorNorm = MakeVector(x, 0.5, z)
        Call g_dx.vectorNormalize(vectorNorm)
        g_vCone(i + 1).vNormal = vectorNorm
   Next i

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.