Jump to content
  • Advertisement
Sign in to follow this  
darkrei9n

Indices and me probably being an idiot

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Alright I'm having an issue with indices and freaking drawing a simple cube. Either me or the indices are being retarded about this. Its probably me. I think maybe I got the addition for coordinates messed up.

const int size = 2;
UINT numVertices = 24;
vertex* v = NULL;

pVertexBuffer->Map(D3D10_MAP_WRITE_DISCARD, 0, (void**) &v );

//vertices for a cube
v[0] = vertex( D3DXVECTOR3(x,y+size,z), D3DXVECTOR4(1,0,0,1) ); //front top left
v[1] = vertex( D3DXVECTOR3(x+size,y+size,z), D3DXVECTOR4(0,1,0,1) ); //front top right
v[2] = vertex( D3DXVECTOR3(x,y,z), D3DXVECTOR4(0,0,1,1) ); //front bottom left
v[3] = vertex( D3DXVECTOR3(x+size,y,z), D3DXVECTOR4(1,1,0,1) ); //front bottom right

v[4] = vertex( D3DXVECTOR3(x,y+size,z+size), D3DXVECTOR4(1,0,0,1) ); //back top left
v[5] = vertex( D3DXVECTOR3(x+size,y+size,z+size), D3DXVECTOR4(0,1,0,1) ); //back top right
v[6] = vertex( D3DXVECTOR3(x,y,z+size), D3DXVECTOR4(0,0,1,1) ); //back bottom left
v[7] = vertex( D3DXVECTOR3(x+size,y,z+size), D3DXVECTOR4(1,1,0,1) ); //back bottom right

pVertexBuffer->Unmap();

//create indexes for a cube
unsigned int* i = NULL;

pIndexBuffer->Map(D3D10_MAP_WRITE_DISCARD, 0, (void**) &i );

//front face
i[0] = 0;
i[1] = 1;
i[2] = 3;
i[3] = 2;

i[4] = 0xffffffff; //start new strip

//right face
i[5] = 0;
i[6] = 2;
i[7] = 6;
i[8] = 4;

i[9] = 0xffffffff;

//left face
i[10] = 5;
i[11] = 7;
i[12] = 3;
i[13] = 1;

i[14] = 0xffffffff;

//back face
i[15] = 6;
i[16] = 4;
i[17] = 5;
i[18] = 7;

i[19] = 0xffffffff;

//top face
i[20] = 0;
i[21] = 4;
i[22] = 1;
i[23] = 5;

i[24] = 0xffffffff;

//bottom face
i[25] = 6;
i[26] = 2;
i[27] = 3;
i[28] = 7;

pIndexBuffer->Unmap();

Share this post


Link to post
Share on other sites
Advertisement
So, what result are you getting. I'm guessing that only some parts of it are showing up? It looks to me like your winding order isn't consistent.It may help to draw out the cube on paper and number the verts, so you can have it in front of you, and can trace out the tris/sides to help you get the vert order correct.

Share this post


Link to post
Share on other sites

So, what result are you getting. I'm guessing that only some parts of it are showing up? It looks to me like your winding order isn't consistent.It may help to draw out the cube on paper and number the verts, so you can have it in front of you, and can trace out the tris/sides to help you get the vert order correct.


asdasdasdasdasd.png

I tried drawing it out on paper. No luck. Infact that was the first thing I tried.

Share this post


Link to post
Share on other sites

Alright I'm having an issue with indices and freaking drawing a simple cube. Either me or the indices are being retarded about this. Its probably me. I think maybe I got the addition for coordinates messed up.


//front face
i[0] = 0;
i[1] = 1;
i[2] = 3;
i[3] = 2;

i[4] = 0xffffffff; //start new strip

//right face
i[5] = 1;
i[6] = 2;
i[7] = 5;
i[8] = 6;

i[9] = 0xffffffff;

//left face
i[10] = 0;
i[11] = 4;
i[12] = 3;
i[13] = 7;

