// +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Here are the routines for the FlowerCar class FLOWERCAR : public OFFCREATURE { enum states { FINISHED, GOING }; private: float FlowerAngle; float TiltAngle; int state; public: FLOWERCAR (char* FileName) { ReadOff (FileName,vertices, triangles, numfaces); FlowerAngle = 0.0; TiltAngle = 0.0; state = GOING; x = -144.0 ; y = -101.0; z = -170.0; } // of Constructor int Animate () { static float stage = 0.0; // make this float so not to have to convert all the time! float tempheight; switch (state) { case GOING: { stage++; FlowerAngle+=10.0; TiltAngle +=1.0; if (stage >= 100.0) { state = FINISHED; stage = 0.0; } // of for } // of case break; case FINISHED: state = GOING; break; } // of switch return (state); } // of Animate void Draw () { int i; float nx,ny,nz; glBegin (GL_TRIANGLES); for (i = 0; i < numfaces; i++) { switch (i) { case 0: // first petal (greenish) glEnd(); glPushMatrix(); glTranslatef(0.0,8.2,0.0); // glRotatef((float)myvar,1.0,0.0,0.0); // to tilt head! glRotatef(FlowerAngle,0.0,0.0,1.0); // glRotatef(TiltAngle,cos(FlowerAngle*PI/180.0),sin(FlowerAngle*PI/180.0),0.0); // glRotatef(TiltAngle,1.0,0.0,0.0); glTranslatef(0.0,-8.2,0.0); glBegin (GL_TRIANGLES); glColor3f(0.408,0.875,0.125); break; case 8: // second petal (cyan) glColor3f(0.0,1.0,1.0); break; case 16: // third petal (blue) glColor3f(0.0,0.0,1.0); break; case 24: // fourth petal (orange) glColor3f(1.0,0.5,0.0); break; case 32: // fifth petal (magenta) glColor3f(1.0,0.0,1.0); break; case 40: // body (yellow) glColor3f(0.969,0.984,0.259); break; case 520: // stem (green) glEnd(); glPopMatrix(); glBegin (GL_TRIANGLES); glColor3f(0.0,1.0,0.0); break; case 528: // board (brown) glColor3f(0.5,0.25,0.0); break; case 544: // wheels (blackish) glColor3f(0.2,0.2,0.2); break; }// of switch CalculateNormal (nx,ny,nz,i); glNormal3f (nx,ny,nz); glVertex3f (vertices[triangles[i][0]].x, vertices[triangles[i][0]].y, vertices[triangles[i][0]].z); glVertex3f (vertices[triangles[i][1]].x, vertices[triangles[i][1]].y, vertices[triangles[i][1]].z); glVertex3f (vertices[triangles[i][2]].x, vertices[triangles[i][2]].y, vertices[triangles[i][2]].z); } glEnd (); } // of Draw }; // of Class FLOWERCAR