Relationship of Normal list to Face List

BlitzMax Forums/BlitzMax OpenGL Programming/Relationship of Normal list to Face List

The forum is locked. These are the original blitzbasic.com forums, kept so they can still be read. No new topics, replies or edits can be made here. To join in, head over to the Blitz3D+ forums.

This looks like a .x file to me ;)

OK From the top:
The first chunk is 20 vertex positions. If this is a cube then there is a face missing coz there should be 24. The reason for this so that the texture mapping will work properly. Each face of the cube has 4 corners (vertices) times that by 6 and you get 24. I'm only guessing about the shape, I am probably wrong.

Go with the guess that its a cube to make it a bit easier to understand:-

The next chunk has 12 triangle polygons. 2 triangles can make a square ( one side of the cube ) times by 6 sides give you the 12 triangles. This list is of indices into the vertex list. (index 0 based) EG. The first list of indices are 0,1,2. This means vertex 0,vertex 1 and vertex 2 are used to make triangle 1, or actually triangle 0 coz of 0 indexing (zero is a number with computers).

The next chunk is a number of mesh normals. These are the vertex normals that can be assigned to each vertex. Just because there is only six doesn't mean anything coz they are not the actual normals linked directly to the vertex, they are just a list of normals available. Imagine the fact that a list of vertices dont make the shape, its the way a triangle is made up of the vertices, that makes the shape of the polygon.


The last chunk of 12 is the normal list for each triangle. Remember each triangle has 3 vertices and each vertex will need a normal. In that list, the first entry, you have 0,0,0. This means: Triangle 0 ( coz its first in the list) -> vertex 0 -> will use normal index 0 which is 0.00 , 1.00 , 0.00. Triangle 0 -> vertex 1 -> will use normal 0 and trinagle 0 -> vertex 2 will use normal index 0. That info is the first line in this list. The next line is the same data but will be used for Triangle 1. The next line is for triangle 2 which is : Vertex 0 -> normal 1, Vertex 1 -> Normal 1 and Vertex 2 -> Normal 1. Again the same info is repeated in the next line for trinagle 3. As work through the list, you will be assinging each vertex used in each triangle an index into the normal list.

All you need to do is index in the normal list and assign a value in array that corresponds to the same vertex in your vertex array. Like :-

VertexArray[0] ... x..y..z..
NormalArray[0] ... nx.ny.nz
VertexArray[1] ... x..y..z..
NormalArray[1] ... nx.ny.nz.

You can use the glVertexPointer to point to the vertex array and glNormalPointer to point to the normal array. Depends on how you want to access the vertex/normal data. You could interleave them in one array so the data would flow as vx,vy,vz,nx,ny,nz,vx,vy,vz,nx,ny,nz.
Just depends on how to want to store and access the data.

Hope this isn't too dificult to read and understand as I was sort of brain-storming this as I typed it.