简体   繁体   中英

Trying draw cylinder in directx through D3DXCreateCylinder

I am very novice in directx and want to know more, I was trying the code from directxtutorial.com I sthere any example\\sample for D3DXCreateCylinder? Thanks

Alright then,

D3DXCreateCylinder can be used as such

LPD3DXMESH cylinder; // Define a pointer to the mesh.

D3DXCreateCylinder(d3ddev, 2.0f, 0.0f, 10.0f, 10, 10, &cylinder, NULL);

So what is going on?

  1. d3ddev should be your device context that I will assume you have created.
  2. The radius on the Negative Z.
  3. The radius on the Positive Z.
  4. The length of the shape on the Z axis.
  5. The amount of polygons (or subdivisions) around the Z.
  6. The amount of polygons on the Z axis.
  7. The address of the pointer which holds the created mesh.

Tinker around with the values, experimenting can't hurt.

By default, D3DXCreateCylinder API don't generate the texture coordinates for mapping a texture above the created cylindrical mesh.

Alternate you can formulate your own cylindrical Geometry like below for texture mapping:

 for( DWORD i = 0; i < Sides; i++ )
{
    FLOAT theta = ( 2 * D3DX_PI * i ) / ( Sides - 1 );

    pVertices[2 * i + 0].position = D3DXVECTOR3(radius*sinf( theta ), -height, radius*cosf( theta ) );
    pVertices[2 * i + 0].color = 0xffffffff;
    pVertices[2 * i + 0].tu = ( ( FLOAT )i ) / ( Sides - 1 );
    pVertices[2 * i + 0].tv = 1.0f;


    pVertices[2 * i + 1].position = D3DXVECTOR3( radius*sinf( theta ), height, radius*cosf( theta ) );
    pVertices[2 * i + 1].color = 0xff808080;
    pVertices[2 * i + 1].tu = ( ( FLOAT )i ) / ( Sides - 1 );
    pVertices[2 * i + 1].tv = 0.0f;

} 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM