Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2009-08-12 14:58:22 +0000
committerStijn Buys <ingar@osirion.org>2009-08-12 14:58:22 +0000
commite8f928ab56d581cb06ec10c2da2cb6706bca6bb3 (patch)
treeabd47ccee36625ad48957b56a5c6a79ff8d433ea /src
parent496a8de5147b79c47b4e6412794e6437a2b31e33 (diff)
corrected .map texture coordinates
Diffstat (limited to 'src')
-rw-r--r--src/model/mapfile.cc70
-rw-r--r--src/model/material.cc4
-rw-r--r--src/render/textures.cc2
3 files changed, 32 insertions, 44 deletions
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();
diff --git a/src/model/material.cc b/src/model/material.cc
index 280ebba..f9f330d 100644
--- a/src/model/material.cc
+++ b/src/model/material.cc
@@ -43,8 +43,10 @@ void Material::set_texture(const std::string &texture)
{
material_texture.assign(texture);
- if (material_loaderfunc)
+ if (material_loaderfunc) {
material_loaderfunc(this);
+ //con_debug << " material " << name() << " " << size().width() << "x" << size().height() << std::endl;
+ }
}
void Material::set_texture_id(const size_t texture_id)
diff --git a/src/render/textures.cc b/src/render/textures.cc
index 8d180b7..6817aa5 100644
--- a/src/render/textures.cc
+++ b/src/render/textures.cc
@@ -79,6 +79,7 @@ void Textures::clear()
if (textures[i]) {
glDeleteTextures(1, &textures[i]);
}
+ texture_size[i].clear();
}
registry.clear();
@@ -94,6 +95,7 @@ void Textures::unload(const std::string &name)
if (textures[id]) {
glDeleteTextures(1, &textures[id]);
textures[id] = 0;
+ texture_size[id].clear();
}
registry.erase(it);
}