Graphics Reference
In-Depth Information
Here, a linked list of indices into the triangle array is maintained for each vertex in
the data set. The element in the linked list is defined as such.
//Linked-list element to keep track of all triangles a vertex is part of
struct TriList {
int triIndex;
// Index to some triangle the vertex is part of
TriList *pNext;
// Pointer to the next triangle in the linked list
};
The maximum number of vertices, MAX_VERTICES , is at most three times the number
of triangles. An array, triListHead , of many list-element pointers is allocated to hold
the pointer to the head of each list. A second array, triListEntry , of equally many
elements is reserved as a pool to allocate a list element from each time a triangle is
associated with a given vertex list.
// If all vertices are unique, there are at most 3 * MAX_TRIANGLES vertices
const int MAX_VERTICES=3*MAX_TRIANGLES;
TriList *triListHead[MAX_VERTICES]; // The head of the list maintained for each vertex
TriList triListEntry[MAX_VERTICES]; // Entries of the linked list
Given these structures, the main code can now loop over all triangles and insert
an index to the triangle into the linked list for each vertex of the triangle.
// Reset the list of triangles associated with each vertex
for(inti=0;i<MAX_VERTICES; i++) triListHead[i] = NULL;
// Reset the triangle list entry counter
int cnt = 0;
// Loop over all triangles and all three of their vertices
for(inti=0;i<numTris; i++) {
for(intj=0;j<3;j++) {
// Get the vertex index number
int vi = tri[i].vertexIndex[j];
// Fill in a new triangle entry for this vertex
triListEntry[cnt].triIndex = i;
// Link new entry first in list and bump triangle entry counter
triListEntry[cnt].pNext = triListHead[vi];
triListHead[vi] = &triListEntry[cnt++];
}
}
 
Search WWH ::




Custom Search