Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Revolution::initRevolution() {
- if (_profile.size() < 2) return; // more than 2 vertices in the profile
- vector<float> p;
- vector<float> n;
- vector<float> t;
- vector<unsigned> index;
- unsigned nbSlice=40; // include last slice that closes the object
- unsigned nbStack=_profile.size();
- float theta = 0.0;
- float thetaStep = 2.0 * M_PI / (nbSlice - 1);
- float phi = 0.0;
- float phiStep = M_PI / (_profile.size() - 1);
- int tl, tr, bl, br;
- float st, tt;
- vector<Vector3> normalProfile; // to compute normal profile
- // Compute normal profile
- normalProfile.push_back(normSegment(_profile[1], _profile[0]));
- Vector3 nS1 = normalProfile[0];
- Vector3 nS2, nP;
- for (unsigned i = 1; i < nbStack - 1; i++) {
- nS2 = normSegment(_profile[i + 1], _profile[i]);
- nP.mid(nS1, nS2);
- normalProfile.push_back(nP);
- nS1 = nS2;
- }
- normalProfile.push_back(normSegment(_profile[_profile.size() - 1],
- _profile[_profile.size() - 2]));
- // Compute attribute
- for (unsigned i = 0; i< nbStack; i++){
- for (unsigned j = 0; j< nbSlice; j++){
- // Compute position
- Vector3 rotatedVector = _profile[i].rotationY(theta);
- p.push_back(rotatedVector.x());
- p.push_back(rotatedVector.y());
- p.push_back(rotatedVector.z());
- // Compute normal sommet
- rotatedVector = normalProfile[i].rotationY(theta);
- n.push_back(rotatedVector.x());
- n.push_back(rotatedVector.y());
- n.push_back(rotatedVector.z());
- // Compute texture sommet
- st = theta / (2 * M_PI);
- tt = (phi / M_PI);
- t.push_back(st);
- t.push_back(tt);
- theta += thetaStep;
- }
- theta = 0;
- phi += phiStep;
- }
- // Init index buffer
- for (unsigned i = 0; i < nbStack - 1; ++i) {
- for (unsigned j = 0; j < nbSlice - 1; ++j) {
- bl = i * nbSlice + j;
- br = bl + 1;
- tl = (i + 1) * nbSlice + j;
- tr = tl + 1;
- // On comprend pas pourquoi, on doit changer ce vecteur pour coller à l'exemple !
- vector<int> ind = {tl, bl, br, br, tr, tl};
- // br, bl, tl, tl, tr, br
- index.insert(index.end(), ind.begin(), ind.end());
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement