/* Creates a ``TeddyBear'' object. Demonstrates affine transforms, including nested transformations, and the new twColor convenience. Written by Caroline Geiersbach and Scott D. Anderson scott.anderson@acm.org Summer 2003 */ #include #include #include /* Creates a bear within a 5*5*3 box */ void drawBear() { twTriple bodyColor = {0.8,0.5,0.3}; twTriple headColor = {0.7,0.4,0.2}; glPushMatrix(); glTranslatef(0,3,0); // necessary to keep bear in bounding box twColor(bodyColor,0,0); // draw ears glPushMatrix(); glTranslatef(-0.6,0.7,0.2); glScalef(1,1,0.5); glutSolidSphere(0.4,20,20); // left ear glPopMatrix(); glPushMatrix(); glTranslatef(0.6,0.7,0.2); glScalef(1,1,0.5); glutSolidSphere(0.4,20,20); // right ear glPopMatrix(); // draw face, slightly darker brown twColor(headColor,0,0); glPushMatrix(); glutSolidSphere(1,20,20); // head glTranslatef(-0.25,0.1,0.9); twColorName(TW_BLACK); glutSolidSphere(0.12,10,10); // left eye glTranslatef(0.5,0,0); glutSolidSphere(0.12,10,10); // right eye glTranslatef(-0.25,-0.4,0); glutSolidSphere(0.2,10,10); // nose glPopMatrix(); // draw body twColor(bodyColor,0,0); glTranslatef(0,-3.8,0); glPushMatrix(); glScalef(1.3,2,1); glutSolidSphere(1.5,20,20); // body glPopMatrix(); // legs are in the head color twColor(headColor,0,0); // dark brown // draw right leg glTranslatef(0.9,-1.9,0); glPushMatrix(); glRotatef(35,-1,0,1); twSolidCylinder(0.7,0.6,2,20,1); glPopMatrix(); // draw left leg glTranslatef(-1.8,0,0); glPushMatrix(); glRotatef(-35,1,0,1); twSolidCylinder(0.7,0.6,2,20,1); glPopMatrix(); // draw left arm glTranslatef(0,3.8,0); glPushMatrix(); glRotatef(-90,0,0,1); twSolidCylinder(0.5,0.4,2,20,1); glPopMatrix(); // draw right arm glTranslatef(2,0,0); glPushMatrix(); glRotatef(90,0,0,1); twSolidCylinder(0.5,0.4,2,20,1); glPopMatrix(); glPopMatrix(); } void display(void) { twDisplayInit(); twCamera(); // sets up camera based on bounding box coords. drawBear(); glFlush(); glutSwapBuffers(); } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH); twInitWindowSize(650,650); glutCreateWindow(argv[0]); twBoundingBox(-5,5,-5,5,-1.5,1.5); twMainInit(); glutDisplayFunc(display); glutMainLoop(); return 0; }