tags:

views:

221

answers:

3

How do you initialize the vertex buffer and index buffer for a cone in DirectX 9 in C++?

+1  A: 

Most professionals draw it using CAD tools which have the ability to save the mesh in a format that can be understood by DX.

gatorfax
+4  A: 

Well its fairly easy.

A cone has a single point at one end.

At the other end you have a circle. Obviously the more points you have in that circle the more circular it looks.

You can plot a circle using

x = r * cos( theta );
y = r * sin( theta );

To make any triangle you can do it by plugging theta and theta plus some small epsilon (2Pi / 60 would give you 60 points round the base of the cone). Your final coordinate is the top 1. Bung each set of the 3 indices into an index buffer and you are good to go.

Goz
+1  A: 

Why don't you use the D3DXCreateCylinder function with the second radius to 1 or so? This way you get the Mesh object with vertex and index buffer. Extracting from there should be easy job.

P.S. I would prefer to use a modeling tool, but if you need to get it all programmatically this is the fastest way.

feal87