Advertisement
Guest User

Untitled

a guest
Feb 27th, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. void Revolution::initRevolution() {
  2. if (_profile.size() < 2) return; // more than 2 vertices in the profile
  3.  
  4. vector<float> p;
  5. vector<float> n;
  6. vector<float> t;
  7.  
  8. vector<unsigned> index;
  9.  
  10. unsigned nbSlice=40; // include last slice that closes the object
  11. unsigned nbStack=_profile.size();
  12.  
  13. float theta = 0.0;
  14. float thetaStep = 2.0 * M_PI / (nbSlice - 1);
  15.  
  16. float phi = 0.0;
  17. float phiStep = M_PI / (_profile.size() - 1);
  18.  
  19. int tl, tr, bl, br;
  20.  
  21. float st, tt;
  22.  
  23.  
  24. vector<Vector3> normalProfile; // to compute normal profile
  25.  
  26. // Compute normal profile
  27. normalProfile.push_back(normSegment(_profile[1], _profile[0]));
  28. Vector3 nS1 = normalProfile[0];
  29. Vector3 nS2, nP;
  30.  
  31. for (unsigned i = 1; i < nbStack - 1; i++) {
  32. nS2 = normSegment(_profile[i + 1], _profile[i]);
  33. nP.mid(nS1, nS2);
  34. normalProfile.push_back(nP);
  35. nS1 = nS2;
  36. }
  37. normalProfile.push_back(normSegment(_profile[_profile.size() - 1],
  38. _profile[_profile.size() - 2]));
  39.  
  40.  
  41. // Compute attribute
  42. for (unsigned i = 0; i< nbStack; i++){
  43. for (unsigned j = 0; j< nbSlice; j++){
  44.  
  45. // Compute position
  46. Vector3 rotatedVector = _profile[i].rotationY(theta);
  47. p.push_back(rotatedVector.x());
  48. p.push_back(rotatedVector.y());
  49. p.push_back(rotatedVector.z());
  50.  
  51. // Compute normal sommet
  52. rotatedVector = normalProfile[i].rotationY(theta);
  53. n.push_back(rotatedVector.x());
  54. n.push_back(rotatedVector.y());
  55. n.push_back(rotatedVector.z());
  56.  
  57. // Compute texture sommet
  58. st = theta / (2 * M_PI);
  59. tt = (phi / M_PI);
  60. t.push_back(st);
  61. t.push_back(tt);
  62.  
  63. theta += thetaStep;
  64. }
  65. theta = 0;
  66. phi += phiStep;
  67. }
  68.  
  69. // Init index buffer
  70. for (unsigned i = 0; i < nbStack - 1; ++i) {
  71. for (unsigned j = 0; j < nbSlice - 1; ++j) {
  72.  
  73. bl = i * nbSlice + j;
  74. br = bl + 1;
  75.  
  76. tl = (i + 1) * nbSlice + j;
  77. tr = tl + 1;
  78.  
  79. // On comprend pas pourquoi, on doit changer ce vecteur pour coller à l'exemple !
  80. vector<int> ind = {tl, bl, br, br, tr, tl};
  81.  
  82. // br, bl, tl, tl, tr, br
  83.  
  84. index.insert(index.end(), ind.begin(), ind.end());
  85. }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement