This topic is now archived and is closed to further replies.


The Coordinates of a Box

Recommended Posts

My question is very simple. If I was to make a primitive of a box(6 sided), and am planning to use D3DPT_TRIANGLELIST to render it, how would I set up the initial D3DVERTEX array before i use device->CreateVertexBuffer(). The answer I''m looking for should(i''d like) to be in the format below. D3DVERTEX aQuad[] = { {-1.0f,-1.0f,-1.0f,0.0f,0.0f}, { 1.0f,-1.0f,-1.0f,1.0f,0.0f}, {-1.0f,-1.0f, 1.0f,0.0f,1.0f}, { 1.0f,-1.0f, 1.0f,1.0f,1.0f} };

Share this post

Link to post
Share on other sites
I''d just setup an index buffer & eight vertices...

The coordinates would then be quite easey, you''d just have to extrude your current set of vertices along an axis... (in your case the new 4 would have a positive Y value instead of a negative)

Hope that helps...


Share this post

Link to post
Share on other sites
If you use index buffers you can copy the coordinates right out of the SDK Documentation Mesh Cube example:

1.000000;1.000000;-1.000000;, // Vertex 0.
-1.000000;1.000000;-1.000000;, // Vertex 1.
-1.000000;1.000000;1.000000;, // And so on.

These are the indices:
0,1,2;, // Face 0 has three vertices.
0,2,3;, // And so on.

Share this post

Link to post
Share on other sites
A vertex buffer is a list of 3d Points. An index buffer is a list of offsets into the vertex buffer. The idea is that since many vertices are used for more than one triangle, by using an index buffer, you do not have to specify the same vertex twice. When you use DrawIndexedPrimitive, directX looks up the vertices based on the indices that you provide it.

In the above example, the first 3 indices: 0,1,2 mean draw a triangle from vertex 0 (1.0;1.0;-1.0) to vertex 1 (-1.0;1.0;-1.0) to vertex 2 (-1.0;1.0;1.0).

You can see that 4 triangles reference vertex 0. This means that if you made a triangle list vertex buffer without the index buffer, you would have to specify vertex 0 4 times.

Share this post

Link to post
Share on other sites