Advertisement
Benjamin_Loison

void loadGround() and void Gl_object::addPart(double tex[4][

Aug 5th, 2018
376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.63 KB | None | 0 0
  1. void loadGround()
  2. {
  3.     unsigned int groundToRenderSize = groundToRender.size();
  4.     for(int g = 0; g < groundToRenderSize; g++)
  5.     {
  6.         // subChunkGroundSize
  7.         double tex[4][2] = {{1, 0}, {1, 1}, {0, 1}, {0, 0}}; // {{0, 1}, {1, 1}, {0, 0}, {1, 0}};
  8.  
  9.         vector<string> name = split(groundToRender[g], " ");
  10.         int chkXThousand = convertStrToInt(name[0]) * chunkGroundSize, chkYThousand = convertStrToInt(name[1]) * chunkGroundSize; // ex: 8000 15000
  11.  
  12.         vector<string> lines = getFileContent(groundFolder + groundToRender[g] + ".height");
  13.         print(groundFolder + groundToRender[g] + ".height");
  14.         groundLoaded[groundToRender[g]] = Gl_object("ground.jpg");
  15.         unsigned int linesSize = lines.size() - 1;
  16.         for(int i = 0; i < linesSize; i++)
  17.         {
  18.             vector<string> partsCurrentLine = split(lines[i], " ");
  19.             vector<string> partsNextLine = split(lines[i + 1], " ");
  20.  
  21.             unsigned int partsCurrentLineSize = partsCurrentLine.size() - 1;
  22.             for(int j = 0; j < partsCurrentLineSize; j++)
  23.             {
  24.                 // if(j <= 10) continue; // TEST MEMORY
  25.                 string xMin = convertNbToStr(chkXThousand + j * subChunkGroundSize), xMax = convertNbToStr(chkXThousand + (j + 1) * subChunkGroundSize);
  26.                 int chkYThousandPluschunkGroundSize = chkYThousand + chunkGroundSize;
  27.                 string yMin = convertNbToStr(chkYThousandPluschunkGroundSize - i * subChunkGroundSize), yMax = convertNbToStr(chkYThousandPluschunkGroundSize - (i + 1) * subChunkGroundSize);
  28.                 string zA = partsCurrentLine[j], zB = partsCurrentLine[j + 1], zC = partsNextLine[j + 1], zD = partsNextLine[j];
  29.                 string vertex[4][3] = {{xMin, yMin, zA},
  30.                                        {xMax, yMin, zB},
  31.                                        {xMax, yMax, zC},
  32.                                        {xMin, yMax, zD}};
  33.                 /*print(xMin + " " + yMin + " " + zA);
  34.                 print(xMax + " " + yMin + " " + zB);
  35.                 print(xMax + " " + yMax + " " + zC);
  36.                 print(xMin + " " + yMax + " " + zD);*/
  37. /*
  38.                 string vertex[4][3] = {{convertNbToStr(chkXThousand + j * 8), convertNbToStr(chkYThousand + chunkGroundSize - i * 8), partsCurrentLine[j]},
  39.                                        {convertNbToStr(chkXThousand + (j + 1) * 8), convertNbToStr(chkYThousand + chunkGroundSize - i * 8), partsCurrentLine[j + 1]},
  40.                                        {convertNbToStr(chkXThousand + j * 8), convertNbToStr(chkYThousand + chunkGroundSize - (i + 1) * 8), partsNextLine[j]},
  41.                                        {convertNbToStr(chkXThousand + (j + 1) * 8), convertNbToStr(chkYThousand + chunkGroundSize - (i + 1) * 8), partsNextLine[j + 1]}};*/
  42.  
  43.                 groundLoaded[groundToRender[g]].addPart(tex, vertex); // BREUH
  44.                 groundLoaded[groundToRender[g]].addPart(tex, vertex);
  45.                 groundLoaded[groundToRender[g]].addPart(tex, vertex);
  46.             }
  47.         }
  48.         // BEN WORKING AREA
  49.         /*vector<glm::vec3> testTmp;
  50.         testTmp.push_back(glm::vec3(0, 0, 0));
  51.         print(convertNbToStr(g) + " " + convertNbToStr(groundToRenderSize));
  52.         groundLoaded[groundToRender[g]].initializeTranslations(testTmp);*/
  53.     }
  54. }
  55.  
  56. void Gl_object::addPart(double tex[4][2], string inVertex[4][3])
  57. {
  58.  
  59.     //print("start");
  60.     double vertex[4][3];
  61.     for(int x = 0; x < 4; x++)
  62.         for(int y = 0; y < 3; y++)
  63.             vertex[x][y] = convertStrToDouble(inVertex[x][y]);
  64.  
  65.     glm::vec3 vertices[] = {glm::vec3(vertex[0][0], vertex[0][1], vertex[0][2]),
  66.                             glm::vec3(vertex[1][0], vertex[1][1], vertex[1][2]),
  67.                             glm::vec3(vertex[2][0], vertex[2][1], vertex[2][2]),
  68.                             glm::vec3(vertex[3][0], vertex[3][1], vertex[3][2]),};
  69.  
  70.     glm::vec2 texCoord[] = {glm::vec2(tex[0][0], tex[0][1]),   glm::vec2(tex[1][0], tex[1][1]),   glm::vec2(tex[2][0], tex[2][1]),   glm::vec2(tex[3][0], tex[3][1])};
  71.  
  72.  
  73.     m_vertices.insert(m_vertices.end(), begin(vertices), end(vertices));
  74.     m_texCoord.insert(m_texCoord.end(), begin(texCoord), end(texCoord));
  75.  
  76.     //for(int i = 0; i < 6; i++)
  77.     //    m_indices.push_back(i + partNumber * 6);
  78.  
  79.     m_indices.push_back(0 + partNumber * 4);
  80.     m_indices.push_back(1 + partNumber * 4);
  81.     m_indices.push_back(2 + partNumber * 4);
  82.     m_indices.push_back(0 + partNumber * 4);
  83.     m_indices.push_back(3 + partNumber * 4);
  84.     m_indices.push_back(2 + partNumber * 4);
  85.  
  86.  
  87.     //print(m_indices.size());
  88.  
  89.     partNumber++;
  90.     //print("finished");
  91.    
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement