- gearsstruct *gp = &gears[MI_SCREEN(mi)];
- static const GLfloat pos[4] = {5.0, 5.0, 10.0, 1.0};
- static const GLfloat red[4] = {0.8, 0.1, 0.0, 1.0};
- static const GLfloat green[4] = {0.0, 0.8, 0.2, 1.0};
- static const GLfloat blue[4] = {0.2, 0.2, 1.0, 1.0};
- static const GLfloat gray[4] = {0.5, 0.5, 0.5, 1.0};
- static const GLfloat white[4] = {1.0, 1.0, 1.0, 1.0};
- int wire = MI_IS_WIREFRAME(mi);
- int mono = MI_IS_MONO(mi);
-
- if (!wire) {
- glLightfv(GL_LIGHT0, GL_POSITION, pos);
- glEnable(GL_CULL_FACE);
- glEnable(GL_LIGHTING);
- glEnable(GL_LIGHT0);
- glEnable(GL_DEPTH_TEST);
- }
-#if 0
-/*-
- * Messes up on multiscreen Pseudocolor:0 StaticGray(monochrome):1
- * 2nd time mode is run it is Grayscale on PseudoColor.
- * The code below forces monochrome on TrueColor.
- */
- if (MI_IS_MONO(mi)) {
- red[0] = red[1] = red[2] = 1.0;
- green[0] = green[1] = green[2] = 1.0;
- blue[0] = blue[1] = blue[2] = 1.0;
- }
-#endif
-
- /* make the gears */
-
- if (! gp->planetary_p) {
-
- gp->gear1 = glGenLists(1);
- glNewList(gp->gear1, GL_COMPILE);
- if (wire) {
- if (mono)
- glColor4fv(white);
- else
- glColor4fv(red);
- } else {
- if (mono)
- glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
- else
- glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
- }
-
- gear(1.0, 4.0, 1.0, 20, 0.7, wire, False);
- glEndList();
-
- gp->gear2 = glGenLists(1);
- glNewList(gp->gear2, GL_COMPILE);
- if (wire) {
- if (mono)
- glColor4fv(white);
- else
- glColor4fv(green);
- } else {
- if (mono)
- glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
- else
- glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green);
- }
- gear(0.5, 2.0, 2.0, 10, 0.7, wire, False);
- glEndList();
-
- gp->gear3 = glGenLists(1);
- glNewList(gp->gear3, GL_COMPILE);
- if (wire) {
- if (mono)
- glColor4fv(white);
- else
- glColor4fv(blue);
- } else {
- if (mono)
- glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
- else
- glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue);
- }
- gear(1.3, 2.0, 0.5, 10, 0.7, wire, False);
- glEndList();
- if (!wire)
- glEnable(GL_NORMALIZE);
-
- } else { /* gp->planetary_p */
-
- gp->gear1 = glGenLists(1);
- glNewList(gp->gear1, GL_COMPILE);
- if (wire) {
- if (mono)
- glColor4fv(white);
- else
- glColor4fv(red);
- } else {
- if (mono)
- glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
- else
- glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
- }
- gear(1.3, 2.0, 2.0, 12, 0.7, wire, False);
- glEndList();
-
- gp->gear2 = glGenLists(1);
- glNewList(gp->gear2, GL_COMPILE);
- if (wire) {
- if (mono)
- glColor4fv(white);
- else
- glColor4fv(green);
- } else {
- if (mono)
- glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
- else
- glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
- }
- gear(1.3, 2.0, 2.0, 12, 0.7, wire, False);
- glEndList();
-
- gp->gear3 = glGenLists(1);
- glNewList(gp->gear3, GL_COMPILE);
- if (wire) {
- if (mono)
- glColor4fv(white);
- else
- glColor4fv(blue);
- } else {
- if (mono)
- glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
- else
- glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, red);
- }
- gear(1.3, 2.0, 2.0, 12, 0.7, wire, False);
- glEndList();
- if (!wire)
- glEnable(GL_NORMALIZE);
-
-
- gp->gear_inner = glGenLists(1);
- glNewList(gp->gear_inner, GL_COMPILE);
- if (wire) {
- if (mono)
- glColor4fv(white);
- else
- glColor4fv(blue);
- } else {
- if (mono)
- glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
- else
- glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, blue);
- }
- gear(1.0, 2.0, 2.0, 12, 0.7, wire, False);
- glEndList();
- if (!wire)
- glEnable(GL_NORMALIZE);
-
-
- gp->gear_outer = glGenLists(1);
- glNewList(gp->gear_outer, GL_COMPILE);
- if (wire) {
- if (mono)
- glColor4fv(white);
- else
- glColor4fv(blue);
- } else {
- if (mono)
- glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, gray);
- else
- glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, green);
- }
- gear(5.7, 7.0, 2.0, 36, 0.7, wire, True);
-
- /* put some nubs on the outer ring, so we can tell how it's moving */
- glPushMatrix();
- glTranslatef(7.0, 0, 0);
- glRotatef(90, 0, 1, 0);
-
- ctube(0.5, 0.5, wire); /* nub 1 */
- glPopMatrix();
-
- glPushMatrix();
- glRotatef(120, 0, 0, 1);
- glTranslatef(7.0, 0, 0);
- glRotatef(90, 0, 1, 0);
- ctube(0.5, 0.5, wire); /* nub 2 */
- glPopMatrix();
+ gears_configuration *bp = &bps[MI_SCREEN(mi)];
+ gear *g0, *g1, *g2, *g3, *g4;
+ GLfloat distance = 2.02;
+
+ bp->planetary_p = True;
+
+ g0 = new_gear (mi, 0);
+ g1 = new_gear (mi, 0);
+ g2 = new_gear (mi, 0);
+ g3 = new_gear (mi, 0);
+ g4 = new_gear (mi, 0);
+
+ if (! place_gear (mi, g0, 0)) abort();
+ if (! place_gear (mi, g1, 0)) abort();
+ if (! place_gear (mi, g2, 0)) abort();
+ if (! place_gear (mi, g3, 0)) abort();
+ if (! place_gear (mi, g4, 0)) abort();
+
+ g0->nteeth = 12 + (3 * (random() % 10)); /* must be multiple of 3 */
+ g0->tooth_w = g0->r / g0->nteeth;
+ g0->tooth_h = g0->tooth_w * 2.8;
+
+# define COPY(F) g4->F = g3->F = g2->F = g1->F = g0->F
+ COPY(r);
+ COPY(th);
+ COPY(nteeth);
+ COPY(tooth_w);
+ COPY(tooth_h);
+ COPY(tooth_slope);
+ COPY(inner_r);
+ COPY(inner_r2);
+ COPY(inner_r3);
+ COPY(thickness);
+ COPY(thickness2);
+ COPY(thickness3);
+ COPY(ratio);
+ COPY(size);
+# undef COPY
+
+ g1->x = cos (M_PI * 2 / 3) * g1->r * distance;
+ g1->y = sin (M_PI * 2 / 3) * g1->r * distance;
+
+ g2->x = cos (M_PI * 4 / 3) * g2->r * distance;
+ g2->y = sin (M_PI * 4 / 3) * g2->r * distance;
+
+ g3->x = cos (M_PI * 6 / 3) * g3->r * distance;
+ g3->y = sin (M_PI * 6 / 3) * g3->r * distance;
+
+ g4->x = 0;
+ g4->y = 0;
+ g4->th = -g3->th;
+
+ /* rotate central gear 1/2 tooth-size if odd number of teeth */
+ if (g4->nteeth & 1)
+ g4->th -= (180.0 / g4->nteeth);
+
+ g0->inverted_p = True;
+ g0->x = 0;
+ g0->y = 0;
+ g0->nteeth = g1->nteeth * 3;
+ g0->r = g1->r * 3.05;
+ g0->inner_r = g0->r * 0.8;
+ g0->inner_r2 = 0;
+ g0->inner_r3 = 0;
+ g0->th = g1->th + (180 / g0->nteeth);
+ g0->ratio = g1->ratio / 3;
+
+ g0->tooth_slope = 0;
+ g0->nubs = 3;
+ g0->spokes = 0;
+ g0->size = INVOLUTE_LARGE;
+
+ bp->gears = (gear **) calloc (6, sizeof(**bp->gears));
+ bp->ngears = 0;
+
+ bp->gears[bp->ngears++] = g1;
+ bp->gears[bp->ngears++] = g2;
+ bp->gears[bp->ngears++] = g3;
+ bp->gears[bp->ngears++] = g4;
+ bp->gears[bp->ngears++] = g0;
+}