Advertisement
Guest User

Untitled

a guest
May 24th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 20.19 KB | None | 0 0
  1. #define GL_SILENCE_DEPRECATION  //эпл не любит опенгл :с
  2. #include <GLFW/glfw3.h>
  3. #include <stdlib.h>  //needed for exit function
  4. #include <iostream>
  5. #include <stdio.h>
  6. #include <cmath>
  7.  
  8. struct circleData {
  9.     int pointsAmount = 6;
  10.     float** pointData;
  11. };
  12.  
  13. struct point {
  14.     float xx;
  15.     float yy;
  16.     float zz;
  17. };
  18.  
  19. struct line {
  20.     float xx1;
  21.     float yy1;
  22.     float zz1;
  23.     float xx2;
  24.     float yy2;
  25.     float zz2;
  26. };
  27.  
  28. void keyboard_callback(GLFWwindow *window, int key, int scancode, int action, int mods);
  29. void drawCylinder(float cylinderHeight, circleData circle, float cylinderRadius, circleData *massOfCircles);
  30. void mouseButtonCallback( GLFWwindow *window, int button, int action, int mods);
  31. void dimetria();
  32. circleData* init(float cylinderHeight, circleData circle, float cylinderRadius);
  33. void cyrus_back(line mainLine, circleData *massOfCircles);
  34.  
  35. int rotate_y = 0;
  36. int rotate_x = 0;
  37. int rotate_z = 0;
  38.  
  39. float trans_x = 0;
  40. float trans_y = 0;
  41. float trans_z = 0;
  42.  
  43. float sc_x = 0.5;
  44. float sc_y = 0.5;
  45. float sc_z = 0.5;
  46.  
  47. int circlesAmount = 3;
  48.  
  49. float fi = (asin(0.625/sqrt(2.0-0.625*0.625))); //62,82
  50. float teta = (asin(0.625/sqrt(2.0))); //41,6
  51.  
  52. bool cyrus = false;
  53.  
  54. GLfloat m[16] = { cos(fi), sin(fi)*sin(teta), sin(fi)*cos(teta), 0,
  55.     0, cos(teta), -sin(teta), 0,
  56.     sin(fi), -cos(fi)*sin(teta), -cos(fi)*cos(teta), 0,
  57.     0, 0, 0, 1
  58. }; //как получилась матрица расписать два поворота по х, у
  59.  
  60.  
  61. circleData circle;
  62. circleData *mass;
  63. circleData *massOfCircles;
  64. line mainLine;
  65. point p1;
  66. point p2;
  67.  
  68. int main(int argc, char const *argv[]) {
  69.    
  70.     if(!glfwInit()) {
  71.         exit(EXIT_FAILURE);
  72.     }
  73.    
  74.     //glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);
  75.    
  76.     GLFWwindow *window = glfwCreateWindow(620, 620, "Rorate Cube", NULL, NULL);
  77.    
  78.     if (!window) {
  79.         glfwTerminate();
  80.         exit(EXIT_FAILURE);
  81.     }
  82.     glfwSetMouseButtonCallback(window, mouseButtonCallback);
  83.     glfwMakeContextCurrent(window);
  84.     glfwSwapInterval(1);
  85.    
  86.     glEnable(GL_DEPTH_TEST);
  87.    
  88.     mass = init(1.0, circle, 0.5);
  89.    
  90.     scanf("%f",&mainLine.xx1);
  91.     scanf("%f",&mainLine.yy1);
  92.     scanf("%f",&mainLine.zz1);
  93.  
  94.     scanf("%f",&mainLine.xx2);
  95.     scanf("%f",&mainLine.yy2);
  96.     scanf("%f",&mainLine.zz2);
  97.     /*
  98.     mainLine.xx1 = -1.0; // -1.0 -0.2 -0.9 0.9 0.6 0.5
  99.     mainLine.yy1 = -0.2;
  100.     mainLine.zz1 = -0.9;
  101.     mainLine.xx2 = 0.9;
  102.     mainLine.yy2 = 0.6;
  103.     mainLine.zz2 = 0.5;
  104.    
  105.     mainLine.xx1 = 0.9; // 0.9 0.9 -0.1 0.5 -0.9 0.5
  106.     mainLine.yy1 = 0.9; //1.0 0.0 0.0 0.0 0.0 0.0
  107.     mainLine.zz1 = -0.1;
  108.     mainLine.xx2 = 0.5;
  109.     mainLine.yy2 = -0.9;
  110.     mainLine.zz2 = 0.5;*/
  111.    
  112.     cyrus_back(mainLine, mass);
  113.    
  114.     while (!glfwWindowShouldClose(window))
  115.     {
  116.         float ratio;
  117.         int width, height;
  118.         glfwGetFramebufferSize(window, &width, &height);
  119.         ratio = width / (float) height;
  120.         glViewport(0, 0, width, height);
  121.        
  122.         glfwSetKeyCallback(window, keyboard_callback);
  123.        
  124.         glClearColor(0, 0, 0, 0);
  125.         glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
  126.        
  127.         glLoadIdentity();
  128.         glOrtho(-ratio, ratio, -1.f, 1.f, 1.f, -1.f);
  129.         //вращение
  130.        
  131.         glTranslatef(0.0, 0.0, 0.0);
  132.        
  133.         glScalef(sc_x, sc_y, sc_z);
  134.        
  135.         glRotatef(rotate_x, 1.0, 0.0, 0.0);  //повороты подломаны???
  136.         glRotatef(rotate_y, 0.0, 1.0, 0.0);
  137.         glRotatef(rotate_z, 0.0, 0.0, 1.0);
  138.        
  139.         //drawLine();
  140.         //drawCylinder(1.0, circle, 0.2, mass);
  141.        
  142.         glLineWidth(2);
  143.         glColor3f(0.9,0.6, 0.3);
  144.         glBegin(GL_LINES);
  145.         glVertex3f(0,0,0);
  146.         glVertex3f(0.7, 0.0, 0.0);
  147.         glEnd();
  148.         glBegin(GL_LINES);
  149.         glVertex3f(0,0,0);
  150.         glVertex3f(0, 0.7, 0);
  151.         glEnd();
  152.         glBegin(GL_LINES);
  153.         glVertex3f(0,0,0);
  154.         glVertex3f(0, 0, 0.7);
  155.         glEnd();
  156.        
  157.         glTranslatef(trans_x, trans_y, trans_z);
  158.         glTranslatef(0.0, 0.0, 0.0);
  159.         glLineWidth(4);
  160.        
  161.         if (!cyrus) {
  162.             glBegin(GL_LINES); // red side - FRONT
  163.             glColor3f(1.0,  0.0,  0.0);
  164.             glVertex3f( mainLine.xx1, mainLine.yy1, mainLine.zz1);
  165.             glVertex3f( mainLine.xx2, mainLine.yy2, mainLine.zz2);
  166.             glEnd();
  167.         } else
  168.             if (cyrus) {
  169.                 glTranslatef(0.0, 0.0, 0.0);
  170.                 glBegin(GL_LINES); // red side - FRONT
  171.                 glColor3f(0.0,  0.0,  1.0);
  172.                 glVertex3f( p1.xx, p1.yy, p1.zz);
  173.                 glVertex3f( p2.xx, p2.yy, p2.zz);
  174.                 glEnd();
  175.             }
  176.        
  177.         //dimetria(); //проекция через повороты/ротейты
  178.         //glMultMatrixf(m);
  179.         glLoadIdentity();
  180.         glScalef(sc_x, sc_y, sc_z);
  181.        
  182.         glRotatef(rotate_x, 1.0, 0.0, 0.0);  //повороты подломаны???
  183.         glRotatef(rotate_y, 0.0, 1.0, 0.0);
  184.         glRotatef(rotate_z, 0.0, 0.0, 1.0);
  185.        
  186.         glTranslatef(trans_x, trans_y, trans_z);
  187.        
  188.         //drawCube();*/
  189.         glTranslatef(0.0, 0.0, 0.0);
  190.         drawCylinder(1.0, circle, 0.5, mass);
  191.        
  192.        
  193.        
  194.        
  195.        
  196.         glfwSwapBuffers(window);
  197.         glfwPollEvents();
  198.     }
  199.    
  200.     glfwTerminate();
  201.     return 0;
  202. }
  203.  
  204. void cyrus_back(line mainLine,circleData *massOfCircles) {
  205.     int k = circle.pointsAmount + 2; //8
  206.     float x1, x2, x3, y1, y2, y3, z1, z2, z3;
  207.     point normals[k];
  208.     point f[k]; //точка, лежащая на i-ой плоскости
  209.     point w[k];
  210.     float d_scalar;
  211.     float w_scalar;
  212.     float t_down = 0;
  213.     float t_up = 1;
  214.     float t;
  215.     float A,B,C,D;
  216.    
  217.     point directr;
  218.     directr.xx = mainLine.xx2 - mainLine.xx1;
  219.     directr.yy = mainLine.yy2 - mainLine.yy1;
  220.     directr.zz = mainLine.zz2 - mainLine.zz1;
  221.     float minX=0, maxX=0, minY=0, maxY=0, minZ=0, maxZ=0;
  222.     //нормали боковых граней
  223.     for (int i=0; i<k-2; i++) {
  224.         x1 = massOfCircles[0].pointData[i][0];
  225.         y1 = massOfCircles[0].pointData[i][1];
  226.         z1 = massOfCircles[0].pointData[i][2];
  227.        
  228.         x2 = massOfCircles[0].pointData[i+1][0];
  229.         y2 = massOfCircles[0].pointData[i+1][1];
  230.         z2 = massOfCircles[0].pointData[i+1][2];
  231.        
  232.        
  233.         x3 = massOfCircles[circlesAmount-1].pointData[i][0];
  234.         y3 = massOfCircles[circlesAmount-1].pointData[i][1];
  235.         z3 = massOfCircles[circlesAmount-1].pointData[i][2];
  236.        
  237.         minX = fmin(minX, x1);
  238.         minX = fmin(minX, x2);
  239.         maxX = fmax(maxX, x1);
  240.         maxX = fmax(maxX, x2);
  241.        
  242.         minY = fmin(minY, y1);
  243.         minY = fmin(minY, y3);
  244.         maxY = fmax(maxY, y1);
  245.         maxY = fmax(maxY, y3);
  246.        
  247.         minZ = fmin(minZ, z1);
  248.         minZ = fmin(minZ, z2);
  249.         maxZ = fmax(maxZ, z1);
  250.         maxZ = fmax(maxZ, z2);
  251.        
  252.         A = y1*(z2-z3) + y2*(z3-z1) + y3*(z1-z2);
  253.         B = z1*(x2-x3) + z2*(x3-x1) + z3*(x1-x2);
  254.         C = x1*(y2-y3) + x2*(y3-y1) + x3*(y1-y2);
  255.         D = x1*(y2*z3-y3*z2) + x2*(y3*z1-y1*z3) + x3*(y1*z2-y2*z1);
  256.        
  257. //        if (D/A < 0) {
  258.             normals[i].xx = A;
  259.             normals[i].yy = B;
  260.             normals[i].zz = C;
  261. //        } else {
  262. //            normals[i].xx = -A;
  263. //            normals[i].yy = -B;
  264. //            normals[i].zz = -C;
  265. //        }
  266.        
  267.         f[i].xx = x1;
  268.         f[i].yy = y1;
  269.         f[i].zz = z1;
  270.     }
  271.     //нормаль дна
  272.     x1 = massOfCircles[0].pointData[0][0];
  273.     y1 = massOfCircles[0].pointData[0][1];
  274.     z1 = massOfCircles[0].pointData[0][2];
  275.    
  276.     x2 = massOfCircles[0].pointData[1][0];
  277.     y2 = massOfCircles[0].pointData[1][1];
  278.     z2 = massOfCircles[0].pointData[1][2];
  279.    
  280.     x3 = massOfCircles[0].pointData[2][0];
  281.     y3 = massOfCircles[0].pointData[2][1];
  282.     z3 = massOfCircles[0].pointData[2][2];
  283.    
  284.     A = y1*(z2-z3) + y2*(z3-z1) + y3*(z1-z2);
  285.     B = z1*(x2-x3) + z2*(x3-x1) + z3*(x1-x2);
  286.     C = x1*(y2-y3) + x2*(y3-y1) + x3*(y1-y2);
  287.     D = x1*(y2*z3-y3*z2) + x2*(y3*z1-y1*z3) + x3*(y1*z2-y2*z1);
  288.    
  289.     if (D/B > 0) {
  290.         normals[k-2].xx = A;
  291.         normals[k-2].yy = B;
  292.         normals[k-2].zz = C;
  293.     } else {
  294.         std::cout << "nize nula dno" << std::endl;
  295.         normals[k-2].xx = -A;
  296.         normals[k-2].yy = -B;
  297.         normals[k-2].zz = -C;
  298.     }
  299.    
  300.     f[k-2].xx = x1;
  301.     f[k-2].yy = y1;
  302.     f[k-2].zz = z1;
  303.     //нормаль крышки
  304.     x1 = massOfCircles[circlesAmount-1].pointData[0][0];
  305.     y1 = massOfCircles[circlesAmount-1].pointData[0][1];
  306.     z1 = massOfCircles[circlesAmount-1].pointData[0][2];
  307.    
  308.     x2 = massOfCircles[circlesAmount-1].pointData[1][0];
  309.     y2 = massOfCircles[circlesAmount-1].pointData[1][1];
  310.     z2 = massOfCircles[circlesAmount-1].pointData[1][2];
  311.    
  312.     x3 = massOfCircles[circlesAmount-1].pointData[2][0];
  313.     y3 = massOfCircles[circlesAmount-1].pointData[2][1];
  314.     z3 = massOfCircles[circlesAmount-1].pointData[2][2];
  315.    
  316.     A = y1*(z2-z3) + y2*(z3-z1) + y3*(z1-z2);
  317.     B = z1*(x2-x3) + z2*(x3-x1) + z3*(x1-x2);
  318.     C = x1*(y2-y3) + x2*(y3-y1) + x3*(y1-y2);
  319.     D = x1*(y2*z3-y3*z2) + x2*(y3*z1-y1*z3) + x3*(y1*z2-y2*z1);
  320.    
  321.     if (D/B > 0) {
  322.         normals[k-1].xx = A;
  323.         normals[k-1].yy = B;
  324.         normals[k-1].zz = C;
  325.     } else {
  326.         std::cout << "nize nula" << std::endl;
  327.         normals[k-1].xx = -A;
  328.         normals[k-1].yy = -B;
  329.         normals[k-1].zz = -C;
  330.     }
  331.    
  332.     f[k-1].xx = x1;
  333.     f[k-1].yy = y1;
  334.     f[k-1].zz = z1;
  335.     //нормали посчитаны //граничные точки плоскостей записаны
  336.    
  337.     //началось веселье
  338.     for (int i=1; i<k; i++) {
  339.         w[i].xx = mainLine.xx1 - f[i].xx;
  340.         w[i].yy = mainLine.yy1 - f[i].yy;
  341.         w[i].zz = mainLine.zz1 - f[i].zz;
  342.         //скалярное произв (directr, n[i])
  343.         d_scalar = directr.xx * normals[i].xx + directr.yy * normals[i].yy + directr.zz * normals[i].zz;
  344.         //скалярное произв (w[i], n[i])
  345.         w_scalar = w[i].xx * normals[i].xx + w[i].yy * normals[i].yy + w[i].zz * normals[i].zz;
  346.        
  347.         if (d_scalar == 0) {
  348.             if (w_scalar < 0) continue;
  349.             continue;
  350.         }
  351.         t = -w_scalar/d_scalar;
  352.         std::cout << "t = " << t << std::endl;
  353.         if (d_scalar > 0) {
  354.             if (t <= 1) {
  355.                 std::cout << t << " down " << t_down << std::endl;
  356.                 t_down = fmax(t, t_down);
  357.                 std::cout << "----down= " << t_down << std::endl;
  358.             }
  359.             //continue;
  360.         }
  361.         if (d_scalar < 0) {
  362.             if (t >= 0)  {
  363.                 std::cout << t << " up " << t_up << std::endl;
  364.                 t_up = fmin(t, t_up);
  365.                 std::cout << "----up= " << t_up << std::endl;
  366.             }
  367.            
  368.             //std::cout << "------- " << t_up << std::endl;
  369.         }
  370.     }
  371.    
  372.     p1.xx = (mainLine.xx1 + (mainLine.xx2 - mainLine.xx1)*t_down);
  373.     p1.yy = (mainLine.yy1 + (mainLine.yy2 - mainLine.yy1)*t_down);
  374.     p1.zz = (mainLine.zz1 + (mainLine.zz2 - mainLine.zz1)*t_down);
  375.    
  376.     p2.xx = (mainLine.xx1 + (mainLine.xx2 - mainLine.xx1)*t_up);
  377.     p2.yy = (mainLine.yy1 + (mainLine.yy2 - mainLine.yy1)*t_up);
  378.     p2.zz = (mainLine.zz1 + (mainLine.zz2 - mainLine.zz1)*t_up);
  379.    
  380.     if (p1.xx < p2.xx) {
  381.         if (p2.xx < minX) {
  382.             p2.xx = 0;
  383.             p1.xx = 0;
  384.             p2.yy = 0;
  385.             p1.yy = 0;
  386.             p2.zz = 0;
  387.             p1.zz = 0;
  388.         }
  389.     } else
  390.         if (p1.xx >= p2.xx) {
  391.             if (p2.xx > maxX) {
  392.                 p2.xx = 0;
  393.                 p1.xx = 0;
  394.                 p2.yy = 0;
  395.                 p1.yy = 0;
  396.                 p2.zz = 0;
  397.                 p1.zz = 0;
  398.             }
  399.         }
  400.    
  401.    
  402.     std::cout << p1.xx << " " << p1.yy << " " << p1.zz << std::endl;
  403.     std::cout << p2.xx << " " << p2.yy << " " << p2.zz << std::endl;
  404. }
  405.  
  406. circleData* init(float cylinderHeight, circleData circle, float cylinderRadius) {
  407.    
  408.     circleData *massOfCircles = new circleData[circlesAmount]; //массив из 4 элементов, каждый из которых содержит кол-во точек 1 кольца и координаты хуz каждой точки
  409.    
  410.     for (int ii=0; ii<circlesAmount; ii++) {
  411.         massOfCircles[ii].pointData = new float*[circle.pointsAmount];
  412.         for (int i=0; i<circle.pointsAmount; i++)
  413.             massOfCircles[ii].pointData[i] = new float[3];
  414.     }
  415.    
  416.    
  417.     float dh = cylinderHeight / circlesAmount;
  418.     float dy = 0.0;
  419.     for(int j=0; j<circlesAmount; j++) {
  420.        
  421.         for(int i=0; i<circle.pointsAmount; i++) { //пробег по точкам j-го круга
  422.             float degInRad = ((3.14159*2)*i)/circle.pointsAmount;
  423.             massOfCircles[j].pointData[i][0] = cos(degInRad)*cylinderRadius;
  424.             massOfCircles[j].pointData[i][1] = dy+dh-0.6;
  425.             massOfCircles[j].pointData[i][2] = sin(degInRad)*cylinderRadius;
  426.             //            std::cout << massOfCircles[j].pointData[i][0] << std::endl;
  427.             //            std::cout << massOfCircles[j].pointData[i][1] << std::endl;
  428.             //            std::cout << massOfCircles[j].pointData[i][2] << std::endl;
  429.         }
  430.         dy += dh;
  431.     }
  432.     return massOfCircles;
  433. }
  434.  
  435. void dimetria() {
  436.    
  437.     //glRotatef(180.0, 0.0, 1.0, 0.0);
  438.     glRotatef(-fi*(180/3.14) , 1.0, 0.0, 0.0);
  439.     glRotatef(-teta*(180/3.14) , 0.0, 1.0, 0.0);
  440.     //glRotatef(180.0 , 0.0, 1.0, 0.0);
  441. }
  442.  
  443. void drawCylinder(float cylinderHeight, circleData circle, float cylinderRadius, circleData *massOfCircles) {
  444.     float dh = cylinderHeight / circlesAmount;
  445.     float dy = 0.0;
  446.     for(int j=0; j<circlesAmount; j++) {
  447.         glBegin(GL_POLYGON);
  448.         for(int i=0; i<circle.pointsAmount; i++) { //пробег по точкам j-го круга
  449.             glColor3f(0.3,  0.0,  0.7);
  450.             glVertex3f(massOfCircles[j].pointData[i][0], massOfCircles[j].pointData[i][1], massOfCircles[j].pointData[i][2]);
  451.         }
  452.         glEnd();
  453.         dy += dh;
  454.        
  455.     }
  456.    
  457.     for (int j=0; j<circlesAmount-1; j++) {
  458.         for (int i=0; i<circle.pointsAmount-1; i++) {
  459.             glBegin(GL_POLYGON);
  460.             glColor3f(0.3,  0.0,  0.7);
  461.             glVertex3f(massOfCircles[j].pointData[i][0], massOfCircles[j].pointData[i][1], massOfCircles[j].pointData[i][2]);
  462.             glVertex3f(massOfCircles[j].pointData[i+1][0], massOfCircles[j].pointData[i+1][1], massOfCircles[j].pointData[i+1][2]);
  463.             glVertex3f(massOfCircles[j+1].pointData[i][0], massOfCircles[j+1].pointData[i][1], massOfCircles[j+1].pointData[i][2]);
  464.             glEnd();
  465.            
  466.             glBegin(GL_POLYGON);
  467.             glColor3f(0.04,  0.14,  0.6);
  468.             glVertex3f(massOfCircles[j].pointData[i+1][0], massOfCircles[j].pointData[i+1][1], massOfCircles[j].pointData[i+1][2]);
  469.             glVertex3f(massOfCircles[j+1].pointData[i][0], massOfCircles[j+1].pointData[i][1], massOfCircles[j+1].pointData[i][2]);
  470.             glVertex3f(massOfCircles[j+1].pointData[i+1][0], massOfCircles[j+1].pointData[i+1][1], massOfCircles[j+1].pointData[i+1][2]);
  471.             glEnd();
  472.         }
  473.     }
  474.     for (int j=0; j<circlesAmount-1; j++) {
  475.         glBegin(GL_POLYGON);
  476.         glColor3f(0.3,  0.0,  0.7);
  477.         glVertex3f(massOfCircles[j].pointData[circle.pointsAmount-1][0], massOfCircles[j].pointData[circle.pointsAmount-1][1], massOfCircles[j].pointData[circle.pointsAmount-1][2]);
  478.         glVertex3f(massOfCircles[j].pointData[0][0], massOfCircles[j].pointData[0][1], massOfCircles[j].pointData[0][2]);
  479.         glVertex3f(massOfCircles[j+1].pointData[circle.pointsAmount-1][0], massOfCircles[j+1].pointData[circle.pointsAmount-1][1], massOfCircles[j+1].pointData[circle.pointsAmount-1][2]);
  480.         glEnd();
  481.        
  482.         glBegin(GL_POLYGON);
  483.         glColor3f(0.04,  0.14,  0.6);
  484.         glVertex3f(massOfCircles[j].pointData[0][0], massOfCircles[j].pointData[0][1], massOfCircles[j].pointData[0][2]);
  485.         glVertex3f(massOfCircles[j+1].pointData[circle.pointsAmount-1][0], massOfCircles[j+1].pointData[circle.pointsAmount-1][1], massOfCircles[j+1].pointData[circle.pointsAmount-1][2]);
  486.         glVertex3f(massOfCircles[j+1].pointData[0][0], massOfCircles[j+1].pointData[0][1], massOfCircles[j+1].pointData[0][2]);
  487.         glEnd();
  488.     }
  489.     /*   for (int j=0; j<circlesAmount-1; j++) {
  490.      glBegin(GL_POLYGON);
  491.      glColor3f(0.3,  0.0,  0.7);
  492.      glVertex3f(massOfCircles[j].pointData[0][0], massOfCircles[j].pointData[0][1], massOfCircles[j].pointData[0][2]);
  493.      glVertex3f(massOfCircles[j].pointData[circle.pointsAmount-1][0], massOfCircles[j].pointData[circle.pointsAmount-1][1], massOfCircles[j].pointData[circle.pointsAmount-1][2]);
  494.      glVertex3f(massOfCircles[j+1].pointData[0][0], massOfCircles[j+1].pointData[0][1], massOfCircles[j+1].pointData[0][2]);
  495.      glEnd();
  496.      
  497.      glBegin(GL_POLYGON);
  498.      glColor3f(0.04,  0.14,  0.6);
  499.      glVertex3f(massOfCircles[j].pointData[circle.pointsAmount-1][0], massOfCircles[j].pointData[circle.pointsAmount-1][1], massOfCircles[j].pointData[circle.pointsAmount-1][2]);
  500.      glVertex3f(massOfCircles[j+1].pointData[0][0], massOfCircles[j+1].pointData[0][1], massOfCircles[j+1].pointData[0][2]);
  501.      glVertex3f(massOfCircles[j+1].pointData[circle.pointsAmount-1][0], massOfCircles[j+1].pointData[circle.pointsAmount-1][1], massOfCircles[j+1].pointData[circle.pointsAmount-1][2]);
  502.      glEnd();
  503.      }*/
  504. }
  505.  
  506. void keyboard_callback(GLFWwindow* window, int key, int scancode, int action, int mods) {
  507.    
  508.     if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
  509.         glfwSetWindowShouldClose(window, GL_TRUE);
  510.    
  511.     if (key == GLFW_KEY_UP && action == GLFW_PRESS)
  512.         rotate_x += 5;
  513.     if (key == GLFW_KEY_DOWN && action == GLFW_PRESS)
  514.         rotate_x -= 5;
  515.     if (key == GLFW_KEY_RIGHT && action == GLFW_PRESS)
  516.         rotate_y -= 5;
  517.     if (key == GLFW_KEY_LEFT && action == GLFW_PRESS)
  518.         rotate_y += 5;
  519.     if (key == GLFW_KEY_O && action == GLFW_PRESS)
  520.         rotate_z -= 5;
  521.     if (key == GLFW_KEY_L && action == GLFW_PRESS)
  522.         rotate_z += 5;
  523.    
  524.     if (key == GLFW_KEY_W && action == GLFW_PRESS)
  525.         trans_y += 0.05;
  526.     if (key == GLFW_KEY_A && action == GLFW_PRESS)
  527.         trans_x -= 0.05;
  528.     if (key == GLFW_KEY_D && action == GLFW_PRESS)
  529.         trans_x += 0.05;
  530.     if (key == GLFW_KEY_S && action == GLFW_PRESS)
  531.         trans_y -= 0.05;
  532.     //
  533.     if (key == GLFW_KEY_Z && action == GLFW_PRESS)
  534.         glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
  535.     if (key == GLFW_KEY_X && action == GLFW_PRESS)
  536.         glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  537.     //
  538.     if (key == GLFW_KEY_C && action == GLFW_PRESS){
  539.         circle.pointsAmount++;
  540.        
  541.         mass = init(1.0, circle, 0.5);
  542.     }
  543.     if (key == GLFW_KEY_V && action == GLFW_PRESS){
  544.        
  545.         circle.pointsAmount--;
  546.        
  547.         mass = init(1.0, circle, 0.5);
  548.        
  549.     }
  550.     if (key == GLFW_KEY_B && action == GLFW_PRESS){
  551.         circlesAmount++;
  552.        
  553.         mass = init(1.0, circle, 0.5);
  554.        
  555.        
  556.     }
  557.     if (key == GLFW_KEY_N && action == GLFW_PRESS){
  558.         circlesAmount--;
  559.        
  560.         mass = init(1.0, circle, 0.5);
  561.     }
  562.     if (key == GLFW_KEY_F && action == GLFW_PRESS){
  563.         //cyrus_back(mainLine);
  564.         cyrus = true;
  565.     }
  566.     if (key == GLFW_KEY_G && action == GLFW_PRESS){
  567.         //cyrus_back(mainLine);
  568.         cyrus = false;
  569.     }
  570. }
  571.  
  572. void mouseButtonCallback( GLFWwindow *window, int button, int action, int mods) {
  573.     if (button == GLFW_MOUSE_BUTTON_RIGHT && action == GLFW_PRESS) {
  574.         std::cout << fi << std::endl;
  575.         sc_x += 0.2;
  576.         sc_y += 0.2;
  577.         //sc_z += 0.2;
  578.     }
  579.    
  580.     if (button == GLFW_MOUSE_BUTTON_LEFT && action == GLFW_PRESS) {
  581.         if (sc_x > 0.2 && sc_y > 0.2) {
  582.             std::cout << teta << std::endl;
  583.             sc_x -= 0.2;
  584.             sc_y -= 0.2;
  585.             //sc_z -= 0.2;
  586.         }
  587.     }
  588. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement