/* Solution 02501-22-0y-xxxxxxx.cpp ********************************************* Insert your Student id and name below ********************************************* Part 1 - Insert the Matrices below ******************************************** Part 2, Insert the Projection Matrix below ******************************************** */ #include #include GLfloat ctrlpoints [5][3] = {{0.,0.,0.},{0.,0.,5.},{5.,0.,10.},{10.,0.,5.},{10.,0.,0.} }; void ctrlpolygon (void); void axis (void); void house (void); void curves (void); void texture (void); void init (void); void display (void); void reshape (int w, int h); void keyboard(unsigned char key, int x, int y); int main(int argc, char** argv); void init(void) { glClearColor(1.0, 1.0, 1.0, 1.0); glShadeModel(GL_SMOOTH); glEnable (GL_DEPTH_TEST); glEnable (GL_NORMALIZE); } void display(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glColor3f(0.0, 0.0, 0.0); glLoadIdentity (); gluLookAt (12., 10., 10., 5., 0., 5., 0., 0., 1.); glPushMatrix (); /* Draws the control points and the connecting control polygon */ ctrlpolygon (); /* draw axis */ axis(); /* Draws the House */ house (); /* Draw the curves - Part 4 - optional*/ curves (); /*Draw the texture - Part 5 - optional*/ texture (); glPopMatrix (); glFlush(); } void reshape(int w, int h) { glViewport(0, 0, (GLsizei) w, (GLsizei) h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); if (w <= h) glOrtho (-30.0, 30.0, -30.0*(GLfloat)h/(GLfloat)w, 30.0*(GLfloat)h/(GLfloat)w , -30., 30.); else glOrtho(-30.0*(GLfloat)w/(GLfloat)h, 30.0*(GLfloat)w/(GLfloat)h, -30.0, 30.0, -30., 30.); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); } void keyboard(unsigned char key, int x, int y) { switch (key) { case 27: exit(0); break; } } int main(int argc, char** argv) { glutInit(&argc, argv); glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); glutInitWindowSize (500, 500); glutInitWindowPosition (100, 100); glutCreateWindow (argv[0]); init (); glutDisplayFunc(display); glutReshapeFunc(reshape); glutKeyboardFunc (keyboard); glutMainLoop(); return 0; } void ctrlpolygon (void) { int i; /* The following code displays the control points as dots ...*/ glPointSize(5.0); glColor3f(0.0, 1.0, 1.0); glBegin(GL_POINTS); for (i = 0; i < 5; i++) glVertex3fv(&ctrlpoints[i][0]); glEnd(); /* ... and draws the Control Polygon as a line strip*/ glColor3f(0.0, 0.0, 0.0); glBegin(GL_LINE_STRIP); for (i = 0; i < 5; i++) glVertex3fv(&ctrlpoints[i][0]); glEnd(); } void axis (void){ /* Red Xw-axis */ glColor3f(1.0, 0.0, 0.0); glBegin(GL_LINES); glVertex3f(0.,0.,0.); glVertex3f(15.,0.,0.); glEnd(); /* Green Yw-axis*/ glColor3f(0.0, 1.0, 0.0); glBegin(GL_LINES); glVertex3f(0.,0.,0.); glVertex3f(0.,15.,0.); glEnd(); /* Blue Zw-axis */ glColor3f(0.0, 0.0, 1.0); glBegin(GL_LINES); glVertex3f(0.,0.,0.); glVertex3f(0.,0.,15.); glEnd(); } void house (void) { int i; /* This code draws the house. The house consists of 6 polygon as defined below: Two Ends: Ep and Ep2, Two Walls: Wp and Wp2, and Two Roofs: Rp and Rp2 The code also sets up the normals of the polygons. */ GLfloat Ep [5][3] = {{0.,0.,0.},{0.,0.,5.},{5.,0.,10.},{10.,0.,5.},{10.,0.,0.} }; GLfloat Wp[4][3] = {{0.,0.,0.},{0.,-10.0,0.},{0.,-10.,5.},{0.,0.,5.} }; GLfloat Rp [4][3] = {{0.,0.,5.},{0.,-10.,5.},{5.,-10.,10.},{5.,0.,10.} }; GLfloat Ep2 [5][3] = {{10.,-10.,0.},{10.,-10.,5.},{5.,-10.,10.},{0.,-10.,5.},{0.,-10.,0.}}; GLfloat Wp2 [4][3] = {{10.,0.,0.},{10.,0.,5.},{10.,-10.,5.},{10.,-10.,0.}}; GLfloat Rp2 [4][3] = {{10.,0.,5.},{5.,0.,10.},{5.,-10.,10.},{10.,-10.,5.} }; glPushMatrix (); glColor3f (0.8, 0.0, 0.0); glBegin(GL_POLYGON); glNormal3f (0.0,1.0,0.0); for (i = 0; i < 5; i++) glVertex3fv(&Ep[i][0]); glEnd(); glBegin(GL_POLYGON); glNormal3f (-1.0,0.0,0.0); for (i = 0; i < 4; i++) glVertex3fv(&Wp[i][0]); glEnd(); glBegin(GL_POLYGON); glNormal3f (-1.0,0.0,1.0); for (i = 0; i < 4; i++) glVertex3fv(&Rp[i][0]); glEnd(); glBegin(GL_POLYGON); glNormal3f (0.0,-1.0,0.0); for (i = 0; i < 5; i++) glVertex3fv(&Ep2[i][0]); glEnd(); glBegin(GL_POLYGON); glNormal3f (1.0,0.0,0.0); for (i = 0; i < 4; i++) glVertex3fv(&Wp2[i][0]); glEnd(); glBegin(GL_POLYGON); glNormal3f (1.0,0.0,1.0); for (i = 0; i < 4; i++) glVertex3fv(&Rp2[i][0]); glEnd(); glPopMatrix(); } void curves (void) { /*Insert code for Part 4 - Optional*/ } void texture (void) { /*Insert code for Part 5 here and where nescessary - Optional*/ }