//display function void display() { glMatrixMode(GL_PROJECTION); //sets current matrix mode to projection matrix glLoadIdentity(); //replaces current matrix with identity matrix glMatrixMode(GL_MODELVIEW); //sets current matrix mode to model view matrix glScalef(1.2,1.2,1.2); //scaling table(0.85,0.15,0.15,0.45); glTranslatef(-0.2,0.07,0); //translation glColor3f(0.4,0,0.7); drawwall(); glColor3f(1,0,0.15); //draw chair drawchair(0.15,0.35); glColor3f(0.0,1,0.0); //set color to green drawWorm(); //draw worm glColor3f(0.8,0.1,0.5); //set color to blue drawteapot(0.25,0.55); //draw teapot glPushMatrix(); glColor3f(1,0.95,0.8); //set color glTranslated(0,0,0.15); drawbook1(0.25,0.25); //draw book1 glPopMatrix(); glPushMatrix(); //drawbook2 glColor3f(0.93,0.86,0.51); glTranslated(0,0,0.15); drawbook2(0.25,0.25); glPopMatrix(); glColor3f(0.7,0.7,0.7); //set color to white drawglass(); //draw glass glColor3f(0,0,0); drawlamp(); glColor3f(1,1,1); //set color to white glTranslatef(0.2,-0.07,0); glTranslatef(-0.0,0.45+0.09,-0.25); glRotated(90,0,1,0); glRotated(-90,0,1,0); glTranslatef(0.0,-0.45-0.09,0.25); glScalef(1/1.2,1/1.2,1/1.2); glEnd(); glFlush(); //forces execution of opengl functions in finite time }
int main() { double L,h; double x,y=0; printf("24-780 Engineering Computation Problem Set 2-2 – Mass-Spring System Enter L and h:"); scanf("%lf %lf",&L,&h); FsOpenWindow(100,100,800,600,0); glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); transform(x,y,L,h); drawwall(x,y); drawspring(x,y,L,h); drawbox(x,y,L,h); glEnd(); glFlush(); while(FSKEY_ESC!=FsInkey()) { FsPollDevice(); FsSleep(25); } return 0; }