开发者

DirectX: How do you initialize the vertex buffer and index buffer for a cone?

How do you initialize the 开发者_运维技巧vertex buffer and index buffer for a cone in DirectX 9 in C++?


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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