+
+
+static void
+tube(GLfloat radius, GLfloat width, GLint facets, Bool wire)
+{
+ GLint i;
+ GLfloat da = 2.0 * M_PI / facets / 4.0;
+
+ glFrontFace(GL_CCW);
+
+ /* draw bottom of tube */
+
+ glShadeModel(GL_FLAT);
+ glNormal3f(0, 0, 1);
+ if (!wire)
+ {
+ glBegin(GL_TRIANGLE_FAN);
+ glVertex3f(0, 0, width * 0.5);
+ for (i = 0; i <= facets; i++) {
+ GLfloat angle = i * 2.0 * M_PI / facets;
+ glVertex3f(radius * cos(angle), radius * sin(angle), width * 0.5);
+ }
+ glEnd();
+ }
+
+ /* draw top of tube */
+
+ glShadeModel(GL_FLAT);
+ glNormal3f(0, 0, -1);
+ glFrontFace(GL_CW);
+ if (!wire)
+ {
+ glBegin(GL_TRIANGLE_FAN);
+ glVertex3f(0, 0, -width * 0.5);
+ for (i = 0; i <= facets; i++) {
+ GLfloat angle = i * 2.0 * M_PI / facets;
+ glVertex3f(radius * cos(angle), radius * sin(angle), -width * 0.5);
+ }
+ glEnd();
+ }
+
+ /* draw side of tube */
+ glFrontFace(GL_CW);
+ glShadeModel(GL_SMOOTH);
+
+ if (!wire)
+ glBegin(GL_QUAD_STRIP);
+
+ for (i = 0; i <= facets; i++) {
+ GLfloat angle = i * 2.0 * M_PI / facets;
+
+ if (wire)
+ glBegin(GL_LINES);
+
+ glNormal3f(cos(angle), sin(angle), 0.0);
+
+ glVertex3f(radius * cos(angle), radius * sin(angle), -width * 0.5);
+ glVertex3f(radius * cos(angle), radius * sin(angle), width * 0.5);
+
+ if (wire) {
+ glVertex3f(radius * cos(angle), radius * sin(angle), -width * 0.5);
+ glVertex3f(radius * cos(angle + 4 * da), radius * sin(angle + 4 * da), -width * 0.5);
+ glVertex3f(radius * cos(angle), radius * sin(angle), width * 0.5);
+ glVertex3f(radius * cos(angle + 4 * da), radius * sin(angle + 4 * da), width * 0.5);
+ glEnd();
+ }
+ }
+
+ if (!wire)
+ glEnd();
+
+ glFrontFace(GL_CCW);
+}
+
+
+static void
+arm(GLfloat length,
+ GLfloat width1, GLfloat height1,
+ GLfloat width2, GLfloat height2,
+ Bool wire)
+{
+ glShadeModel(GL_FLAT);
+
+#if 0 /* don't need these - they're embedded in other objects */
+ /* draw end 1 */
+ glFrontFace(GL_CW);
+ glNormal3f(-1, 0, 0);
+ glBegin(wire ? GL_LINE_LOOP : GL_QUADS);
+ glVertex3f(-length/2, -width1/2, -height1/2);
+ glVertex3f(-length/2, width1/2, -height1/2);
+ glVertex3f(-length/2, width1/2, height1/2);
+ glVertex3f(-length/2, -width1/2, height1/2);
+ glEnd();
+
+ /* draw end 2 */
+ glFrontFace(GL_CCW);
+ glNormal3f(1, 0, 0);
+ glBegin(wire ? GL_LINE_LOOP : GL_QUADS);
+ glVertex3f(length/2, -width2/2, -height2/2);
+ glVertex3f(length/2, width2/2, -height2/2);
+ glVertex3f(length/2, width2/2, height2/2);
+ glVertex3f(length/2, -width2/2, height2/2);
+ glEnd();
+#endif
+
+ /* draw top */
+ glFrontFace(GL_CCW);
+ glNormal3f(0, 0, -1);
+ glBegin(wire ? GL_LINE_LOOP : GL_QUADS);
+ glVertex3f(-length/2, -width1/2, -height1/2);
+ glVertex3f(-length/2, width1/2, -height1/2);
+ glVertex3f( length/2, width2/2, -height2/2);
+ glVertex3f( length/2, -width2/2, -height2/2);
+ glEnd();
+
+ /* draw bottom */
+ glFrontFace(GL_CW);
+ glNormal3f(0, 0, 1);
+ glBegin(wire ? GL_LINE_LOOP : GL_QUADS);
+ glVertex3f(-length/2, -width1/2, height1/2);
+ glVertex3f(-length/2, width1/2, height1/2);
+ glVertex3f( length/2, width2/2, height2/2);
+ glVertex3f( length/2, -width2/2, height2/2);
+ glEnd();
+
+ /* draw left */
+ glFrontFace(GL_CW);
+ glNormal3f(0, -1, 0);
+ glBegin(wire ? GL_LINE_LOOP : GL_QUADS);
+ glVertex3f(-length/2, -width1/2, -height1/2);
+ glVertex3f(-length/2, -width1/2, height1/2);
+ glVertex3f( length/2, -width2/2, height2/2);
+ glVertex3f( length/2, -width2/2, -height2/2);
+ glEnd();
+
+ /* draw right */
+ glFrontFace(GL_CCW);
+ glNormal3f(0, 1, 0);
+ glBegin(wire ? GL_LINE_LOOP : GL_QUADS);
+ glVertex3f(-length/2, width1/2, -height1/2);
+ glVertex3f(-length/2, width1/2, height1/2);
+ glVertex3f( length/2, width2/2, height2/2);
+ glVertex3f( length/2, width2/2, -height2/2);
+ glEnd();
+
+ glFrontFace(GL_CCW);
+}
+
+