+static void
+four_tetras (gasketstruct *gp,
+ XYZ *outer, XYZ *normals,
+ Bool wireframe_p, int countdown, int which,
+ int *countP)
+{
+ if (countdown <= 0)
+ {
+ (*countP)++;
+ if (which == 0)
+ {
+ glNormal3f (normals[0].x, normals[0].y, normals[0].z);
+ triangle (outer[0].x, outer[0].y, outer[0].z,
+ outer[1].x, outer[1].y, outer[1].z,
+ outer[2].x, outer[2].y, outer[2].z,
+ wireframe_p);
+ }
+ else if (which == 1)
+ {
+ glNormal3f (normals[1].x, normals[1].y, normals[1].z);
+ triangle (outer[0].x, outer[0].y, outer[0].z,
+ outer[3].x, outer[3].y, outer[3].z,
+ outer[1].x, outer[1].y, outer[1].z,
+ wireframe_p);
+ }
+ else if (which == 2)
+ {
+ glNormal3f (normals[2].x, normals[2].y, normals[2].z);
+ triangle (outer[0].x, outer[0].y, outer[0].z,
+ outer[2].x, outer[2].y, outer[2].z,
+ outer[3].x, outer[3].y, outer[3].z,
+ wireframe_p);
+ }
+ else
+ {
+ glNormal3f (normals[3].x, normals[3].y, normals[3].z);
+ triangle (outer[1].x, outer[1].y, outer[1].z,
+ outer[3].x, outer[3].y, outer[3].z,
+ outer[2].x, outer[2].y, outer[2].z,
+ wireframe_p);
+ }
+ }
+ else
+ {
+# define M01 0
+# define M02 1
+# define M03 2
+# define M12 3
+# define M13 4
+# define M23 5
+ XYZ inner[M23+1];
+ XYZ corner[4];
+
+ inner[M01].x = (outer[0].x + outer[1].x) / 2.0;
+ inner[M01].y = (outer[0].y + outer[1].y) / 2.0;
+ inner[M01].z = (outer[0].z + outer[1].z) / 2.0;
+
+ inner[M02].x = (outer[0].x + outer[2].x) / 2.0;
+ inner[M02].y = (outer[0].y + outer[2].y) / 2.0;
+ inner[M02].z = (outer[0].z + outer[2].z) / 2.0;
+
+ inner[M03].x = (outer[0].x + outer[3].x) / 2.0;
+ inner[M03].y = (outer[0].y + outer[3].y) / 2.0;
+ inner[M03].z = (outer[0].z + outer[3].z) / 2.0;
+
+ inner[M12].x = (outer[1].x + outer[2].x) / 2.0;
+ inner[M12].y = (outer[1].y + outer[2].y) / 2.0;
+ inner[M12].z = (outer[1].z + outer[2].z) / 2.0;
+
+ inner[M13].x = (outer[1].x + outer[3].x) / 2.0;
+ inner[M13].y = (outer[1].y + outer[3].y) / 2.0;
+ inner[M13].z = (outer[1].z + outer[3].z) / 2.0;
+
+ inner[M23].x = (outer[2].x + outer[3].x) / 2.0;
+ inner[M23].y = (outer[2].y + outer[3].y) / 2.0;
+ inner[M23].z = (outer[2].z + outer[3].z) / 2.0;
+
+ countdown--;
+
+ corner[0] = outer[0];
+ corner[1] = inner[M01];
+ corner[2] = inner[M02];
+ corner[3] = inner[M03];
+ four_tetras (gp, corner, normals, wireframe_p, countdown, which, countP);
+
+ corner[0] = inner[M01];
+ corner[1] = outer[1];
+ corner[2] = inner[M12];
+ corner[3] = inner[M13];
+ four_tetras (gp, corner, normals, wireframe_p, countdown, which, countP);
+
+ corner[0] = inner[M02];
+ corner[1] = inner[M12];
+ corner[2] = outer[2];
+ corner[3] = inner[M23];
+ four_tetras (gp, corner, normals, wireframe_p, countdown, which, countP);
+
+ corner[0] = inner[M03];
+ corner[1] = inner[M13];
+ corner[2] = inner[M23];
+ corner[3] = outer[3];
+ four_tetras (gp, corner, normals, wireframe_p, countdown, which, countP);
+ }
+}
+
+
+static void
+compile_gasket(ModeInfo *mi, int which)
+{
+ Bool wireframe_p = MI_IS_WIREFRAME(mi);
+ gasketstruct *gp = &gasket[MI_SCREEN(mi)];
+ int count = 0;
+ XYZ vertex[5];
+ XYZ normal[4];
+
+ vertex[0].x = -1; vertex[0].y = -1; vertex[0].z = -1;
+ vertex[1].x = 1; vertex[1].y = 1; vertex[1].z = -1;
+ vertex[2].x = 1; vertex[2].y = -1; vertex[2].z = 1;
+ vertex[3].x = -1; vertex[3].y = 1; vertex[3].z = 1;
+ vertex[4].x = 0; vertex[4].y = 0; vertex[4].z = 0; /* center */
+
+ normal[0].x = 1; normal[0].y = -1; normal[0].z = -1;
+ normal[1].x = -1; normal[1].y = 1; normal[1].z = -1;
+ normal[2].x = -1; normal[2].y = -1; normal[2].z = 1;
+ normal[3].x = 1; normal[3].y = 1; normal[3].z = 1;
+
+ four_tetras (gp, vertex, normal, wireframe_p,
+ (gp->current_depth < 0
+ ? -gp->current_depth : gp->current_depth),
+ which,
+ &count);
+ mi->polygon_count += count;
+}
+