diff options
author | Stijn Buys <ingar@osirion.org> | 2010-11-26 19:02:27 +0000 |
---|---|---|
committer | Stijn Buys <ingar@osirion.org> | 2010-11-26 19:02:27 +0000 |
commit | 772631d07bced1963b54978c7eb86ebfd69f633c (patch) | |
tree | 294dd732a9378d604831da6ea73d60c4f8c236d3 /src/model | |
parent | a96da42a7c1232dee986e1f658ee34440f78ac6c (diff) |
Brute-force patch subdivision
Diffstat (limited to 'src/model')
-rw-r--r-- | src/model/mapfile.cc | 51 |
1 files changed, 39 insertions, 12 deletions
diff --git a/src/model/mapfile.cc b/src/model/mapfile.cc index f57106d..76a75a9 100644 --- a/src/model/mapfile.cc +++ b/src/model/mapfile.cc @@ -388,18 +388,45 @@ bool MapFile::read_patchdef() } // load patch data into the model geometry - // TODO triangulate, assign texture coordinates - for (size_t r = 0; r < rows-1; r++) { - for (size_t c = 0; c < columns -1; c++) { - // unwind face counter-clockwise - Quad *quad = new Quad( - patchvertices[r+1][c+1], - patchvertices[r][c+1], - patchvertices[r][c], - patchvertices[r+1][c], - math::normal(patchvertices[r][c+1], patchvertices[r][c], patchvertices[r+1][c+1]) - ); - primitives->add_quad(quad); + // the patch is a set of quadratic B-splines with m = n =2 + // TODO texture coordinates, normals + + // TODO variable sibdivision + const size_t subdivide = 4; + const float binom[3] = {1, 2, 1}; + + for (size_t r = 0; r < rows-2; r +=2 ) { + for (size_t c = 0; c < columns -2; c += 2) { + math::Vector3f mesh[subdivide + 1][subdivide +1]; + + for (size_t i = 0; i <= subdivide; i++) { + const float u = (float) i / (float) subdivide; + for (size_t j = 0; j <= subdivide; j++) { + const float v = (float) j / (float) subdivide; + + for (size_t mi = 0; mi < 3; mi++) { + for (size_t mj = 0; mj < 3; mj++) { + mesh[i][j] += + patchvertices[r+mi][c+mj] * + binom[mi] * pow (u,mi) * pow(1.0f - u, 2-mi) * + binom[mj] * pow (v,mj) * pow(1.0f - v, 2-mj); + } + } + } + } + + for (size_t i = 0; i < subdivide; i++) { + for (size_t j = 0; j < subdivide; j++) { + Quad *quad = new Quad( + mesh[i+1][j+1], + mesh[i][j+1], + mesh[i][j], + mesh[i+1][j], + math::normal(mesh[i][j+1], mesh[i][j], mesh[i+1][j+1]) + ); + primitives->add_quad(quad); + } + } } } |