i[14] = 0xffffffff;

//back face
i[15] = 7;
i[16] = 6;
i[17] = 4;
i[18] = 5;

i[19] = 0xffffffff;

//top face
i[20] = 0;
i[21] = 4;
i[22] = 1;
i[23] = 5;

i[24] = 0xffffffff;

//bottom face
i[25] = 6;
i[26] = 2;
i[27] = 3;
i[28] = 7;

pIndexBuffer->Unmap();



Changed a couple indices, try it with these.

edit: I am fairly sure some of your groups for faces were incorrect, but my order inside those groups might also be incorrect.

Top: 0,1,4,5
Front: 0,1,2,3
Left: 4,0,3,7
Right: 1,2,5,6
Bottom: 3,2,6,7
Back: 4,5,6,7

Share this post


Link to post
Share on other sites

Top: 0,1,4,5
Front: 0,1,2,3
Left: 4,0,3,7
Right: 1,2,5,6
Bottom: 3,2,6,7
Back: 4,5,6,7

Heh. I was going to suggest:
Front: 0, 2, 3, 1
Right: 1, 3, 7, 5
Left: 0, 4, 6, 2
Back: 4, 5, 7, 6
Top: 0, 1, 5, 4
Bottom: 2, 6, 7, 3

From the picture, it looks like his normals are flipped for most of the sides, which is why I reversed their winding order. Also, the yellow/green face looks mis-indexed, but it doesn't look like it should be from the code. It would help if each vertex had a unique color instead of having two vertices share a color.

Share this post


Link to post
Share on other sites
In addition to ordering the strips, remember to allocate the right buffers, 8 vertices in the vertex buffer and 29 in the index buffer (24 + 5). Your numVertices = 24 might mess some things up. Also winding order and culling mode can matter.

Another alternative for the strips, if Y+ is up and Z+ is further in, and you have clockwise frontfaces that should be on the outside of the cube.
0, 1, 2, 3, // front
0xffffffff,
5, 4, 7, 6, // back
0xffffffff,
4, 0, 6, 2, // left
0xffffffff,
1, 5, 3, 7, // right
0xffffffff,
4, 5, 0, 1, // top
0xffffffff,
2, 3, 6, 7 // bottom

Share this post


Link to post
Share on other sites

[quote name='way2lazy2care' timestamp='1317571837' post='4868294']
Top: 0,1,4,5
Front: 0,1,2,3
Left: 4,0,3,7
Right: 1,2,5,6
Bottom: 3,2,6,7
Back: 4,5,6,7

Heh. I was going to suggest:
Front: 0, 2, 3, 1
Right: 1, 3, 7, 5
Left: 0, 4, 6, 2
Back: 4, 5, 7, 6
Top: 0, 1, 5, 4
Bottom: 2, 6, 7, 3

From the picture, it looks like his normals are flipped for most of the sides, which is why I reversed their winding order. Also, the yellow/green face looks mis-indexed, but it doesn't look like it should be from the code. It would help if each vertex had a unique color instead of having two vertices share a color.
[/quote]

vertsides.png

Uploaded with ImageShack.us

I read my diagram totally wrong I think. I did it very small in pen <_< edit: the bottom right is a 7.

Share this post


Link to post
Share on other sites
The coordinates look correct to me. As I said before, it would be easier if each vertex were uniquely colored. That way you identifying which face is which would be easier in the graphic, and you could fix the faces one at a time. I'd just send two faces (after changing to unique vertex colors), and ensure theyre correct before adding a third, and so on. I recommend starting with two so you can easily tell if the normals are flipled.

Share this post


Link to post
Share on other sites
I've beginning to notice that the major issue is with the left face, no matter what, one point is always connected to vertex 4.

Issue is far from my code, I'm beginning to think either my computer is racist towards cubes, or I messed up something earlier on in the code.

I just took code out of a book I have for drawing a cube and the same crap is also happening.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!