+/* Draw base such that poles are distributed around a regular polygon. */
+static int drawRoundBase(glhcfg *glhanoi) {
+ int polys = 0;
+ GLfloat theta, sinth, costh;
+
+ /*
+ r[0] = (minimum) inner radius of base at vertices
+ r[1] = (minimum) outer radius of base at vertices
+ y[0] = bottom of base
+ y[1] = top of base */
+ GLfloat r[2], y[2];
+ /* positions of end points: beginning, end.
+ beg[0] is inner corner of beginning of base, beg[1] is outer corner.
+ beg[i][0] is x, [i][1] is z. */
+ GLfloat beg[2][2], end[2][2], begNorm, endNorm;
+ /* ratio of radius at base vertices to ratio at poles */
+ GLfloat longer = 1.0 / cos(M_PI / (glhanoi->numberOfPoles + 1));
+
+ r[0] = (glhanoi->poleDist - glhanoi->maxDiskRadius) * longer;
+ r[1] = (glhanoi->poleDist + glhanoi->maxDiskRadius) * longer;
+ y[0] = 0;
+ y[1] = glhanoi->baseHeight;
+
+ /* compute beg, end. Make the ends square. */
+ theta = M_PI * 2 / (glhanoi->numberOfPoles + 1);
+
+ costh = cos(theta);
+ sinth = sin(theta);
+ beg[0][0] = (glhanoi->poleDist - glhanoi->maxDiskRadius) * costh +
+ glhanoi->maxDiskRadius * sinth;
+ beg[1][0] = (glhanoi->poleDist + glhanoi->maxDiskRadius) * costh +
+ glhanoi->maxDiskRadius * sinth;
+ beg[0][1] = (glhanoi->poleDist - glhanoi->maxDiskRadius) * sinth -
+ glhanoi->maxDiskRadius * costh;
+ beg[1][1] = (glhanoi->poleDist + glhanoi->maxDiskRadius) * sinth -
+ glhanoi->maxDiskRadius * costh;
+ begNorm = theta - M_PI * 0.5;
+
+ theta = M_PI * 2 * glhanoi->numberOfPoles / (glhanoi->numberOfPoles + 1);
+
+ costh = cos(theta);
+ sinth = sin(theta);
+ end[0][0] = (glhanoi->poleDist - glhanoi->maxDiskRadius) * costh -
+ glhanoi->maxDiskRadius * sinth;
+ end[1][0] = (glhanoi->poleDist + glhanoi->maxDiskRadius) * costh -
+ glhanoi->maxDiskRadius * sinth;
+ end[0][1] = (glhanoi->poleDist - glhanoi->maxDiskRadius) * sinth +
+ glhanoi->maxDiskRadius * costh;
+ end[1][1] = (glhanoi->poleDist + glhanoi->maxDiskRadius) * sinth +
+ glhanoi->maxDiskRadius * costh;
+ endNorm = theta + M_PI * 0.5;
+
+ /* bottom: never seen
+ polys = drawBaseStrip(glhanoi, 0, 0, 0, 1, y, r, beg, end); */
+ /* outside edge */
+ polys += drawBaseStrip(glhanoi, 0, 1, 1, 1, y, r, beg, end);
+ /* top */
+ polys += drawBaseStrip(glhanoi, 1, 1, 1, 0, y, r, beg, end);
+ /* inside edge */
+ polys += drawBaseStrip(glhanoi, 1, 0, 0, 0, y, r, beg, end);
+
+ /* Draw ends */
+ glBegin(GL_QUADS);
+
+ glVertex3f(beg[0][0], y[1], beg[0][1]);
+ glVertex3f(beg[1][0], y[1], beg[1][1]);
+ glVertex3f(beg[1][0], y[0], beg[1][1]);
+ glVertex3f(beg[0][0], y[0], beg[0][1]);
+ glNormal3f(cos(begNorm), 0, sin(begNorm));
+
+ glVertex3f(end[0][0], y[0], end[0][1]);
+ glVertex3f(end[1][0], y[0], end[1][1]);
+ glVertex3f(end[1][0], y[1], end[1][1]);
+ glVertex3f(end[0][0], y[1], end[0][1]);
+ glNormal3f(cos(endNorm), 0, sin(endNorm));
+
+ polys += 2;
+
+ glEnd();
+
+ return polys;
+}
+
+static int drawDisks(glhcfg *glhanoi)