# ListIndex for a cube...

This topic is 5120 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi. I have got the following list index in a little program I got:
[Source]
WORD indexList[36] = { 2, 2, 2,
3, 1, 0,
7, 6, 4,
2, 5, 7,
2, 6, 2,
2, 0, 4,
1, 3, 7,
7, 5, 1,
4, 0, 1,
1, 5, 4,
2, 6, 7,
7, 3, 2};

g3D->render(gVertPool, 8, indexList, 36); // Draw the cube
[/Source]
[/source] I am just wondering how you understand the values? I.E. Which surface does each value corrspond to? Thanks Mark.

##### Share on other sites
It's a cube that looks like this:

    0---------1   /|        /|  / |       / | /  |      /  |2---------3   ||   |     |   ||   4-----|---5|  /      |  /| /       | /|/        |/6---------7

The list is a list of indices that define each triangle, except that 3 of them in your list are wrong.

2, 2, 2 should be 0, 2, 3 and
2, 6, 2 should be 2, 4, 6
2, 5, 7 should be 4, 5, 7

each sequential pair of lines represent the 2 triangles that form a face, followed by the 2 triangles that represent the opposite face, etc. And each trio of indices should form a triangle such that the indices go in counter-clockwise order if viewed head-on. If you replace the lines I described, and then trace each triangle based on my diagram, you should see what I'm talking about.

##### Share on other sites
Assuming you're rendering a triangle list, you have to take each group of vertices three at a time. So basically the only way to "understand" the values would be to draw each of the triangles represented by every three values. (To render them, heh.)

I don't think that's a cube, or maybe it's not a triangle list, since it begins with "2,2,2...".
ajas95m that is a most excellent cube.

##### Share on other sites
Hi.

Thanks for the reply. Managed to figure it out by trial and error.

Just two other questions...

1. As each square is currently being made out of two triangles, is there a way to set 4 points for one square?

e.g. somehow set 0 1 2 3 and to produce a square edge.

2. I am currently using this code to colour each surface:

gVertPool.color = ARGB(0, 255, 0, 0); //Alpha, Red, Green, Blue

Is it possible to just colour the line that joins each point up? For example white lines on a black background would make it look wireframe.

Mark.

[Edited by - Mark04 on December 6, 2004 6:37:58 AM]

##### Share on other sites
drawing in wireframe is pretty much up to your renderer. See if there's some sort of "Draw Lines" or "Wireframe" mode that you can set on your renderer or pass as an argument or something. (what rendering library are you using?)

##### Share on other sites
Hi.

I am using DX9 Library.

Here is some sample code for building a simple cube. Anywhere in here where I can put the wireframe code?

[Source]void DrawCube(const CPos &cen, int size){	for(int i = 0; i < 8; ++i)	{		if(i & 1)			gVertPool.x = cen.x - size;					else			gVertPool.x = cen.x + size;					if(i & 2)			gVertPool.y = cen.y - size;		else			gVertPool.y = cen.y + size;					if(i & 4)		{			gVertPool.z = cen.z + size;			gVertPool.color = ARGB(0, 0, 0, 255); //SURFACE_COLOUR		}			else		{			gVertPool.z = cen.z - size;			gVertPool.color = ARGB(0, 255, 0, 0); //SURFACE_COLOUR		}			}[\Source]I have discovered I need to use "g3D->renderLine" but just not sure where in the code???Mark

[Edited by - Mark04 on December 6, 2004 12:19:18 PM]

1. 1
2. 2
3. 3
Rutin
12
4. 4
5. 5

• 26
• 10
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633694
• Total Posts
3013380
×