SHARE
TWEET

Untitled

a guest May 26th, 2019 91 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // in srcs amount of polygons must be same, polygons must be of same dots
  2. bool drawTwining(std::vector<EllipticParabola> &srcs, GLfloat p) {
  3.     if (srcs.size() != 4 || p < 0 || p > 1) {
  4.         return false;
  5.     }
  6.  
  7.     glLineWidth(0.5f);
  8.     glColorMaterial(GL_FRONT, GL_DIFFUSE);
  9.     glEnable(GL_COLOR_MATERIAL);
  10.     glPolygonMode(GL_FRONT_AND_BACK, cubeMode);
  11.  
  12.     GLfloat c0 = (1 - p)*(1 - p)*(1 - p);
  13.     GLfloat c1 = 3 * p*(1 - p)*(1 - p);
  14.     GLfloat c2 = 3 * p*p*(1 - p);
  15.     GLfloat c3 = p*p*p;
  16.  
  17.     EllipticParabola t;
  18.     EllipticParabola* ep = &t;
  19.     ep->text_coords.clear();
  20.     ep->text_coords.push_back(std::pair<GLfloat, GLfloat>(1.f, 1.f));
  21.     ep->text_coords.push_back(std::pair<GLfloat, GLfloat>(0.f, 1.f));
  22.     ep->text_coords.push_back(std::pair<GLfloat, GLfloat>(0.f, 0.f));
  23.     ep->text_coords.push_back(std::pair<GLfloat, GLfloat>(1.f, 0.f));
  24.  
  25.     ep->texture = textures["VENUS"];
  26.     glLineWidth(0.5f);
  27.     glPolygonMode(GL_FRONT_AND_BACK, cubeMode);
  28.     if (text_enabled) {
  29.         glColorMaterial(GL_FRONT, GL_DIFFUSE);
  30.         glEnable(GL_COLOR_MATERIAL);
  31.         glBindTexture(GL_TEXTURE_2D, ep->texture);
  32.         for (const std::vector<int>& pol : srcs[0].polygons) {
  33.             int i = 0;
  34.  
  35.             glBegin(GL_POLYGON);
  36.  
  37.             i = 0;
  38.             for (int ind : pol) {
  39.                 ind *= 3;
  40.                 glTexCoord2f(ep->text_coords[i].first, ep->text_coords[i].second);
  41.                 //glColor3f(ep->points_color[ind], ep->points_color[ind + 1], ep->points_color[ind + 2]);
  42.                 glNormal3f(c0*srcs[0].points_normal[ind] + c1*srcs[1].points_normal[ind] + c2*srcs[2].points_normal[ind] + c3*srcs[3].points_normal[ind],
  43.                     c0*srcs[0].points_normal[ind + 1] + c1*srcs[1].points_normal[ind + 1] + c2*srcs[2].points_normal[ind + 1] + c3*srcs[3].points_normal[ind + 1],
  44.                     c0*srcs[0].points_normal[ind + 2] + c1*srcs[1].points_normal[ind + 2] + c2*srcs[2].points_normal[ind + 2] + c3*srcs[3].points_normal[ind + 2]);
  45.  
  46.                 glVertex3f(c0*srcs[0].points_pos[ind] + c1*srcs[1].points_pos[ind] + c2*srcs[2].points_pos[ind] + c3*srcs[3].points_pos[ind],
  47.                     c0*srcs[0].points_pos[ind + 1] + c1*srcs[1].points_pos[ind + 1] + c2*srcs[2].points_pos[ind + 1] + c3*srcs[3].points_pos[ind + 1],
  48.                     c0*srcs[0].points_pos[ind + 2] + c1*srcs[1].points_pos[ind + 2] + c2*srcs[2].points_pos[ind + 2] + c3*srcs[3].points_pos[ind + 2]);
  49.                 i++;
  50.             }
  51.  
  52.             glEnd();
  53.         }
  54.  
  55.         glBindTexture(GL_TEXTURE_2D, 0);
  56.     }
  57.     else {
  58.         glColorMaterial(GL_FRONT, GL_DIFFUSE);
  59.         glEnable(GL_COLOR_MATERIAL);
  60.         for (const std::vector<int>& pol : srcs[0].polygons) {
  61.             int i = 0;
  62.  
  63.             glBegin(GL_POLYGON);
  64.  
  65.             i = 0;
  66.             for (int ind : pol) {
  67.                 ind *= 3;
  68.                 glTexCoord2f(ep->text_coords[i].first, ep->text_coords[i].second);
  69.                 glColor3f(c0*srcs[0].points_color[ind] + c1*srcs[1].points_color[ind] + c2*srcs[2].points_color[ind] + c3*srcs[3].points_color[ind],
  70.                     c0*srcs[0].points_color[ind + 1] + c1*srcs[1].points_color[ind + 1] + c2*srcs[2].points_color[ind + 1] + c3*srcs[3].points_color[ind + 1],
  71.                     c0*srcs[0].points_color[ind + 2] + c1*srcs[1].points_color[ind + 2] + c2*srcs[2].points_color[ind + 2] + c3*srcs[3].points_color[ind + 2]);
  72.  
  73.                 glNormal3f(c0*srcs[0].points_normal[ind] + c1*srcs[1].points_normal[ind] + c2*srcs[2].points_normal[ind] + c3*srcs[3].points_normal[ind],
  74.                     c0*srcs[0].points_normal[ind + 1] + c1*srcs[1].points_normal[ind + 1] + c2*srcs[2].points_normal[ind + 1] + c3*srcs[3].points_normal[ind + 1],
  75.                     c0*srcs[0].points_normal[ind + 2] + c1*srcs[1].points_normal[ind + 2] + c2*srcs[2].points_normal[ind + 2] + c3*srcs[3].points_normal[ind + 2]);
  76.  
  77.                 glVertex3f(c0*srcs[0].points_pos[ind] + c1*srcs[1].points_pos[ind] + c2*srcs[2].points_pos[ind] + c3*srcs[3].points_pos[ind],
  78.                     c0*srcs[0].points_pos[ind + 1] + c1*srcs[1].points_pos[ind + 1] + c2*srcs[2].points_pos[ind + 1] + c3*srcs[3].points_pos[ind + 1],
  79.                     c0*srcs[0].points_pos[ind + 2] + c1*srcs[1].points_pos[ind + 2] + c2*srcs[2].points_pos[ind + 2] + c3*srcs[3].points_pos[ind + 2]);
  80.                 i++;
  81.             }
  82.  
  83.             glEnd();
  84.         }
  85.     }
  86.     /*for (const std::vector<int>& pol : srcs[0].polygons) {
  87.         glBegin(GL_POLYGON);
  88.  
  89.         for (int ind : pol) {
  90.             ind *= 3;
  91.             glColor3f(c0*srcs[0].points_color[ind] + c1*srcs[1].points_color[ind] + c2*srcs[2].points_color[ind] + c3*srcs[3].points_color[ind],
  92.                 c0*srcs[0].points_color[ind + 1] + c1*srcs[1].points_color[ind + 1] + c2*srcs[2].points_color[ind + 1] + c3*srcs[3].points_color[ind + 1],
  93.                 c0*srcs[0].points_color[ind + 2] + c1*srcs[1].points_color[ind + 2] + c2*srcs[2].points_color[ind + 2] + c3*srcs[3].points_color[ind + 2]);
  94.  
  95.             glNormal3f(c0*srcs[0].points_normal[ind] + c1*srcs[1].points_normal[ind] + c2*srcs[2].points_normal[ind] + c3*srcs[3].points_normal[ind],
  96.                 c0*srcs[0].points_normal[ind + 1] + c1*srcs[1].points_normal[ind + 1] + c2*srcs[2].points_normal[ind + 1] + c3*srcs[3].points_normal[ind + 1],
  97.                 c0*srcs[0].points_normal[ind + 2] + c1*srcs[1].points_normal[ind + 2] + c2*srcs[2].points_normal[ind + 2] + c3*srcs[3].points_normal[ind + 2]);
  98.  
  99.             glVertex3f(c0*srcs[0].points_pos[ind] + c1*srcs[1].points_pos[ind] + c2*srcs[2].points_pos[ind] + c3*srcs[3].points_pos[ind],
  100.                 c0*srcs[0].points_pos[ind + 1] + c1*srcs[1].points_pos[ind + 1] + c2*srcs[2].points_pos[ind + 1] + c3*srcs[3].points_pos[ind + 1],
  101.                 c0*srcs[0].points_pos[ind + 2] + c1*srcs[1].points_pos[ind + 2] + c2*srcs[2].points_pos[ind + 2] + c3*srcs[3].points_pos[ind + 2]);
  102.         }
  103.  
  104.         glEnd();
  105.     }*/
  106.  
  107.     return true;
  108. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top