/* file name: mmoore2.cpp written by: maui moore description: file containing definition of mmoore2DrawPalmTree function delcared in "mmoore2.h" Copyright (C) 2007 by Marielle Moore under the GNU GPL */ void mmoore2DrawPalmTree(twTriple palmColor1,twTriple palmColor2, twTriple palmColor3, twTriple coconutColor, twTriple trunkColor, int treeBase, int treeHeight) { /* make the trunk using a trunkColored cone */ glColor3fv(trunkColor); glPushMatrix(); /* placement of tree in bounding box is related to height of tree */ glTranslatef((treeHeight/2),0,(treeHeight/2)); glRotatef(270,1,0,0); glutSolidCone(treeBase,treeHeight,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 */ glColor3fv(palmColor1); /* first frond doesn't need to be rotated and so is not encoded in loop */ glPushMatrix(); /* bases of all fronds placed at apex of 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); //90,0,1,0 glutSolidCone(treeBase/2,(2*treeHeight)/3,100,100); glPopMatrix(); } /* second layer of crown */ glColor3fv(palmColor2); 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 */ glColor3fv(palmColor3); 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(); } /*coconuts */ glColor3fv(coconutColor); /* one coconut is attached to the tree, 9/10 of the way up, slightly set of */ /* from center of base of cone */ glPushMatrix(); glTranslatef((treeHeight/2)-(treeBase/2),(9*treeHeight)/10,(treeHeight/2)); glutSolidSphere(treeBase/2,100,100); glPopMatrix(); /* this coconut is on the ground to the right of the tree */ glPushMatrix(); glTranslatef((treeHeight/2)+(treeBase*2),treeBase/2,(treeHeight/2)); glutSolidSphere(treeBase/2,100,100); glPopMatrix(); } /* This file is part of moore2-PalmTree. moore2-PalmTree is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. moore2-PalmTree is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with moore2-PalmTree. If not, see . */