r735 - trunk

lordhavoc at icculus.org lordhavoc at icculus.org
Sat Dec 23 04:48:53 EST 2006


Author: lordhavoc
Date: 2006-12-23 04:48:53 -0500 (Sat, 23 Dec 2006)
New Revision: 735

Modified:
   trunk/model.c
Log:
added some more comments


Modified: trunk/model.c
===================================================================
--- trunk/model.c	2006-12-23 09:48:11 UTC (rev 734)
+++ trunk/model.c	2006-12-23 09:48:53 UTC (rev 735)
@@ -137,16 +137,23 @@
 	}
 	hashentry_t;
 	hashentry_t **hashtable, *hashentries, *hash;
+
+	// this is a tweakable parameter
 	hashsize = numvertices*2;
+
+	// allocate the hashtable for fast edge searches
 	hashtable = Mem_Alloc(Global_Zone, hashsize * sizeof(hashentry_t *) + numtriangles * 3 * sizeof(hashentry_t));
 	hashentries = (hashentry_t *)(hashtable + hashsize);
-	// find neighboring triangles
+
+	// build edge information in the hashtable
 	for (i = 0, e = elements, n = neighbors;i < numtriangles;i++, e += 3, n += 3)
 	{
 		for (j = 0, p = 2;j < 3;p = j, j++)
 		{
+			// two vertex indices define an edge
 			e1 = e[p];
 			e2 = e[j];
+
 			// this hash index works for both forward and backward edges
 			hashindex = e1 + e2;
 			hash = hashentries + i * 3 + j;
@@ -157,12 +164,15 @@
 			hash->element[1] = e2;
 		}
 	}
+
+	// look up neighboring triangles by finding matching edges in the hashtable
 	for (i = 0, e = elements, n = neighbors;i < numtriangles;i++, e += 3, n += 3)
 	{
 		for (j = 0, p = 2;j < 3;p = j, j++)
 		{
 			e1 = e[p];
 			e2 = e[j];
+
 			// this hash index works for both forward and backward edges
 			hashindex = e1 + e2;
 			count = 0;
@@ -178,13 +188,16 @@
 				else if (hash->element[0] == e1 && hash->element[1] == e2)
 					count++;
 			}
+
 			// detect edges shared by three triangles and make them seams
+			// (this is a rare case but must be handled properly)
 			if (count > 2)
 				match = -1;
 			n[p] = match;
 		}
 	}
-	// free the allocated buffers
+
+	// free the allocated hashtable
 	Mem_Free(&hashtable);
 }
 




More information about the neither-commits mailing list