/* file name: mmoore2a.cpp written by: maui moore date: 15 November 2007 description: file containing definition of mmoore2LitPalmTree function delcared in "mmoore2a.h" */ void mmoore2LitPalmTree(twTriple palmColor1,twTriple palmColor2, twTriple palmColor3, twTriple coconutColor, twTriple trunkColor, float treeBase, int treeHeight) { /* make the trunk using a trunkColored cone */ twColor(trunkColor,.1,25); //trunk should not be very shiny glPushMatrix(); /* placement of tree in bounding box is related to height of tree */ glTranslatef((treeHeight/2),0,(treeHeight/2)); glRotatef(270,1,0,0); /* trunk is a stack of cones */ for (int i=0; i < treeHeight-1; i ++){ glTranslatef(0,0,1); glutSolidCone(treeBase,2,100,100); } glPopMatrix(); /* make the crown using cones */ /* each palm frond is 2/3 height of tree */ /* the crown has 3 layers of palm fronds, one of each palmColor# */ /* each layers is coded in a separate for loop that changes the /* /* axis/axes and angle of rotation of each cone*/ /* first layer of crown */ twColor(palmColor1,1.0,20); /* first frond doesn't need to be rotated and so is not encoded in loop */ glPushMatrix(); /* bases of all fronds placed at apex of top cone */ glTranslatef((treeHeight/2),treeHeight,(treeHeight/2)); glutSolidCone(treeBase/2,(2*treeHeight)/3,100,100); glPopMatrix(); for (int i = 90; i <360; i+=90){ glPushMatrix(); glTranslatef((treeHeight/2),treeHeight,(treeHeight/2)); glRotatef(i,1,1,0); glutSolidCone(treeBase/2,(2*treeHeight)/3,100,100); glPopMatrix(); } /* second layer of crown */ twColor(palmColor2, .1, 75); /* just experimenting with diff. values */ for (int i=45;i<360;i+=90){ glPushMatrix(); glTranslatef((treeHeight/2),treeHeight,(treeHeight/2)); glRotatef(i,0,1,0); glutSolidCone(treeBase/2,(2*treeHeight)/3,100,100); glPopMatrix(); } /* 3rd layer of crown */ twColor(palmColor3, 0, 10); for (int i=45; i<360; i+=45){ glPushMatrix(); glTranslatef((treeHeight/2),treeHeight,(treeHeight/2)); glRotatef(i,0,1,1); glutSolidCone(treeBase/2,(2*treeHeight)/3,100,100); glPopMatrix(); } }