Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- RawModel ModelLoader::createTerrain()
- {
- int count = TERRAIN_VERTICES * TERRAIN_VERTICES;
- float vertices[count * 3];
- float normals[count *3];
- float colors[count * 3];
- int indices[6 * (TERRAIN_VERTICES-1) * (TERRAIN_VERTICES*1)];
- int vertexPointer = 0;
- for(int i = 0; i < TERRAIN_VERTICES; i++){
- for(int j = 0; j < TERRAIN_VERTICES; j++)
- {
- vertices[vertexPointer*3] = (float)j/((float)TERRAIN_VERTICES - 1) * TERRAIN_SIZE;
- //HEIGHT HERE
- vertices[vertexPointer*3+1] = 0;
- vertices[vertexPointer*3+2] = (float)i/((float)TERRAIN_VERTICES - 1) * TERRAIN_SIZE;
- normals[vertexPointer*3] = 0;
- normals[vertexPointer*3+1] = 1;
- normals[vertexPointer*3+2]= 0;
- colors[vertexPointer*3] = ((float) rand() / (RAND_MAX));
- colors[vertexPointer*3+1] = ((float) rand() / (RAND_MAX));
- colors[vertexPointer*3+2] = ((float) rand() / (RAND_MAX));
- vertexPointer++;
- }}
- int pointer = 0;
- for(int gz = 0; gz < TERRAIN_VERTICES-1; gz++)
- for(int gx = 0; gx < TERRAIN_VERTICES-1; gx++)
- {
- int topLeft = (gz*TERRAIN_VERTICES) + gx;
- int topRight = topLeft + 1;
- int bottomLeft = ((gz + 1) * TERRAIN_VERTICES) + gx;
- int bottomRight = bottomLeft +1;
- indices[pointer++] = topLeft;
- indices[pointer++] = bottomLeft;
- indices[pointer++] = topRight;
- indices[pointer++] = topRight;
- indices[pointer++] = bottomLeft;
- indices[pointer++] = bottomRight;
- }
- return createVAO_VCNIN(vertices, colors, normals, indices, 3*count, 6 * (TERRAIN_VERTICES-1) * (TERRAIN_VERTICES*1));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement