Created
October 22, 2014 12:27
-
-
Save shakesoda/c8d1d108101776f461d9 to your computer and use it in GitHub Desktop.
don't even worry about it
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Generate vertices | |
| const int size = 256; | |
| verts.reserve(size*size); | |
| faces.reserve(size*size); | |
| for (int j = 0; j < size; j++) | |
| { | |
| for (int i = 0; i < size; i++) | |
| { | |
| Vertex v; | |
| v.position = glm::vec3(i, j, 0); | |
| v.position.z += glm::perlin(v.position / 50.f) * 10.0f; | |
| v.position.z += glm::perlin(v.position / 20.f) * 5.0f; | |
| v.position.z += glm::perlin(v.position / 5.0f) / 2.0f; | |
| v.position.z += glm::perlin(v.position / 2.0f) / 4.0f; | |
| v.texcoord = glm::vec2(i / 10.0f, j / 10.0f); | |
| verts.push_back(v); | |
| } | |
| } | |
| // Build index buffer and calculate vertex normals. | |
| for (int j = 0; j < size-1; j++) | |
| { | |
| for (int i = 0; i < size-1; i++) | |
| { | |
| unsigned row = j*size; | |
| unsigned next = row+size; | |
| faces.push_back(Face(row+i, row+i+1, next+i)); | |
| faces.push_back(Face(next+i, row+i+1, next+i+1)); | |
| Face f1 = faces[faces.size()-2], f2 = faces[faces.size()-1]; | |
| Vertex *v[4]; | |
| v[0] = &verts[f1.verts[0]]; | |
| v[1] = &verts[f1.verts[1]]; | |
| v[2] = &verts[f1.verts[2]]; | |
| v[3] = &verts[f2.verts[2]]; | |
| v[0]->normal = mknormal( | |
| v[0]->position, | |
| v[1]->position, | |
| v[2]->position | |
| ); | |
| v[1]->normal = v[2]->normal = v[3]->normal = v[0]->normal; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment