Advertisement
k0mZ

Untitled

Dec 28th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1.  
  2. void CGLRenderer::PrepareSphere(float radius)
  3. {
  4. float x, y, z;
  5. int k = 0;
  6. int i = 0;
  7. const float PI = 3.145926;
  8. const int sectors = 20;
  9.  
  10. int r = 0;
  11. for (int i = 0; i < sectors + 1; i++)
  12. {
  13. for (int j = 0; j < sectors + 1; j++) {
  14. int nextStrip = j + (i + 1) * sectors;
  15. int currStrip = j + i * sectors;
  16.  
  17. indicesSphere[r++] = currStrip;
  18. indicesSphere[r++] = nextStrip;
  19. indicesSphere[r++] = nextStrip + 1;
  20.  
  21. indicesSphere[r++] = currStrip + 1;
  22. indicesSphere[r++] = currStrip;
  23. indicesSphere[r++] = nextStrip + 1;
  24.  
  25. }
  26. }
  27. sphereVert = r;
  28. texSphere = new float[sectors * sectors * 2];
  29.  
  30. int texCoords = 0;
  31. for (float lat = -PI / 2; lat <= PI / 2; lat += (PI / sectors)) {
  32. for (float lon = -PI; lon <= PI; lon += (2 * PI) / sectors) {
  33.  
  34. x = radius * cos(lat) * cos(lon);
  35. y = radius * cos(lat) * sin(lon);
  36. z = radius * sin(lat);
  37.  
  38. normalsSphere[i++] = x / radius;
  39. normalsSphere[i++] = y / radius;
  40. normalsSphere[i++] = z / radius;
  41.  
  42. vertSphere[k++] = x;
  43. vertSphere[k++] = y;
  44. vertSphere[k++] = z;
  45.  
  46. //Y = (X - A) / (B - A) * (D - C) + C
  47.  
  48. texSphere[texCoords++] = (lat - (-PI / 2)) / PI;
  49. texSphere[texCoords++] = (lat - (-PI)) / (2*PI);
  50. }
  51. }
  52.  
  53. //lat => x;
  54. //lon => y
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement