#include #include #include #include using namespace std; const float d = 8; struct point { int x, y, z; }; struct line { point start, end; }; vector figure; // a utility routine to stick a line into the vector. void makeLine(int x1, int y1, int z1, int x2, int y2, int z2) { point p1,p2; line l; p1.x = x1; p1.y = y1; p1.z = z1; p2.x = x2; p2.y = y2; p2.z = z2; l.start = p1; l.end= p2; figure.push_back(l); } // this builds the scene void makeShape() { // a simple cube // make the front of the cube makeLine(-10,-10,10,-10, 10,10); makeLine(-10,-10,10, 10,-10,10); makeLine(-10, 10,10, 10, 10,10); makeLine( 10,-10,10, 10, 10,10); // make the back of the cube makeLine(-10,-10,30,-10, 10,30); makeLine(-10,-10,30, 10,-10,30); makeLine(-10, 10,30, 10, 10,30); makeLine( 10,-10,30, 10, 10,30); // make the sides of the cube makeLine(-10,-10,30,-10,-10,10); makeLine( 10,-10,30, 10,-10,10); makeLine(-10, 10,30,-10, 10,10); makeLine( 10, 10,30, 10, 10,10); // put an x on the right side makeLine(10, -8, 12, 10, 8, 28); makeLine(10, -8, 28, 10, 8, 12); // and put a T on the Top makeLine(-8,10, 28, 8, 10,28); makeLine( 0,10, 12, 0, 10, 28); // finally a triangle on the back wall. makeLine( 0, 8, 28, -8, -8, 28); makeLine( 0, 8, 28, 8, -8, 28); makeLine(-8,-8, 28, 8, -8, 28); } void drawLine(line l) { float x1, y1, x2, y2; // do the projection (from the book) x1 = -float(l.start.x)/(float(l.start.z)/d); x2 = -float(l.end.x) /(float(l.end.z) /d); y1 = -float(l.start.y)/(float(l.start.z)/d); y2 = -float(l.end.y) /(float(l.end.z) /d); // this is how you draw a 2d line glBegin(GL_LINES); glVertex2f(x1, y1); glVertex2f(x2, y2); glEnd(); } void display() { int i; // clear the scene glClear(GL_COLOR_BUFFER_BIT); // set the drawing color glColor3f(1.0,0,0); // actually draw the figure for(i=0;i