// Here soars the bird class PAPERBIRD : public CREATURES { private: double BodyAngle ; double WingAngle ; double TipAngle [10] ; void DrawElement(float width, float length) { glBegin (GL_TRIANGLES); glVertex3f(0.0,0.0,0.0); glVertex3f(0.0,width,length); glVertex3f(0.0,0.0,length); glEnd (); } // of DrawElement void DrawTip (int iteration) { if (iteration>0) { glPushMatrix(); glRotatef(-2.862, 1.0,0.0,0.0); // Rotate by atan (5/10) glRotatef(TipAngle[iteration-1], 0.0,0.0,1.0); DrawElement(0.5,10.0); DrawTip(iteration-1); glPopMatrix (); } // of if } void DrawWing () { glPushMatrix(); glRotatef(-11.3, 1.0,0.0,0.0); // Rotate by atan (2/10) // glRotatef(MyVar, 0.0,0.0,1.0); DrawElement(0.5,10.0); DrawTip(10); glPopMatrix (); } public: PAPERBIRD (void) { BodyAngle = 20.0 ; WingAngle = 60.0 ; } // of Constructor int Animate () { enum states { FINISHED, FLAPUP, FLAPDOWN, FLAPROLL }; static int state = FLAPDOWN; static float stage = 0.0; // make this float so not to have to convert all the time! int i; switch (state) { case FLAPDOWN: { stage++; glTranslatef(0.0,stage/100.0*5.0,0.0); // pushup for (i=0; i<9; i++) { TipAngle[i]=0.0; } // of for TipAngle[9] = stage/100.0*95.0; if (stage >= 100.0) { state = FLAPROLL; stage = 0.0; } // of for } // of case break; case FLAPROLL: { stage++; glTranslatef(0.0,(100.0-stage)/100.0*5.0,0.0); // falldown for (i=0; i<9; i++) { TipAngle[i]=(stage/50.0)*30.0; } // of for TipAngle[9] = 95.0-(95.0-30.0)*stage/50.0; if (stage >= 50.0) { state = FLAPUP; stage = 0.0; } // of for } // of case break; case FLAPUP: { stage++; glTranslatef(0.0,(50.0-stage)/100.0*5.0,0.0); // falldown for (i=0; i<10; i++) { TipAngle[i]=(1.0-stage/50.0)*30.0; } // of for if (stage >= 50.0) { state = FINISHED; stage = 0.0; } // of for } // of case break; case FINISHED: state = FLAPDOWN; break; } // of switch return (state); } // of AnimateBird void Draw() { int i; glColor3f (0.2, 0.1, 0.5); // draw the left wing glPushMatrix (); glRotatef(BodyAngle,0.0,0.0,1.0); DrawElement(2.0,10.0); DrawWing(); // using the symmetry of the bird, we draw exactly the same thing, mirrored!!! glScalef(-1.0,1.0,1.0); glRotatef(BodyAngle,0.0,0.0,1.0); DrawElement(2.0,10.0); DrawWing(); glPopMatrix (); } // of DrawBird }; // of Class PAPERBIRD