Archived

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

3cheeseMac

Cubes from vertices?

Recommended Posts

Let''s say that I have a vertex struct and a vertex buffer. I want to define a set of vertices that describe a cube. How do I arrange those vertices in the buffer to get a cube? Do I need 4 vertices? More? Is there a specific order they must adhere to? Do I instead need to define 12 triangles, or 6 strips instead? Please point me in the right direction. 3CM

Share this post


Link to post
Share on other sites
Eh... the vertex buffer contains the vertices... then you use an index buffer to render the triangles from the vertices.. in other words... suppose you have some vertices like these

((-1.0f, -1.0f, 0.0f), (-1.0f, 1.0f, 0.0f), (1.0f, 1.0f, 0.0f), (1.0f, -1.0f, 0.0f))

then you would use this for triangle indices (left handed)

(0,1,2,0,2,3)

so... that works... now you could speed it up if you have a fixed polygon type (ie... the number of vertices per polygon is fixed)... I do not think that it is worth using other types than triangles unless you have large polygons... but I could be wrong.

Anyways... I hope this has helped you enough

(Note that to answer your question directly... a cube needs 8 (position) vertices (note position... because if you want to texture as well... well it still is possible with 8... but not optimal)... and a cube consists out of 12 triangles indeed... the strips do work if you have the fixed amount of vertices per polygon (4 for quads)... but it is not the best way to go if you use a models consisting out of triangles (note that a triangle is always convex... which might be what you want also))

Share this post


Link to post
Share on other sites
actually 8 won''t work regardless of texturing unless you want a rounded cube (you need seperate normals for different faces). You''ll need 4 vertices per face, and for each face you use a different normal (which is assinged to all the vertices used in that face).

that''s a total of 24 vertices.

Share this post


Link to post
Share on other sites