class CREATURES { public: // enforce these methods virtual void Draw () =0; virtual int Animate () =0; void SetMove (float newx, float newy,float newz,int steps) { // this is due to how the data for the frames was gathered float offsetangle = 0.0; float tempangle; DX = (newx-x) / (float (steps)*200.0); DY = (newy-y) / (float (steps)*200.0); DZ = (newz-z) / (float (steps)*200.0); tempangle = atan2((newz - z),(newx - x))* 180.0/PI; DAngle = (tempangle)/((float) steps*200.0) ; // printf ("D's\n %f %f %f %f\n",x,y,z,angle); // gets(s); } // this initialises the next SnowmanMoveSequence void Move () // interpolates the snowman to go in the direction specified and returns 1 if he reached the position // its supposed to do step bounces to reach the goalposition { x += DX; y += DY; z += DZ; angle += DAngle; } // of Move float X () {return (x);} // of X float Y () {return (y);} // of Y float Z () {return (z);} // of Z float Angle () {return (angle);} // of Angle protected: // positional stuff float x ; float y ; float z ; float angle ; // this is about the y-axis! float DX,DY,DZ,DAngle; }; // of Superclass CREATURES class OFFCREATURE : public CREATURES { // all off creatures must be able to load their off files. protected: void CalculateNormal (float &nx, float &ny, float &nz, int i) { float ax,ay,az,bx,by,bz; // calculate the normals ax = vertices[triangles[i][1]].x - vertices[triangles[i][0]].x; ay = vertices[triangles[i][1]].y - vertices[triangles[i][0]].y; az = vertices[triangles[i][1]].z - vertices[triangles[i][0]].z; bx = vertices[triangles[i][2]].x - vertices[triangles[i][0]].x; by = vertices[triangles[i][2]].y - vertices[triangles[i][0]].y; bz = vertices[triangles[i][2]].z - vertices[triangles[i][0]].z; nx = ay*bz - az*by; ny = az*bx - ax*bz; nz = ax*by - ay*bx; } // of CalculateNormal public: OFFCREATURE (void) { } // of default Constructor OFFCREATURE(char* FileName) { ReadOff (FileName,vertices, triangles, numfaces); } // of Constructor ~OFFCREATURE(void) { delete (vertices); delete (triangles); } // of Destructor int Animate (void) {return (0);} // of empty Animate void Draw(void) // this may be overridden for specialised drawing... { int i; float nx,ny,nz; glColor3f (0.9, 0.9, 0.9); glBegin (GL_TRIANGLES); for (i = 0; i < numfaces; i++) { 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 Standard Draw protected: // the childs can access this Vertex * vertices; Triangle * triangles; int numfaces; void ReadOff (char * filename, Vertex* &vertices, Triangle* &triangles, int &numface) /* no error checking at all - add some in if you feel inclined. */ { int i; int numvertex; int numedge; FILE * fl = fopen (filename, "r"); fscanf (fl, "%d %d %d\n", &numvertex, &numface, &numedge); vertices = new Vertex[numvertex]; triangles = new Triangle[numface]; for (i = 0; i < numvertex; i++) { fscanf (fl, "%f %f %f\n", &(vertices[i].x), &(vertices[i].y), &(vertices[i].z)); } /* of for */ for (i = 0; i < numface; i++) fscanf (fl, "3 %d %d %d\n", &(triangles[i][0]), &(triangles[i][1]), &(triangles[i][2])); fclose (fl); } // of ReadOff }; // of Derived Class OFFCREATURE // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #include "./flowercar.h" // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #include "./snowman.h" // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ #include "./paperbird.h" // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++