Advertisement
Guest User

code

a guest
May 31st, 2015
284
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.56 KB | None | 0 0
  1. RawModel ModelLoader::createTerrain()
  2.     {
  3.         int count = TERRAIN_VERTICES * TERRAIN_VERTICES;
  4.         float vertices[count * 3];
  5.         float normals[count *3];
  6.         float colors[count * 3];
  7.         int indices[6 * (TERRAIN_VERTICES-1) * (TERRAIN_VERTICES*1)];
  8.         int vertexPointer = 0;
  9.         for(int i = 0; i < TERRAIN_VERTICES; i++){
  10.             for(int j = 0; j < TERRAIN_VERTICES; j++)
  11.             {
  12.                 vertices[vertexPointer*3] = (float)j/((float)TERRAIN_VERTICES - 1) * TERRAIN_SIZE;
  13.                 //HEIGHT HERE
  14.                 vertices[vertexPointer*3+1] = 0;
  15.                 vertices[vertexPointer*3+2] = (float)i/((float)TERRAIN_VERTICES - 1) * TERRAIN_SIZE;
  16.                 normals[vertexPointer*3] = 0;
  17.                 normals[vertexPointer*3+1] = 1;
  18.                 normals[vertexPointer*3+2]= 0;
  19.                 colors[vertexPointer*3] = ((float) rand() / (RAND_MAX));
  20.                 colors[vertexPointer*3+1] = ((float) rand() / (RAND_MAX));
  21.                 colors[vertexPointer*3+2] = ((float) rand() / (RAND_MAX));
  22.                
  23.                 vertexPointer++;
  24.             }}
  25.            
  26.         int pointer = 0;
  27.         for(int gz = 0; gz < TERRAIN_VERTICES-1; gz++)
  28.             for(int gx = 0; gx < TERRAIN_VERTICES-1; gx++)
  29.             {
  30.                 int topLeft = (gz*TERRAIN_VERTICES) + gx;
  31.                 int topRight = topLeft + 1;
  32.                 int bottomLeft = ((gz + 1) * TERRAIN_VERTICES) + gx;
  33.                 int bottomRight = bottomLeft +1;
  34.                 indices[pointer++] = topLeft;
  35.                 indices[pointer++] = bottomLeft;
  36.                 indices[pointer++] = topRight;
  37.                 indices[pointer++] = topRight;
  38.                 indices[pointer++] = bottomLeft;
  39.                 indices[pointer++] = bottomRight;
  40.             }
  41.         return createVAO_VCNIN(vertices, colors, normals, indices, 3*count, 6 * (TERRAIN_VERTICES-1) * (TERRAIN_VERTICES*1));
  42.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement