+
+
+ 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();
+
+ glPushMatrix();
+ glRotatef(240, 0, 0, 1);
+ glTranslatef(7.0, 0, 0);
+ glRotatef(90, 0, 1, 0);
+ ctube(0.5, 0.5, wire); /* nub 3 */
+ glPopMatrix();
+
+
+ glEndList();
+ if (!wire)
+ glEnable(GL_NORMALIZE);
+
+ gp->armature = glGenLists(1);
+ glNewList(gp->armature, 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, gray);
+ }
+
+ glTranslatef(0, 0, 1.5);
+ ctube(0.5, 10, wire); /* center axle */
+
+ glPushMatrix();
+ glTranslatef(0.0, 4.2, -1);
+ ctube(0.5, 3, wire); /* axle 1 */
+ glTranslatef(0, 0, 1.8);
+ ctube(0.7, 0.7, wire);
+ glPopMatrix();
+
+ glPushMatrix();
+ glRotatef(120, 0.0, 0.0, 1.0);
+ glTranslatef(0.0, 4.2, -1);
+ ctube(0.5, 3, wire); /* axle 2 */
+ glTranslatef(0, 0, 1.8);
+ ctube(0.7, 0.7, wire);
+ glPopMatrix();
+
+ glPushMatrix();
+ glRotatef(240, 0.0, 0.0, 1.0);
+ glTranslatef(0.0, 4.2, -1);
+ ctube(0.5, 3, wire); /* axle 3 */
+ glTranslatef(0, 0, 1.8);
+ ctube(0.7, 0.7, wire);
+ glPopMatrix();
+
+ glTranslatef(0, 0, 1.5); /* center disk */
+ ctube(1.5, 2, wire);
+
+ glPushMatrix();
+ glRotatef(270, 0, 0, 1);
+ glRotatef(-10, 0, 1, 0);
+ glTranslatef(-2.2, 0, 0);
+ arm(4.0, 1.0, 0.5, 2.0, 1.0, wire); /* arm 1 */
+ glPopMatrix();
+
+ glPushMatrix();
+ glRotatef(30, 0, 0, 1);
+ glRotatef(-10, 0, 1, 0);
+ glTranslatef(-2.2, 0, 0);
+ arm(4.0, 1.0, 0.5, 2.0, 1.0, wire); /* arm 2 */
+ glPopMatrix();
+
+ glPushMatrix();
+ glRotatef(150, 0, 0, 1);
+ glRotatef(-10, 0, 1, 0);
+ glTranslatef(-2.2, 0, 0);
+ arm(4.0, 1.0, 0.5, 2.0, 1.0, wire); /* arm 3 */
+ glPopMatrix();
+
+ glEndList();
+ if (!wire)
+ glEnable(GL_NORMALIZE);
+ }
+}
+
+
+Bool
+gears_handle_event (ModeInfo *mi, XEvent *event)
+{
+ gearsstruct *gp = &gears[MI_SCREEN(mi)];
+
+ if (event->xany.type == ButtonPress &&
+ event->xbutton.button & Button1)
+ {
+ gp->button_down_p = True;
+ gltrackball_start (gp->trackball,
+ event->xbutton.x, event->xbutton.y,
+ MI_WIDTH (mi), MI_HEIGHT (mi));
+ return True;
+ }
+ else if (event->xany.type == ButtonRelease &&
+ event->xbutton.button & Button1)
+ {
+ gp->button_down_p = False;
+ return True;
+ }
+ else if (event->xany.type == MotionNotify &&
+ gp->button_down_p)
+ {
+ gltrackball_track (gp->trackball,
+ event->xmotion.x, event->xmotion.y,
+ MI_WIDTH (mi), MI_HEIGHT (mi));
+ return True;
+ }
+
+ return False;