//Created by Christina Pong //Origami Crane //pset 4 for cs307 //v2 //Origami Crane by Christina Pong // //cpongOrigamiCrane2(); //Draws an origami crane. //By default, you see the crane from the side with the head facing toward the right, down the //negative X axis. The tail points down the positive Y axis. Values are scaled based on the head, //which starts with a size of 10 units. The crane can be scaled via affine transformations. //Color is defined by the user through the craneColor agrument. The origin is the // bottom center of the crane (0,0,0) 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 wingAngle = 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*.4; //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/50; //distances the top fold from the wing so you can see it static const GLfloat botOffset = head/20; //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 crane2[29] = { //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(wingAngle),wingMid*cos(wingAngle)}, //left wing {((head/2)+(head/10)),wingMid*sin(wingAngle),wingMid*cos(wingAngle)}, //right wing {0,wingTip*sin(wingAngle),wingTip*cos(wingAngle)}, //tip of the wing [15] //points for the top folds on the wings {(-(head/2)-(head/10)),wingMid*sin(wingAngle),(wingMid*cos(wingAngle))+topOffset}, //left top fold point {((head/2)+(head/10)),wingMid*sin(wingAngle),wingMid*cos(wingAngle) + 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(wingAngle),intersection*cos(wingAngle)}, //where the above meet [20] //points for the bottom folds on the wings {-(head/2),wingFold*sin(wingAngle),wingFold*cos(wingAngle)+ botOffset}, //left bottom fold {head/2,wingFold*sin(wingAngle),wingFold*cos(wingAngle)+ 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(wingAngle),intersection*cos(wingAngle)+botOffset}, //where the above meet {0,head/7,head/15 + botOffset}, //the bottom middle [26] //this point makes the body poof out {0,head*.5,width}, //[27] {0,intersection*sin(wingAngle),intersection*cos(wingAngle)}, //center point for first wing triangle }; //function that cacluates the normal for 3 given points (a plane) void calcNormal(twTriple craneA, twTriple craneB, twTriple craneC){ twTriple v,w,u; twVector(v,craneA,craneB); twVector(w,craneB,craneC); twCrossProduct(u,v,w); twVectorNormalize(u); glNormal3fv(u); } //draws half of the crane using a line draw from the head to //the point of the tail as the line of symmmetry static void drawHalfCrane2(twTriple craneColor){ //front side of the body is made up of 4 panels b/c it bulges twColor(craneColor,.4,10); //top left panel calcNormal(crane2[2],crane2[27],crane2[5]); glBegin(GL_TRIANGLES); { glVertex3fv(crane2[2]); glVertex3fv(crane2[27]); glVertex3fv(crane2[5]); } glEnd(); //bottom left panel calcNormal(crane2[5],crane2[27],crane2[7]); glBegin(GL_QUADS); { glVertex3fv(crane2[5]); glVertex3fv(crane2[27]); glVertex3fv(crane2[7]); glVertex3fv(crane2[6]); } glEnd(); //top right panel calcNormal(crane2[2],crane2[9],crane2[27]); glBegin(GL_TRIANGLES); { glVertex3fv(crane2[2]); glVertex3fv(crane2[9]); glVertex3fv(crane2[27]); } glEnd(); //bottom right panel calcNormal(crane2[9],crane2[8],crane2[7]); glBegin(GL_POLYGON); { glVertex3fv(crane2[9]); glVertex3fv(crane2[8]); glVertex3fv(crane2[7]); glVertex3fv(crane2[27]); } glEnd(); //right side of the body calcNormal(crane2[2],crane2[3],crane2[8]); glBegin(GL_QUADS); { glVertex3fv(crane2[2]); glVertex3fv(crane2[3]); glVertex3fv(crane2[8]); glVertex3fv(crane2[9]); } glEnd(); //left side of the body calcNormal(crane2[2],crane2[5],crane2[6]); glBegin(GL_QUADS); { glVertex3fv(crane2[2]); glVertex3fv(crane2[5]); glVertex3fv(crane2[6]); glVertex3fv(crane2[3]); } glEnd(); //tail calcNormal(crane2[3],crane2[4],crane2[8]); glBegin(GL_TRIANGLES); { glVertex3fv(crane2[3]); glVertex3fv(crane2[4]); glVertex3fv(crane2[8]); } glEnd(); //neck calcNormal(crane2[11],crane2[1],crane2[3]); glBegin(GL_QUADS); { glVertex3fv(crane2[11]); glVertex3fv(crane2[1]); glVertex3fv(crane2[3]); glVertex3fv(crane2[6]); } glEnd(); //head calcNormal(crane2[11],crane2[1],crane2[0]); glBegin(GL_TRIANGLES); { glVertex3fv(crane2[11]); glVertex3fv(crane2[1]); glVertex3fv(crane2[0]); } glEnd(); //bottom layer of wings //top left calcNormal(crane2[15],crane2[7],crane2[13]); glBegin(GL_TRIANGLES); { glVertex3fv(crane2[15]); glVertex3fv(crane2[13]); glVertex3fv(crane2[7]); } glEnd(); //top right calcNormal(crane2[15],crane2[14],crane2[7]); glBegin(GL_TRIANGLES); { glVertex3fv(crane2[15]); glVertex3fv(crane2[14]); glVertex3fv(crane2[7]); } glEnd(); //bottom left calcNormal(crane2[13],crane2[7],crane2[6]); glBegin(GL_TRIANGLES); { glVertex3fv(crane2[13]); glVertex3fv(crane2[6]); glVertex3fv(crane2[7]); } glEnd(); //bottom right calcNormal(crane2[14],crane2[8],crane2[7]); glBegin(GL_TRIANGLES); { glVertex3fv(crane2[14]); glVertex3fv(crane2[8]); glVertex3fv(crane2[7]); } glEnd(); // folds on wings //top left triangle calcNormal(crane2[16],crane2[20],crane2[18]); glBegin(GL_TRIANGLES); { glVertex3fv(crane2[16]); glVertex3fv(crane2[18]); glVertex3fv(crane2[20]); } glEnd(); //top right calcNormal(crane2[17],crane2[19],crane2[20]); glBegin(GL_TRIANGLES); { glVertex3fv(crane2[17]); glVertex3fv(crane2[19]); glVertex3fv(crane2[20]); } glEnd(); //bottom left calcNormal(crane2[21],crane2[26],crane2[23]); glBegin(GL_TRIANGLES); { glVertex3fv(crane2[21]); glVertex3fv(crane2[26]); glVertex3fv(crane2[23]); } glEnd(); //using overlapping triangles to avoid using quads //bottom left overlap glBegin(GL_TRIANGLES); { glVertex3fv(crane2[20]); glVertex3fv(crane2[26]); glVertex3fv(crane2[21]); } glEnd(); //bottom right calcNormal(crane2[22],crane2[24],crane2[26]); glBegin(GL_TRIANGLES); { glVertex3fv(crane2[22]); glVertex3fv(crane2[24]); glVertex3fv(crane2[26]); } glEnd(); //using overlapping triangles to avoid using quads //bottom right overlap glBegin(GL_TRIANGLES); { glVertex3fv(crane2[20]); glVertex3fv(crane2[26]); glVertex3fv(crane2[22]); } glEnd(); } void cpongOrigamiCrane2(twTriple craneColor){ drawHalfCrane2(craneColor); glPushMatrix(); glScalef(1,1,-1); //reflects over plane of symmetry, z = 0 drawHalfCrane2(craneColor); glPopMatrix(); }