Advertisement
Guest User

Untitled

a guest
Aug 19th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.23 KB | None | 0 0
  1. #include <GL/glut.h>
  2. #include <math.h>
  3.  
  4. void init ()
  5. {
  6.     glClearColor (1.0, 1.0, 1.0, 0.0);
  7.     glMatrixMode (GL_PROJECTION);
  8.     glLoadIdentity ( );
  9.     glOrtho(-400, 400, -400, 400,-500,500);
  10.     glMatrixMode (GL_MODELVIEW);
  11.     glLoadIdentity ( );
  12. }
  13.  
  14. void rectFace (GLint vert1, GLint vert2, GLint vert3, GLint vert4)
  15. {
  16.     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}};
  17.     glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  18.     glBegin(GL_LINE_LOOP);
  19.     glVertex3iv(bowVertices[vert1]);
  20.     glVertex3iv(bowVertices[vert2]);
  21.     glVertex3iv(bowVertices[vert3]);
  22.     glVertex3iv(bowVertices[vert4]);
  23.     glEnd();
  24. }
  25.  
  26. void triFace (GLint vert1, GLint vert2, GLint vert3)
  27. {
  28.     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}};
  29.     glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  30.     glBegin(GL_LINE_LOOP);
  31.     glVertex3iv(bowVertices[vert1]);
  32.     glVertex3iv(bowVertices[vert2]);
  33.     glVertex3iv(bowVertices[vert3]);
  34.     glEnd();
  35. }
  36.  
  37. void bow ()
  38. {
  39.     triFace(3, 2, 1);
  40.     rectFace(6, 3, 1, 4);
  41.     rectFace(5, 2, 3, 6);
  42.     rectFace(4, 1, 2, 5);
  43.     triFace(4, 5, 6);
  44. }
  45.  
  46. void boat ()
  47. {
  48.     //create base (2 triangular prisms)
  49.     bow();
  50.     //add piece to deck
  51.     //add 2 pieces onto deck piece
  52.     //add radio tower on left of two pieces
  53.     //add antenna to radio tower
  54. }
  55.  
  56. void draw ()
  57. {
  58.     glClear (GL_COLOR_BUFFER_BIT);
  59.     glColor3f(0.0,0.0,0.0);
  60.     glViewport (0, 0, 800, 600);
  61.     //water
  62.     //boat
  63.     boat();
  64.     //opera house
  65.     glutSwapBuffers();
  66. }
  67.  
  68. void keyboard (unsigned char key, int x, int y)
  69. {
  70.     switch (key)
  71.         {
  72.     case 'x':
  73.     case 'X':
  74.         glRotatef(10.0,1.0,0.0,0.0);
  75.         glutPostRedisplay();
  76.         break;
  77.     case 'y':
  78.     case 'Y':
  79.         glRotatef(10.0,0.0,1.0,0.0);
  80.         glutPostRedisplay();
  81.         break;
  82.     case 'i':
  83.     case 'I':
  84.         glLoadIdentity();
  85.         glutPostRedisplay();
  86.         break;
  87.     case 27:
  88.         exit(0);
  89.         break;
  90.     }
  91. }
  92. void main (int argc, char **argv)
  93. {
  94.     glutInit (&argc, argv);
  95.     glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB);
  96.     glutInitWindowPosition (0, 0);
  97.     glutInitWindowSize (800, 600);
  98.     glutCreateWindow ("Assignment 2");
  99.  
  100.     init ( );
  101.  
  102.     glutDisplayFunc (draw);
  103.     glutKeyboardFunc(keyboard);
  104.     glutMainLoop ( );
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement