OpenGL C++ Plane Subdivison in QUADS, Iterative approach -


i have done recursive method subdivision accordingly post: opengl c++ plain subdivison in quads (radiosity) patches on arrays. however, need iterative because indices on array messed , impossible me interpolate colors manually.

the indexes array follows:

//  ___________________  // |    |    |    |    | // | 15 | 14 | 11 | 10 | // |____|____|____|____| // |    |    |    |    | // | 12 | 13 |  8 |  9 | // |____|____|____|____| // |    |    |    |    | // |  3 |  2 |  7 |  6 | // |____|____|____|____| // |    |    |    |    | // |  0 |  1 |  4 |  5 | // |____|____|____|____| 

and want them this:

//  ___________________  // |    |    |    |    | // | 12 | 13 | 14 | 15 | // |____|____|____|____| // |    |    |    |    | // |  8 |  9 | 10 | 11 | // |____|____|____|____| // |    |    |    |    | // |  4 |  5 |  6 |  7 | // |____|____|____|____| // |    |    |    |    | // |  0 |  1 |  2 |  3 | // |____|____|____|____| 

on post, user melak47 suggested how method in iterative way, however, didn't make well.

can have @ , give me code or suggestion on how solve problem, thank you!

how can vertices float values? each vertex have x y , z coordinates, can't multiply vertex 0 or lose coordinates. got bit lost there!

any1 understand this?

an iterative approach requires execute 2 nested loops rather using recursion.

vector<patch> scene::subdivide(patch& patch, glint subdivisions = 2) {    vector<patch> result;    // 4 vertices patch    vect ll = patch.getvertex(0);    vect lr = patch.getvertex(1);    vect ur = patch.getvertex(2);    vect ul = patch.getvertex(3);    float height = ???; // find vertical distance between ll , ul    float width = ???; // find horizontal distance between ll , lr    float rowheight = height / subdivisions;    float colwidth = width / subdivisions;    (int row = 0; row < subdivisions; ++row) {       float rowbottom = row * rowheight;       float rowtop = rowbottom + rowheight;       (int col = 0; col < subdivisions; ++col) {          float colleft = col * colwidth;          float colright = colleft + colwidth;          // create 4 vertices created combining colleft, colright,          // rowbottom , rowtop vect ll          ...          // create patch 4 vertices          patch p = ???;          // add result          result.push_back(p);       }    }    return result; } 

you might still able use recursion, require lot of math in section:

} else {     vector<patch> result2;     (auto& x : result) { // take each patch , subdive them further         auto subplanes = subdivide(x, iterations - 1);         // storing patches subdivisions returned         result2.insert(result2.end(), subplanes.begin(), subplanes.end());     }     return result2; // completed, return result } 

because need take result apart , divide rows finding appropriate insertion point, , taking subset of returned subplanes , inserting them there. not recommend approach.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -