Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. for(int i = 0; i < N * M; i++)
  2. vertices[i].normal = vec3();
  3.  
  4. for(unsigned int z = 1; z < N; z++)
  5. {
  6. for(unsigned int x = 1; x < M; x++)
  7. {
  8. index = z * M + x;
  9. indices[indices_index++] = index;
  10. indices[indices_index++] = index - 1;
  11. indices[indices_index++] = index - M - 1;
  12.  
  13. vec3 a = vertices[index].pos;
  14. vec3 b = vertices[index - 1].pos;
  15. vec3 c = vertices[index - M - 1].pos;
  16. vec3 ab = b - a;
  17. vec3 ac = c - a;
  18. vec3 n = cross(ab, ac);
  19.  
  20. vertices[index ].normal = vertices[index ].normal + n;
  21. vertices[index - 1 ].normal = vertices[index - 1 ].normal + n;
  22. vertices[index - 1 - M].normal = vertices[index - 1 - M].normal + n;
  23.  
  24. indices[indices_index++] = index;
  25. indices[indices_index++] = index - M - 1;
  26. indices[indices_index++] = index - M;
  27.  
  28. a = vertices[index].pos;
  29. b = vertices[index - M].pos;
  30. c = vertices[index - M - 1].pos;
  31. ab = b - a;
  32. ac = c - a;
  33. n = cross(ab, ac);
  34.  
  35. vertices[index ].normal = vertices[index ].normal + n;
  36. vertices[index - M ].normal = vertices[index - M ].normal + n;
  37. vertices[index - M - 1].normal = vertices[index - M - 1].normal + n;
  38. }
  39. }
  40.  
  41. for(int i = 0; i < N * M; i++)
  42. vertices[index].normal = normalice(vertices[index].normal);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement