Advertisement
Guest User

bezier

a guest
Jun 18th, 2019
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.08 KB | None | 0 0
  1. #include <GL/gl.h>
  2. #include <GL/glu.h>
  3. #include <GL/glut.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6.  
  7. int screenWidth = 600;
  8. int screenHeight = 600;
  9. int fps = 60;
  10.  
  11. GLdouble cameraPos[] = {0.0, 0.0, 25.0};
  12. double baserotation = 180.0;
  13. double rotation = 0.0;
  14.  
  15. GLfloat lightAmb[] = {0.1, 0.1, 0.1, 1.0};
  16. GLfloat lightDif[] = {0.7, 0.7, 0.7, 1.0};
  17. GLfloat lightPos[] = {0, 0, 800, 1.0};
  18. GLfloat lightSpec[] = {1, 1, 1, 1};
  19.  
  20. GLfloat points[4][3] = {
  21.     {-5.0, 5.0, 0.0},
  22.     {0.0, 0.0, 0.0},
  23.     {5.0, -2.0, 0.0},
  24.     {7.0, 4.0, 0.0}
  25.     };
  26.  
  27. GLuint activePoint = 0;
  28.  
  29. void init(){
  30.     glEnable(GL_DEPTH_TEST);
  31.     glEnable(GL_POINT_SMOOTH);
  32.     glEnable(GL_MAP1_VERTEX_3);
  33. }
  34.  
  35. void display() {
  36.     glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  37.     glClearColor(0.0, 0.0, 0.0, 1.0);
  38.     glLoadIdentity ();
  39.  
  40.     gluLookAt(cameraPos[0], cameraPos[1], cameraPos[2], 0.0, 0.0, 0.0, 0.0, 1.0, 0.0);
  41.  
  42.  
  43.     glColor3f(1.0, 0.0, 0.0);
  44.     glPointSize(5);
  45.     glBegin(GL_POINTS);
  46.         (activePoint != 0) ? glColor3f(1.0, 0.0, 0.0) : glColor3f(0.0, 1.0, 0.0);
  47.         glVertex3fv(points[0]);
  48.         (activePoint != 1) ? glColor3f(1.0, 0.0, 0.0) : glColor3f(0.0, 1.0, 0.0);
  49.         glVertex3fv(points[1]);
  50.         (activePoint != 2) ? glColor3f(1.0, 0.0, 0.0) : glColor3f(0.0, 1.0, 0.0);
  51.         glVertex3fv(points[2]);
  52.         (activePoint != 3) ? glColor3f(1.0, 0.0, 0.0) : glColor3f(0.0, 1.0, 0.0);
  53.         glVertex3fv(points[3]);
  54.     glEnd();
  55.  
  56.     glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, &points[0][0]);
  57.     glMapGrid1f(30, 0, 1);
  58.     glEvalMesh1(GL_LINE, 0, 30);
  59.  
  60.     glFlush ();
  61.     glutPostRedisplay();
  62.     glutSwapBuffers();
  63. }
  64.  
  65. void reshape(int w, int h) {
  66.     glViewport(0, 0, (GLsizei) w, (GLsizei) h);
  67.     glMatrixMode(GL_PROJECTION);
  68.     glLoadIdentity();
  69.  
  70.     gluPerspective(45.0, (GLfloat)w / (GLfloat)h, 1.5, 300.0);
  71.  
  72.     glMatrixMode(GL_MODELVIEW);
  73. }
  74.  
  75. void keyboard(unsigned char key, int x, int y){
  76.     switch(key){
  77.         case 27 :
  78.         case 'q':
  79.             exit(0);
  80.             break;
  81.         case 32:
  82.             ++activePoint %= 4; break;
  83.         case 'w':
  84.             points[activePoint][1]++; break;
  85.         case 's':
  86.             points[activePoint][1]--; break;
  87.         case 'a':
  88.             points[activePoint][0]--; break;
  89.         case 'd':
  90.             points[activePoint][0]++; break;
  91.     }
  92. }
  93.  
  94. void timerfunc(int p){
  95.     rotation += 0.3;
  96.  
  97.     glutPostRedisplay();
  98.     glutTimerFunc(1000/fps, &timerfunc, 0);
  99. }
  100.  
  101. void menu(int value) {
  102.     switch(value) {
  103.         case 0:
  104.             exit(0);
  105.             break;
  106.     }
  107. }
  108.  
  109. int main(int argc, char *argv[]) {
  110.     glutInit(&argc, argv);
  111.     glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB);
  112.     glutInitWindowSize(screenWidth, screenHeight);
  113.     glutCreateWindow(argv[0]);
  114.     glutDisplayFunc(display);
  115.     glutReshapeFunc(reshape);
  116.     glutKeyboardFunc(keyboard);
  117.     glutTimerFunc(1000/fps, &timerfunc, 0);
  118.  
  119.     glutCreateMenu(menu);
  120.     glutAddMenuEntry("Wyjscie", 0);
  121.  
  122.     glutAttachMenu(GLUT_RIGHT_BUTTON);
  123.  
  124.     init();
  125.  
  126.     glutMainLoop();
  127.  
  128.     return 0;
  129. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement