Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/model/mapfile.cc39
1 files changed, 36 insertions, 3 deletions
diff --git a/src/model/mapfile.cc b/src/model/mapfile.cc
index 94a8eab..7775c8d 100644
--- a/src/model/mapfile.cc
+++ b/src/model/mapfile.cc
@@ -278,6 +278,7 @@ bool MapFile::read_patchdef()
}
math::Vector3f patchvertices[rows][columns];
+ math::Vector2f patchtexcoords[rows][columns];
// read rows
for (size_t r = 0; r < rows; r++) {
@@ -328,6 +329,7 @@ bool MapFile::read_patchdef()
}
patchvertices[r][c].assign(x, y, z);
+ patchtexcoords[r][c].assign(tx, ty);
}
if (!(linestream >> word)) {
@@ -394,8 +396,6 @@ bool MapFile::read_patchdef()
// patchvertices[][] are the control points as read from the .map file
// mesh[][] is a subdivideXsubdivide quad mesh calculated for each set of 9 control points in the patch
- // TODO texture coordinates, normals
-
// TODO variable sibdivision
const size_t subdivide = 4;
const float binom[3] = {1.0f, 2.0f, 1.0f};
@@ -405,6 +405,7 @@ bool MapFile::read_patchdef()
math::Vector3f mesh[subdivide + 1][subdivide +1];
math::Vector3f meshnormals[subdivide + 1][subdivide +1];
+ math::Vector2f meshtexcoords[subdivide + 1][subdivide +1];
for (size_t i = 0; i <= subdivide; i++) {
const float u = (float) i / (float) subdivide;
@@ -447,10 +448,35 @@ bool MapFile::read_patchdef()
}
}
+ // assign normal
meshnormals[i][j].assign(math::crossproduct(tan_u, tan_v));
meshnormals[i][j].normalize();
+
+ // calculate texture coordinates
+ size_t tr = r;
+ size_t tc = c;
+
+ float tu = u;
+ float tv = v;
+
+ if (u >= 0.5f) {
+ tr++;
+ tu -= 0.5f;
+ }
+ if (v >= 0.5f) {
+ tc++;
+ tv -= 0.5f;
+ }
+ tu *= 2.0f;
+ tv *= 2.0f;
+
+ meshtexcoords[i][j] = (
+ (patchtexcoords[tr+1][tc] * tu + patchtexcoords[tr][tc] * (1.0f - tu)) * (1.0f - tv) +
+ (patchtexcoords[tr+1][tc+1] * tu + patchtexcoords[tr][tc+1] * (1.0f - tu)) * tv
+ );
+
class_box.expand(mesh[i][j] * SCALE);
- }
+ }
}
const math::Vector3f zero;
@@ -465,9 +491,16 @@ bool MapFile::read_patchdef()
);
quad->n0().assign(meshnormals[i+1][j+1]);
+ quad->t0().assign(meshtexcoords[i+1][j+1]);
+
quad->n1().assign(meshnormals[i][j+1]);
+ quad->t1().assign(meshtexcoords[i][j+1]);
+
quad->n2().assign(meshnormals[i][j]);
+ quad->t2().assign(meshtexcoords[i][j]);
+
quad->n3().assign(meshnormals[i+1][j]);
+ quad->t3().assign(meshtexcoords[i+1][j]);
primitives->add_quad(quad);
}