// Here is the stuff for the snowman class SNOWMAN : public OFFCREATURE { enum states { FINISHED, COMPRESSING, BOUNCING, RELAXING }; private: float CurrHeight ; float CurrWidth ; int state; public: SNOWMAN (char* FileName) { ReadOff (FileName,vertices, triangles, numfaces); state = COMPRESSING; x= 130.0 ; y= -50.0 ; z= -160.0 ; angle = 0.0; // this is about the y-axis! CurrHeight = 10.0 ; CurrWidth = 10.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 COMPRESSING: { stage++; CurrHeight = 10.0- (stage/100.0) * 4.0; // Translate Downwards to stay in contact with earth glTranslatef(0.0,- stage/100.0, 0.0); if (stage >= 100.0) { state = BOUNCING; stage = 0.0; } // of for } // of case break; case BOUNCING: { stage++; CurrHeight = 10.0 + (4.0-stage / 50.0)* sin (stage/10.0*PI); // Translate Upwards, bigtime tempheight = stage-100.0; glTranslatef(0.0, (10000.0-tempheight*tempheight)/800.0, 0.0); if (stage >= 200.0) { state = RELAXING; stage = 0.0; } // of for } // of case break; case RELAXING: { stage++; CurrHeight = 10.0 + (1.0-stage / 100.0)/2.0* sin (stage/10.0*PI); glTranslatef(0.0,0.3*(1.0-stage / 100.0)* sin (stage/10.0*PI),0.0); if (stage >= 100.0) { state = FINISHED; stage = 0.0; } // of for } // of case break; case FINISHED: state = COMPRESSING; break; } // of switch return (state); } // of Animate void Draw () { int i; float nx,ny,nz; glColor3f (0.9, 0.9, 0.9); glPushMatrix(); CurrWidth = 20.0-CurrHeight; glScalef (CurrWidth/10.0, CurrHeight/10.0, CurrWidth/10.0); // height scaling! glPushMatrix(); glTranslatef(0.319,-0.4,0.0); // torso glutSolidSphere(0.8,10.0,10.0); glPopMatrix(); glPushMatrix(); glTranslatef(0.319,-1.49,0.0); // lower Body glutSolidSphere(1.0,20.0,20.0); glPopMatrix(); /* glPushMatrix(); glTranslatef(r/10.0,g/10.0,b/10.0); // lower body glutSolidSphere(radius/10.0,10.0,10.0); glPopMatrix(); */ glBegin (GL_TRIANGLES); for (i = 0; i < numfaces; i++) { switch (i) { case 0: // Main Head (grey) glColor3f(0.9,0.9,0.9); break; case 470: // rim of hat (green) glColor3f(0.3,0.8,0.1); break; case 496: // eyes (coalblack) glColor3f(0.0,0.0,0.0); break; case 528: // mouth (red) glColor3f(1.0,0.0,0.0); break; case 546: // top of hat (green) glColor3f(0.3,0.8,0.1); break; case 669: // nose (carrot orange) glColor3f(0.9,0.5,0.0); break; }// of switch // calculate the normals 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 (); glPopMatrix(); } // of Draw }; // of Class SNOWMAN