Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <GL/glut.h>
- #include <math.h>
- void init ()
- {
- glClearColor (1.0, 1.0, 1.0, 0.0);
- glMatrixMode (GL_PROJECTION);
- glLoadIdentity ( );
- glOrtho(-400, 400, -400, 400,-500,500);
- glMatrixMode (GL_MODELVIEW);
- glLoadIdentity ( );
- }
- void rectFace (GLint vert1, GLint vert2, GLint vert3, GLint vert4)
- {
- GLint bowVertices [6][3] = {{40.0, 0.0, 10.0}, {40.0, 0.0, -30.0}, {40.0, -20.0, -10.0}, {0.0, 0.0, 0.0}, {0.0, 0.0, -20.0}, {0.0, -20.0, -10.0}};
- glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
- glBegin(GL_LINE_LOOP);
- glVertex3iv(bowVertices[vert1]);
- glVertex3iv(bowVertices[vert2]);
- glVertex3iv(bowVertices[vert3]);
- glVertex3iv(bowVertices[vert4]);
- glEnd();
- }
- void triFace (GLint vert1, GLint vert2, GLint vert3)
- {
- GLint bowVertices [6][3] = {{40.0, 0.0, 10.0}, {40.0, 0.0, -30.0}, {40.0, -20.0, -10.0}, {0.0, 0.0, 0.0}, {0.0, 0.0, -20.0}, {0.0, -20.0, -10.0}};
- glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
- glBegin(GL_LINE_LOOP);
- glVertex3iv(bowVertices[vert1]);
- glVertex3iv(bowVertices[vert2]);
- glVertex3iv(bowVertices[vert3]);
- glEnd();
- }
- void bow ()
- {
- triFace(3, 2, 1);
- rectFace(6, 3, 1, 4);
- rectFace(5, 2, 3, 6);
- rectFace(4, 1, 2, 5);
- triFace(4, 5, 6);
- }
- void boat ()
- {
- //create base (2 triangular prisms)
- bow();
- //add piece to deck
- //add 2 pieces onto deck piece
- //add radio tower on left of two pieces
- //add antenna to radio tower
- }
- void draw ()
- {
- glClear (GL_COLOR_BUFFER_BIT);
- glColor3f(0.0,0.0,0.0);
- glViewport (0, 0, 800, 600);
- //water
- //boat
- boat();
- //opera house
- glutSwapBuffers();
- }
- void keyboard (unsigned char key, int x, int y)
- {
- switch (key)
- {
- case 'x':
- case 'X':
- glRotatef(10.0,1.0,0.0,0.0);
- glutPostRedisplay();
- break;
- case 'y':
- case 'Y':
- glRotatef(10.0,0.0,1.0,0.0);
- glutPostRedisplay();
- break;
- case 'i':
- case 'I':
- glLoadIdentity();
- glutPostRedisplay();
- break;
- case 27:
- exit(0);
- break;
- }
- }
- void main (int argc, char **argv)
- {
- glutInit (&argc, argv);
- glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
- glutInitWindowPosition (0, 0);
- glutInitWindowSize (800, 600);
- glutCreateWindow ("Assignment 2");
- init ( );
- glutDisplayFunc (draw);
- glutKeyboardFunc(keyboard);
- glutMainLoop ( );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement