Advertisement
Guest User

Untitled

a guest
Jan 28th, 2015
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.67 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4. #include <time.h>
  5. #include <GL/gl.h>
  6. #include <GL/glu.h>
  7. #include <GL/glut.h>
  8.  
  9. GLfloat zoom            = -7.0;
  10. GLfloat rotObsY         =  25.0;
  11. GLfloat rotObsX         =  20.0;
  12. int pomocnicze = -1;
  13.  
  14. void Rysuj(void)
  15. {
  16.     glEnable(GL_DEPTH_TEST);
  17.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  18.     glMatrixMode(GL_MODELVIEW);
  19.  
  20.     if(pomocnicze == 1)
  21.     {
  22.         glBegin(GL_LINES);
  23.    
  24.         glColor3f(1.0, 0.0, 0.0);
  25.         glVertex3f(-100.0, 0.0, 0.0);
  26.         glVertex3f(100.0, 0.0, 0.0);
  27.    
  28.         glColor3f(0.0,1.0,0.0);
  29.         glVertex3f(0.0, -100.0, 0.0);
  30.         glVertex3f(0.0, 100.0, 0.0);
  31.    
  32.         glColor3f(0.0,0.0,1.0);
  33.         glVertex3f(0.0, 0.0, -100.0);
  34.         glVertex3f(0.0, 0.0, 100.0);
  35.    
  36.         glEnd();
  37.     }
  38.  
  39.     glPushMatrix();
  40.     glColor3f(0.3f, 0.5f, 0.3f);
  41.     glutSolidCube(1.0);
  42.     glPopMatrix();
  43. }
  44.  
  45. void WyswietlObraz(void)
  46. {
  47.     glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
  48.     glPushMatrix();
  49.  
  50.     glTranslatef(0, 0, zoom);
  51.     glRotatef(rotObsX, 1, 0, 0);
  52.     glRotatef(rotObsY,0,1,0);
  53.  
  54.     Rysuj();
  55.     glPopMatrix();
  56.     glutSwapBuffers();
  57. }
  58.  
  59. void UstawParametryWidoku(int szerokosc, int wysokosc)
  60. {
  61.     glViewport(0, 0, szerokosc, wysokosc);
  62.     glShadeModel(GL_SMOOTH);
  63.     glClearColor(0, 0, 0, 0);  
  64.     glMatrixMode(GL_PROJECTION);
  65.     glLoadIdentity();
  66.     gluPerspective(40.0, (float)szerokosc/(float)wysokosc, 1.0, 1000.0);
  67.     glMatrixMode(GL_MODELVIEW);
  68.     glLoadIdentity();
  69. }
  70.  
  71. void ObslugaKlawiszySpecjalnych(int klawisz, int x, int y)
  72. {
  73.     switch(klawisz)
  74.         {
  75.         case GLUT_KEY_UP:
  76.             rotObsX = rotObsX + 2.0;
  77.             break;
  78.  
  79.         case GLUT_KEY_DOWN:
  80.             rotObsX = rotObsX - 2.0;
  81.             break;
  82.  
  83.         case GLUT_KEY_LEFT:
  84.             rotObsY = rotObsY - 2.0;
  85.             break;
  86.  
  87.         case GLUT_KEY_RIGHT:
  88.             rotObsY = rotObsY + 2.0;
  89.             break;
  90.            
  91.         case GLUT_KEY_PAGE_UP:
  92.             zoom = (zoom <= -10.0) ? zoom + 5.0 : zoom;
  93.             break;
  94.  
  95.         case GLUT_KEY_PAGE_DOWN:
  96.             zoom = (zoom >= -200.0) ? zoom - 5.0 : zoom;
  97.             break;
  98.         }
  99. }
  100.  
  101. void ObslugaKlawiatury(unsigned char klawisz, int x, int y)
  102. {
  103.     switch(klawisz)
  104.     {
  105.         case 'p': pomocnicze = -pomocnicze; break;
  106.         case 27: exit(0); break;
  107.     }
  108. }
  109.  
  110. int  main(int argc, char **argv)
  111. {
  112.     glutInit(&argc, argv);
  113.  
  114.     glutInitDisplayMode (GLUT_DOUBLE|GLUT_RGB|GLUT_DEPTH);
  115.     glutInitWindowPosition(100, 100);
  116.     glutInitWindowSize(600, 400);
  117.     glutCreateWindow("Cube");
  118.  
  119.     glEnable(GL_DEPTH_TEST);
  120.     glEnable(GL_LIGHTING);
  121.     glEnable(GL_LIGHT0);
  122.     glEnable(GL_COLOR_MATERIAL);
  123.  
  124.     glClearDepth(1000.0);
  125.     glClearColor (0.0, 0.0, 0.0, 0.0);
  126.  
  127.     glutDisplayFunc(WyswietlObraz);
  128.     glutReshapeFunc(UstawParametryWidoku);
  129.     glutIdleFunc(WyswietlObraz);
  130.     glutKeyboardFunc(ObslugaKlawiatury);
  131.     glutSpecialFunc(ObslugaKlawiszySpecjalnych);
  132.  
  133.     glutMainLoop();
  134.  
  135.     return 0;
  136. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement