From e8f928ab56d581cb06ec10c2da2cb6706bca6bb3 Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Wed, 12 Aug 2009 14:58:22 +0000 Subject: corrected .map texture coordinates --- src/model/mapfile.cc | 70 ++++++++++++++++++++-------------------------------- 1 file changed, 27 insertions(+), 43 deletions(-) (limited to 'src/model/mapfile.cc') diff --git a/src/model/mapfile.cc b/src/model/mapfile.cc index 21d318b..681a3be 100644 --- a/src/model/mapfile.cc +++ b/src/model/mapfile.cc @@ -20,20 +20,25 @@ namespace model { -/* - from radiant tools/quake3/map.c -*/ +// max geometry bounds +const float MAX_BOUNDS = 16384; + +const float MIN_DELTA = 10e-10; +// from radiant tools/quake3/q3map2/map.c math::Vector3f texture_baseaxis[18] = { - math::Vector3f(0,0,1), math::Vector3f(1,0,0), math::Vector3f(0,-1,0), // floor - math::Vector3f(0,0,-1), math::Vector3f(1,0,0), math::Vector3f(0,-1,0), // ceiling - math::Vector3f(1,0,0), math::Vector3f(0,1,0), math::Vector3f(0,0,-1), // west wall - math::Vector3f(-1,0,0), math::Vector3f(0,1,0), math::Vector3f(0,0,-1), // east wall - math::Vector3f(0,1,0), math::Vector3f(1,0,0), math::Vector3f(0,0,-1), // south wall - math::Vector3f(0,-1,0), math::Vector3f(1,0,0), math::Vector3f(0,0,-1) // north wall + // normal texture plane + math::Vector3f(0,0,1), math::Vector3f(1,0,0), math::Vector3f(0,-1,0), // floor + math::Vector3f(0,0,-1), math::Vector3f(1,0,0), math::Vector3f(0,-1,0), // ceiling + math::Vector3f(1,0,0), math::Vector3f(0,1,0), math::Vector3f(0,0,-1), // west wall + math::Vector3f(-1,0,0), math::Vector3f(0,1,0), math::Vector3f(0,0,-1), // east wall + math::Vector3f(0,1,0), math::Vector3f(1,0,0), math::Vector3f(0,0,-1), // south wall + math::Vector3f(0,-1,0), math::Vector3f(1,0,0), math::Vector3f(0,0,-1) // north wall + }; +// from radiant tools/quake3/q3map2/map.c // determines best orthagonal axis to project a texture onto a wall (must be identical in radiant!) void texture_axis_from_plane(const Face &face, math::Vector3f &xv, math::Vector3f &yv) { @@ -41,10 +46,13 @@ void texture_axis_from_plane(const Face &face, math::Vector3f &xv, math::Vector3 float dot = 0; float best = 0; + math::Vector3f n(face.normal()*-1); + n.normalize(); + for (size_t i=0 ; i<6 ; i++) { - dot = math::dotproduct(face.normal(), texture_baseaxis[i *3]); - if( dot > best + 0.0001f ) /* ydnar: bug 637 fix, suggested by jmonroe */ + dot = math::dotproduct(n, texture_baseaxis[i *3]); + if( dot > best + MIN_DELTA ) /* ydnar: bug 637 fix, suggested by jmonroe */ { best = dot; best_axis = i; @@ -55,6 +63,7 @@ void texture_axis_from_plane(const Face &face, math::Vector3f &xv, math::Vector3 yv.assign(texture_baseaxis[best_axis*3+2]); } +// from radiant tools/quake3/q3map2/map.c // creates world-to-texture mapping vecs for crappy quake plane arrangements void face_texture_verts(Face &face, const math::Vector2f &tex_shift, const float tex_rotate, const math::Vector2f & tex_scale) { @@ -117,25 +126,15 @@ void face_texture_verts(Face &face, const math::Vector2f &tex_shift, const float face.tex_shift().assign(tex_shift); } +// from radiant tools/quake3/q3map2/map.c +// project vertex into texture plane const math::Vector2f map_texture_coords(Face *face, const math::Vector3f &v) { - math::Vector2f t ( + return math::Vector2f ( (face->tex_shift().x + math::dotproduct(face->tex_vec(0), v)) / face->material()->size().width(), (face->tex_shift().y + math::dotproduct(face->tex_vec(1), v)) / face->material()->size().height() ); - - //con_debug << " texture coords for vertex (" << v << ") set to (" << t.x << "," << t.y << ")" << std::endl; - return t; } -/* - - // nearest-axial projection - dv->st[ 0 ] = s->vecs[ 0 ][ 3 ] + DotProduct( s->vecs[ 0 ], vTranslated ); - dv->st[ 1 ] = s->vecs[ 1 ][ 3 ] + DotProduct( s->vecs[ 1 ], vTranslated ); - dv->st[ 0 ] /= si->shaderWidth; - dv->st[ 1 ] /= si->shaderHeight; - -*/ // function to test spawnflags inline bool spawnflag_isset(unsigned int spawnflags, unsigned int flag) @@ -143,11 +142,6 @@ inline bool spawnflag_isset(unsigned int spawnflags, unsigned int flag) return ((spawnflags & flag) == flag); } -// max geometry bounds -const float MAX_BOUNDS = 16384; - -const float MIN_DELTA = 10e-10; - MapFile::MapFile() : map_center(0,0,0) { mapfile_name.clear(); @@ -309,13 +303,13 @@ bool MapFile::getline() std::string texture; int n = 0; - linestream >> p1; + linestream >> p1; // first plane vertex x y z linestream >> tmp; // ) linestream >> tmp; // ( - linestream >> p2; + linestream >> p2; // second plane vertex x y z linestream >> tmp; // ) linestream >> tmp; // ( - linestream >> p3; + linestream >> p3; // third plane vertex x y z linestream >> tmp; // ) Face *face = new Face(p1, p2, p3); @@ -335,18 +329,9 @@ bool MapFile::getline() // texture alignment float tx, ty, tr, tsx, tsy; - linestream >> tx >> ty; // texture translation + linestream >> tx >> ty; // texture shift linestream >> tr; // texture rotation angle linestream >> tsx >> tsy; // texture scale - /* - face->tex_translate().assign(tx, ty); - face->tex_rotate() = tr; - face->tex_scale().assign(tsx, tsy); - */ - - // from radiant: tools/quake3/q3map2map.c - tsx -= (floor( tsx / material->size().width()) * material->size().width()); - tsy -= (floor( tsy / material->size().height()) * material->size().height()); // store the texture transformation for this face face_texture_verts((*face), math::Vector2f(tx, ty), tr, math::Vector2f(tsx, tsy)); @@ -364,7 +349,6 @@ bool MapFile::getline() } face->surface_flags() = n; - planes.push_back(face); value_current.clear(); -- cgit v1.2.3