Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- for(int i = 0; i < N * M; i++)
- vertices[i].normal = vec3();
- for(unsigned int z = 1; z < N; z++)
- {
- for(unsigned int x = 1; x < M; x++)
- {
- index = z * M + x;
- indices[indices_index++] = index;
- indices[indices_index++] = index - 1;
- indices[indices_index++] = index - M - 1;
- vec3 a = vertices[index].pos;
- vec3 b = vertices[index - 1].pos;
- vec3 c = vertices[index - M - 1].pos;
- vec3 ab = b - a;
- vec3 ac = c - a;
- vec3 n = cross(ab, ac);
- vertices[index ].normal = vertices[index ].normal + n;
- vertices[index - 1 ].normal = vertices[index - 1 ].normal + n;
- vertices[index - 1 - M].normal = vertices[index - 1 - M].normal + n;
- indices[indices_index++] = index;
- indices[indices_index++] = index - M - 1;
- indices[indices_index++] = index - M;
- a = vertices[index].pos;
- b = vertices[index - M].pos;
- c = vertices[index - M - 1].pos;
- ab = b - a;
- ac = c - a;
- n = cross(ab, ac);
- vertices[index ].normal = vertices[index ].normal + n;
- vertices[index - M ].normal = vertices[index - M ].normal + n;
- vertices[index - M - 1].normal = vertices[index - M - 1].normal + n;
- }
- }
- for(int i = 0; i < N * M; i++)
- vertices[index].normal = normalice(vertices[index].normal);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement