/***********************************************************/ // Objects created by Zsuzsa Moricz, Fall 2005. // CS307 - Computer Graphics, Professor Scott Anderson /*------------ HAT - (SELF-CONTAINED FUNCTION) ------------*/ // Hat is created from a torus, a cylinder and a disk. // Origin is at the bottom of the hat // to be able to place it on a head or a surface. // Radius of hat 1.4, height 2. // Color needs to be set by the user beforehand with twColor(). // Suggested values: 0.5 for specularity and 100 for shininess. */ void zmoriczHat() { const float hatHeight = 2; const float outerRadius = 1.4; const float innerRadius = 0.8; const float flare = 0.2; glPushMatrix(); glRotatef(-90,1,0,0); glShadeModel(GL_SMOOTH); glPushMatrix(); glScalef(1,1,0.2); glutSolidTorus(outerRadius-innerRadius,outerRadius,30,30); glPopMatrix(); twCylinder(innerRadius+0.1,innerRadius+flare,hatHeight,20,20); glPushMatrix(); glTranslatef(0,0,hatHeight); twDisk(1,20); glPopMatrix(); glPopMatrix(); } /*------------ CLUB - (SELF-CONTAINED FUNCTION) ------------*/ // The club has a total height 7.5. // Origin is at handle and the club points downwards. // Color needs to be set by user beforehand with twColor(). // Suggested values: 1 for specularity and 30 for shininess. void zmoriczClub() { const float maxRadius = 0.7; const float minRadius = 0.1; const float topRadius = 0.3; const float barLength = 2.5; const float lowerCylinder = 3; //length const float topCylinder = 2; //length glPushMatrix(); glShadeModel(GL_SMOOTH); //handle glPushMatrix(); glScalef(1,0.5,1); glutSolidSphere(topRadius,20,20); glPopMatrix(); //bar glPushMatrix(); glRotatef(-90,1,0,0); twTube(minRadius,minRadius,barLength,20,20); glPopMatrix(); //lower cylinder glRotatef(-90,1,0,0); glTranslatef(0,0,barLength); twCylinder(minRadius,maxRadius,lowerCylinder,20,20); //top cylinder glTranslatef(0,0,lowerCylinder); twCylinder(maxRadius,topRadius,topCylinder,20,20); //cover for top glTranslatef(0,0,topCylinder); twDisk(topRadius,20); glPopMatrix(); } /*------------ BEANBAG - (SELF-CONTAINED FUNCTION) ------------*/ // Beanbag is a striped juggling ball. // To make the ball striped two spheres are placed into each other: // one is stretched along the x-axis while the other one along the z-axis. // This is how the illusion of the stripes is created. // Origin is at the bottom of the ball, radius of ball is 1. // Beanbag has two colors one is always black. // The other one is determined by the user with the twColor() function // before the beanbag function is called. // Suggested values: 1 for specularity and 40 for shininess. void zmoriczBeanbag() { const float stretch = 1.1; const float compress = 0.9; twTriple black = {0,0,0}; glPushMatrix(); glTranslatef(0,1,0); glPushMatrix(); glScalef(compress,1,stretch); glShadeModel(GL_SMOOTH); glutSolidSphere(1,20,20); glPopMatrix(); glPushMatrix(); glScalef(stretch,1,compress); twColor(black,1,40); glShadeModel(GL_SMOOTH); glutSolidSphere(1,20,20); glPopMatrix(); glPopMatrix(); } /*------------ SPIRAL - (SELF-CONTAINED FUNCTION) ------------*/ // This function draws a spiral. // One spiral has length 4. // It takes 3 arguments: // 1: color // 2: int n - the number of spirals put together // 3: int nsteps - how many steps it takes to draw the curve // (efficiency vs smoothness) // Light behaves a little strange with this bezier curve. // Origin is at the bottom of the spiral. // And the spiral advances along the +y-axis. // To draw the spiral we need a control point array. // This array contains 10 control points 2*5. // The first 5 represents the left side // and the second 5 the right side of the spiral. // The x and z values are creating a rotating motion // by placing the control points on a circle with radius 1 // and its center at the origin. // Each control point is 90 degrees after the previous one, // except the 1st control point, which appears 45 degrees ahead // and the 5th control point, which is 45 degrees behind as it should be. // This helps to put several spirals together later on. // The y values are incremented by 1 with each point as the spiral advances. void zmoriczSpiral(twTriple color, int n, int nsteps) { GLfloat spiral[10][3] = { {-0.5, 0, -0.5}, // 1 left { 0, 1,-1}, // 2 { 1, 2, 0}, // 3 { 0, 3, 1}, // 4 {-0.5, 4, 0.5}, // 5 {0.5, 0, 0.5}, // 6 right { 0, 1, 1}, // 7 {-1, 2, 0}, // 8 { 0, 3,-1}, // 9 {0.5, 4, -0.5}, // 10 }; int i; glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT_AND_DIFFUSE,color); glMaterialfv(GL_FRONT_AND_BACK,GL_SPECULAR,color); glMaterialf(GL_FRONT_AND_BACK,GL_SHININESS,10); glPushMatrix(); glTranslatef(0,-4,0); for(i=1;i<=n;i++) { glTranslatef(0,4,0); //to put two pieces of spiral together a rotation is needed glRotatef(90,0,1,0); //drawing the bezier curve glEnable(GL_AUTO_NORMAL); // automatically compute normals glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 5, 0, 1, 15, 2, spiral[0]); glEnable(GL_MAP2_VERTEX_3); // set up grid and generate the desired surface glMapGrid2f(nsteps, 0, 1, nsteps, 0, 1); glEnable(GL_NORMALIZE); glEvalMesh2(GL_FILL, 0, nsteps, 0, nsteps); } glPopMatrix(); }