//Created by Christina Pong //Origami Crane //pset 4 for cs307 //Origami Crane by Christina Pong // //cpongOrigamiCrane(); //Draws an origami crane. //By default, you see the crane from the side with the head facing toward the right. //Values are scaled based on the head. Crane can be scaled via affine transformations. //Default color at the moment is shades of white. Lighting will be added soon. //The origin is the bottom of the crane so the crane can be placed on a surface. //In the event that you want to hang the crane off an object via the top of the body, //the body of the crane is 25/3 units high and you can translate down by that amount. //--------------------------------------------------------------------------------------- static const GLfloat head = 10; //supposed length of the head. Everything scales to this static const GLfloat width = head/5; //the width when looking straight on at the crane's head //I also think of this as the "poufiness" of the model :) static const GLfloat angle = 45; //the angle of the wings static const GLfloat wingTip = head*2; //height of the tip of the wing static const GLfloat wingMid = head*.7; //height of the middle point of the wing static const GLfloat wingFold = head/5; //height of the point of the bottom fold... static const GLfloat intersection = head/4; //height of point where these folds meet static const GLfloat topOffset = head/20; //distances the top fold from the wing so you can see it static const GLfloat botOffset = head/18; //distances the bottom fold from the top fold //using a vertex array to create half a crane: half a head, body, and tail //as well as one wing. static twTriple crane[28] = { //the center vertices {-head*2,head*.75,0}, //tip of the beak {-head*1.2,head*1.2,0}, //top of the head {0,head*.8,0}, //top of the body {0,head/7,0}, //bottom of the body (middle) {head*2,head*2,0}, //tip of the tail [4] //front side of the body {-head/2,head*.5,width}, //top left {-head/2+(head/10),0,head/15}, //bottom left {0,head/7,head/15}, //middle {head/2-(head/10),0,head/15}, //bottom right {head/2,head*.5,width}, //top right [9] //points for the neck and head {-head*1.1,head*1.2,head/15}, //right top of neck {-head*1.3,head*1.2,head/15}, //left top of neck {-head*1.2,head*1.2,0}, //center of top of head [12] //wing coordinates based on wing angle {(-(head/2)-(head/10)),wingMid*sin(angle),wingMid*cos(angle)}, //left wing {((head/2)+(head/10)),wingMid*sin(angle),wingMid*cos(angle)}, //right wing {0,wingTip*sin(angle),wingTip*cos(angle)}, //tip of the wing [15] //points for the top folds on the wings {(-(head/2)-(head/10)),wingMid*sin(angle),(wingMid*cos(angle))+topOffset}, //left top fold point {((head/2)+(head/10)),wingMid*sin(angle),wingMid*cos(angle) + topOffset}, //right top fold point {-head/2+(head/10),0,head/15 + topOffset}, //left bottom corner {head/2-(head/10),0,head/15 + topOffset}, //right bottom corner {0,intersection*sin(angle),intersection*cos(angle)+topOffset}, //where the above meet [20] //points for the bottom folds on the wings {-(head/2),wingFold*sin(angle),wingFold*cos(angle)+ botOffset}, //left bottom fold {head/2,wingFold*sin(angle),wingFold*cos(angle)+ botOffset}, //right bottom fold {-head/2+(head/10),0,head/15 + botOffset}, //left bottom corner {head/2-(head/10),0,head/15 + botOffset}, //right bottom corner {0,intersection*sin(angle),intersection*cos(angle)+botOffset}, //where the above meet {0,head/7,botOffset}, //the bottom middle [26] //this point makes the body poof out {0,head*.5,width}, //[27] }; static void centerLine(){ //function used to help visualize the points when making the crane //this line connects the center vertices twColorName(TW_BLACK); glLineWidth(2); glBegin(GL_LINES); { glVertex3fv(crane[0]); glVertex3fv(crane[1]); glVertex3fv(crane[1]); glVertex3fv(crane[2]); glVertex3fv(crane[2]); glVertex3fv(crane[3]); glVertex3fv(crane[3]); glVertex3fv(crane[4]); } glEnd(); } static void drawHalfCrane(){ //front side of the body is made up of 4 panels b/c it bulges glColor3ub(235,235,235); //top left panel glBegin(GL_TRIANGLES); { glVertex3fv(crane[2]); glVertex3fv(crane[5]); glVertex3fv(crane[27]); } glEnd(); //bottom left panel glBegin(GL_QUADS); { glVertex3fv(crane[5]); glVertex3fv(crane[6]); glVertex3fv(crane[7]); glVertex3fv(crane[27]); } glEnd(); //top right panel glBegin(GL_TRIANGLES); { glVertex3fv(crane[2]); glVertex3fv(crane[9]); glVertex3fv(crane[27]); } glEnd(); //bottom right panel glBegin(GL_POLYGON); { glVertex3fv(crane[9]); glVertex3fv(crane[8]); glVertex3fv(crane[7]); glVertex3fv(crane[27]); } glEnd(); //right side of the body glColor3ub(220,220,225); glBegin(GL_QUADS); { glVertex3fv(crane[2]); glVertex3fv(crane[9]); glVertex3fv(crane[8]); glVertex3fv(crane[3]); } glEnd(); //left side of the body glBegin(GL_QUADS); { glVertex3fv(crane[2]); glVertex3fv(crane[5]); glVertex3fv(crane[6]); glVertex3fv(crane[3]); } glEnd(); //tail glColor3ub(240,240,240); glBegin(GL_TRIANGLES); { glVertex3fv(crane[3]); glVertex3fv(crane[4]); glVertex3fv(crane[8]); } glEnd(); //neck glBegin(GL_QUADS); { glVertex3fv(crane[11]); glVertex3fv(crane[6]); glVertex3fv(crane[3]); glVertex3fv(crane[1]); } glEnd(); //head glColor3ub(255,255,255); glBegin(GL_TRIANGLES); { glVertex3fv(crane[11]); glVertex3fv(crane[1]); glVertex3fv(crane[0]); } glEnd(); //wings glColor3ub(220,220,213); glBegin(GL_QUADS); { glVertex3fv(crane[7]); glVertex3fv(crane[6]); glVertex3fv(crane[13]); glVertex3fv(crane[15]); } glEnd(); glBegin(GL_QUADS); { glVertex3fv(crane[7]); glVertex3fv(crane[8]); glVertex3fv(crane[14]); glVertex3fv(crane[15]); } glEnd(); //creases on the wings glColor3ub(190,190,190); glLineWidth(head/5); glBegin(GL_LINES); { glVertex3fv(crane[15]); glVertex3fv(crane[7]); glVertex3fv(crane[16]); glVertex3fv(crane[20]); glVertex3fv(crane[17]); glVertex3fv(crane[20]); glVertex3fv(crane[21]); glVertex3fv(crane[25]); glVertex3fv(crane[22]); glVertex3fv(crane[25]); } glEnd(); //folds on wings... to be implemented in v2.0 // glColor3ub(235,235,225); // //top left // glBegin(GL_TRIANGLES); // { // glVertex3fv(crane[16]); // glVertex3fv(crane[18]); // glVertex3fv(crane[20]); // } // glEnd(); // //top right // glBegin(GL_TRIANGLES); // { // glVertex3fv(crane[17]); // glVertex3fv(crane[19]); // glVertex3fv(crane[20]); // } // glEnd(); // //bottom left // glColor3ub(235,235,235); // glBegin(GL_QUADS); // { // glVertex3fv(crane[21]); // glVertex3fv(crane[25]); // glVertex3fv(crane[26]); // glVertex3fv(crane[23]); // } // glEnd(); // //bottom right // glBegin(GL_QUADS); // { // glVertex3fv(crane[22]); // glVertex3fv(crane[25]); // glVertex3fv(crane[26]); // glVertex3fv(crane[24]); // } // glEnd(); } void cpongOrigamiCrane(){ glTranslatef(12,0,12); //centers crane glPushMatrix(); drawHalfCrane(); glScalef(1,1,-1); //reflects over plane of symmetry, z = 0 drawHalfCrane(); glPopMatrix(); }