// *********** My Object for the object library ************ // Function: Draws three flowers of different colors. // draw_bezier_surface() is used to create the flowers' petals. // This function will take 8 steps and 16 Bezier points for // its parameters. // drawFlower() creates one flower and takes one parameter, which // is an integer to determine what color to use for the flower // (0 for plum, 1 for pink, and 2 for purple). // drawThreeFlowers() then calls the drawFlower() function to // draw the plum, pink and purple flowers. static GLfloat petal[16][3]={ //the petal is drawn along the negative z-axis with the origin //at (0.0,0.2,0.0) {-0.1,0.1,-0.8}, //upper left {-0.3,0.2,-0.5}, //upper middle left {-0.3,0.4,-0.5}, //lower middle left {0.1,0.2,0.0}, //lower left {0.0,0.1,-0.8}, //upper middle {0.0,0.2,-0.5}, //upper inner {0.0,0.4,-0.5}, //lower inner {0.0,0.2,0.0}, //lower middle {0.0,0.1,-0.8}, //upper middle {0.0,0.2,-0.5}, //upper inner {0.0,0.4,-0.5}, //lower inner {0.0,0.2,0.0}, //lower middle {0.1,0.1,-0.8}, //upper right {0.3,0.2,-0.5}, //upper middle right {0.3,0.4,-0.5}, //lower middle right {0.1,0.2,0.0} //lower right }; static void draw_bezier_surface(int nsteps,GLfloat*control_points){ //glEnable(GL_AUTO_NORMAL); glMap2f(GL_MAP2_VERTEX_3, 0, 1, 3, 4, 0, 1, 12, 4, control_points); glEnable(GL_MAP2_VERTEX_3); glMapGrid2f(nsteps, 0.0, 1.0, nsteps, 0.0, 1.0); glEvalMesh2(GL_FILL,0,nsteps,0,nsteps); } void jguintoDrawFlower(int color){ //determines which color to use for the petals if (color==0){ twTriple plum = {221/255.0,160/255.0,221/255.0}; twColor (plum,0.1,10); } else if (color==1){ twTriple pink = {255/255.0,20/255.0,147/255.0}; twColor (pink,0.1,10); }else { twTriple purple = {85/255.0,26/255.0,139/255.0}; twColor (purple,0.1,10); } //draws the four petals. //The petals are shifted 0.3 units up from the y-axis //to take account for the stem height. glPushMatrix(); glTranslatef(0,0.3,0); draw_bezier_surface(8,petal[0]); glPopMatrix(); glPushMatrix(); glTranslatef(0,0.3,0); glRotatef(90,0,1,0); glRotatef(10,1,0,0); draw_bezier_surface(8,petal[0]); glPopMatrix(); glPushMatrix(); glTranslatef(0,0.3,0); glRotatef(180,0,1,0); glRotatef(5,1,0,0); draw_bezier_surface(8,petal[0]); glPopMatrix(); glPushMatrix(); glTranslatef(0,0.3,0); glRotatef(270,0,1,0); glRotatef(-10,1,0,0); draw_bezier_surface(8,petal[0]); glPopMatrix(); //draws a green stem of 0.5 units twTriple green = {0/255.0,255/255.0,0/255.0}; twColor (green,0.1,10); glBegin(GL_LINES); glVertex3f(0,0.5,0); glVertex3f(0,0,0); glEnd(); } void jguintoDrawThreeFlowers(){ //draws a pink flower glPushMatrix(); glTranslatef(1,0,1); glRotatef(200,0,1,0); jguintoDrawFlower(1); glPopMatrix(); //draws a purple flower glPushMatrix(); glTranslatef(2,0,2); glRotatef(270,0,1,0); jguintoDrawFlower(2); glPopMatrix(); //draws a plum flower glPushMatrix(); glTranslatef(3,0,1); glRotatef(270,0,1,0); jguintoDrawFlower(0); glPopMatrix(); }