• Create Account

#ActualManabreak

Posted 30 August 2012 - 02:59 AM

Okay, this is kind of a sequel to my last post: ( http://www.gamedev.n...-using-vboglsl/ )

Basically, I'm trying to create the needed vertices from a set of base vertices, indices and UV coordinates. I just can't get it right. Let's take a simple cube for an example: I have 8 base vertex coordinates (read from a FBX file), 36 indices for triangles and 36 UV coordinates, one for each index. Now, I need a new set of vertices with the UV coordinates mapped to them.

Let's assume I have vertex coordinates like this:
(1, 1, -1)
(1, -1, -1)
(-1, -1, -1)
(-1, 1, -1)
(1, 1, 1)
(1, -1, 1)
(-1, -1, 1)
(-1, 1, 1)


And indices list like this:
4,0,3
4,3,7
2,6,7
2,7,3
1,5,2
5,6,2
0,4,1
4,5,1
4,7,5
7,6,5
0,1,2
0,2,3


I tried a simple code like this:
List<Vertex> tempVerts = new List<Vertex>();
for(int i = 0; i < indices.Count; ++i)
{
tempVerts.Add(vertices[indices[i]]);  // 'vertices' is the list of the eight original vertices
}
vertices = tempVerts; // override the original list with the newly made one


.. but it cause a hell of a mess:
[attachment=10985:cube_prob_2.jpg]

... while this is how it SHOULD be:
[attachment=10986:cube_correct.jpg]

I'm losing my head here, because I KNOW it's a simple thing, yet I cannot get my mind around it. Please help me before I go bald from pulling my hair! Also, someone told me last time that there should be 24 unique vertices in the final version, but I get 36. Huh?

#1Manabreak

Posted 29 August 2012 - 09:19 AM

Okay, this is kind of a sequel to my last post: ( http://www.gamedev.n...-using-vboglsl/ )

Basically, I'm trying to create the needed vertices from a set of base vertices, indices and UV coordinates. I just can't get it right. Let's take a simple cube for an example: I have 8 base vertex coordinates (read from a FBX file), 36 indices for triangles and 36 UV coordinates, one for each index. Now, I need a new set of vertices with the UV coordinates mapped to them.

Let's assume I have vertex coordinates like this:
(1, 1, -1)
(1, -1, -1)
(-1, -1, -1)
(-1, 1, -1)
(1, 1, 1)
(1, -1, 1)
(-1, -1, 1)
(-1, 1, 1)


And indices list like this:
4,0,3
4,3,7
2,6,7
2,7,3
1,5,2
5,6,2
0,4,1
4,5,1
4,7,5
7,6,5
0,1,2
0,2,3


I tried a simple code like this:
List<Vertex> tempVerts = new List<Vertex>();
for(int i = 0; i < indices.Count; ++i)
{
tempVerts.Add(vertices[indices[i]]);  // 'vertices' is the list of the eight original vertices
}
vertices = tempVerts; // override the original list with the newly made one


.. but it cause a hell of a mess:
[attachment=10985:cube_prob_2.jpg]

... while this is how it SHOULD be:
[attachment=10986:cube_correct.jpg]

I'm losing my head here, because I KNOW it's a simple thing, yet I cannot get my mind around it. Please help me before I go bald from pulling my hair! Also, someone told me last time that there should be 24 unique vertices in the final version, but I get 36. Huh?

PARTNERS