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/core/model.cc126
-rw-r--r--src/core/model.h28
-rw-r--r--src/render/draw.cc47
3 files changed, 144 insertions, 57 deletions
diff --git a/src/core/model.cc b/src/core/model.cc
index 6a82989..a0aa489 100644
--- a/src/core/model.cc
+++ b/src/core/model.cc
@@ -117,7 +117,6 @@ void VertexArray::add_sphere()
}
- con_debug << "SPhere segment count " << count <<std::endl;
delete[] sintable;
delete[] costable;
}
@@ -206,10 +205,14 @@ Model::Model(std::string const & name) :
{
model_valid = false;
model_scale = 1.0f / 1024.0f;
+
model_first_vertex = 0;
model_first_evertex = 0;
+
model_vertex_count = 0;
+ model_vertex_countdetail = 0;
model_evertex_count = 0;
+ model_evertex_countdetail = 0;
std::string fn("maps/");
fn.append(name);
@@ -243,9 +246,8 @@ Model::Model(std::string const & name) :
float class_angle;
math::Color class_color;
unsigned int class_spawnflags;
+ bool brush_detail;
- model_first_vertex = VertexArray::vertex_index/3;
-
while (ifs) {
ifs.getline(data, 1023);
std::istringstream linestream(data);
@@ -262,6 +264,7 @@ Model::Model(std::string const & name) :
class_origin = math::Vector3f(0,0,0);
class_color = math::Color(1, 1, 1);
class_spawnflags = 0;
+ brush_detail = false;
}
level ++;
//cout << " LEVEL +" << level << std::endl;
@@ -273,7 +276,7 @@ Model::Model(std::string const & name) :
// for every face
std::vector<Vector3f *>points;
for (std::vector<Plane3f *>::iterator face = planes.begin(); face != planes.end(); face++) {
- make_face((*face), planes);
+ make_face((*face), planes, brush_detail);
}
}
@@ -282,6 +285,7 @@ Model::Model(std::string const & name) :
delete(*it);
}
planes.clear();
+ brush_detail = false;
} else if ((level == 1) && (class_name == "target_engine")) {
//con_debug << " engine at " << class_origin << "\n";
@@ -376,6 +380,13 @@ Model::Model(std::string const & name) :
linestream >> tmp; // )
linestream >> texture;
+ // 5 numbers (texture alignment?)
+ for (int i=0; i < 5; i++)
+ linestream >> tmp;
+
+ if (linestream >> tmp)
+ brush_detail = true;
+
//cout << data << std::endl;
//cout << "(" << p1 << ") (" << p2 << ") (" << p3 << ") " << texture << std::endl;
@@ -392,29 +403,76 @@ Model::Model(std::string const & name) :
ifs.close();
- model_first_evertex = VertexArray::vertex_index/3;
- if (model_etris.size()) {
+ if ((model_tris.size() + model_etris.size()) > 0) {
+
+ math::Vector3f center = (model_minbbox + model_maxbbox) / 2;
+
+ model_minbbox -= center;
+ model_maxbbox -= center;
+ model_radius = model_maxbbox.length();
+
+ // structural triangles
+ model_first_vertex = VertexArray::vertex_index/3;
+ for (std::list<Triangle *>::iterator it = model_tris.begin(); it != model_tris.end(); it++) {
+ Triangle *triangle = (*it);
+ if (!triangle->detail()) {
+ VertexArray::add_vertex(triangle->triangle_v0-center, triangle->normal(), triangle->color() );
+ VertexArray::add_vertex(triangle->triangle_v1-center, triangle->normal(), triangle->color() );
+ VertexArray::add_vertex(triangle->triangle_v2-center, triangle->normal(), triangle->color() );
+ model_vertex_count += 3;
+ }
+ }
+ // detail triangles
+ for (std::list<Triangle *>::iterator it = model_tris.begin(); it != model_tris.end(); it++) {
+ Triangle *triangle = (*it);
+ if (triangle->detail()) {
+ VertexArray::add_vertex(triangle->triangle_v0-center, triangle->normal(), triangle->color() );
+ VertexArray::add_vertex(triangle->triangle_v1-center, triangle->normal(), triangle->color() );
+ VertexArray::add_vertex(triangle->triangle_v2-center, triangle->normal(), triangle->color() );
+ model_vertex_countdetail += 3;
+ }
+ delete triangle;
+ }
+ model_tris.clear();
+
+ // structural etriangles
+ model_first_evertex = VertexArray::vertex_index/3;
+ for (std::list<Triangle *>::iterator it = model_etris.begin(); it != model_etris.end(); it++) {
+ Triangle *triangle = (*it);
+ if (!triangle->detail()) {
+ VertexArray::add_vertex(triangle->triangle_v0-center, triangle->normal(), triangle->color() );
+ VertexArray::add_vertex(triangle->triangle_v1-center, triangle->normal(), triangle->color() );
+ VertexArray::add_vertex(triangle->triangle_v2-center, triangle->normal(), triangle->color() );
+ model_evertex_count += 3;
+ }
+ }
+
+ // detail etriangles
for (std::list<Triangle *>::iterator it = model_etris.begin(); it != model_etris.end(); it++) {
Triangle *triangle = (*it);
- VertexArray::add_vertex(triangle->triangle_v0, triangle->normal(), triangle->color() );
- VertexArray::add_vertex(triangle->triangle_v1, triangle->normal(), triangle->color() );
- VertexArray::add_vertex(triangle->triangle_v2, triangle->normal(), triangle->color() );
- model_evertex_count += 3;
+ if (triangle->detail()) {
+ VertexArray::add_vertex(triangle->triangle_v0-center, triangle->normal(), triangle->color() );
+ VertexArray::add_vertex(triangle->triangle_v1-center, triangle->normal(), triangle->color() );
+ VertexArray::add_vertex(triangle->triangle_v2-center, triangle->normal(), triangle->color() );
+ model_evertex_countdetail += 3;
+ }
delete triangle;
}
model_etris.clear();
- }
- if ((model_vertex_count + model_evertex_count) > 0 ) {
- if (model_maxbbox.lengthsquared() > model_minbbox.lengthsquared()) {
- model_radius = model_maxbbox.length();
- } else {
- model_radius = model_minbbox.length();
+ // reposition light and engines
+ for (std::list<Engine *>::iterator eit = model_engine.begin(); eit != model_engine.end(); eit++) {
+ (*eit)->engine_location -= center;
}
- model_valid = true;
+
+ for (std::list<Light *>::iterator lit = model_light.begin(); lit != model_light.end(); lit++) {
+ (*lit)->light_location -= center;
+ }
+
+ model_valid = true;
}
- //con_debug << " maps/" << name << ".map " << model_face.size() << " polygons\n";
- con_debug << " maps/" << name << ".map " << tris() << " triangles" << std::endl;
+
+ con_debug << " maps/" << name << ".map " << tris() << " triangles (" << details() << " detail)" << std::endl;
}
Model::~Model()
@@ -432,7 +490,18 @@ Model::~Model()
model_light.clear();
}
-void Model::make_face(math::Plane3f *face, std::vector<math::Plane3f *> & planes)
+size_t Model::tris() const
+{
+ return ((model_vertex_count + model_vertex_countdetail +
+ model_evertex_count + model_evertex_countdetail)/3);
+}
+
+size_t Model::details() const
+{
+ return ((model_vertex_countdetail + model_evertex_countdetail)/3);
+}
+
+void Model::make_face(math::Plane3f *face, std::vector<math::Plane3f *> & planes, bool detail)
{
using math::Vector3f;
using math::Plane3f;
@@ -681,17 +750,19 @@ void Model::make_face(math::Plane3f *face, std::vector<math::Plane3f *> & planes
if (!color) {
// evertices will be added to the VertexArray after normal vertices
- Triangle *triangle = new Triangle(*(*vn1), *(*vn), *(*v0), n, 0, false);
+ Triangle *triangle = new Triangle(*(*vn1), *(*vn), *(*v0), n, 0, detail);
model_etris.push_back(triangle);
//VertexArray::add_evertex(*(*vn1), n);
//VertexArray::add_evertex(*(*vn), n);
//VertexArray::add_evertex(*(*v0), n);
//model_evertex_count += 3;
} else {
- VertexArray::add_vertex(*(*vn1), n, *color);
- VertexArray::add_vertex(*(*vn), n, *color);
- VertexArray::add_vertex(*(*v0), n, *color);
- model_vertex_count += 3;
+ Triangle *triangle = new Triangle(*(*vn1), *(*vn), *(*v0), n, color, detail);
+ model_tris.push_back(triangle);
+ //VertexArray::add_vertex(*(*vn1), n, *color);
+ //VertexArray::add_vertex(*(*vn), n, *color);
+ //VertexArray::add_vertex(*(*v0), n, *color);
+ //model_vertex_count += 3;
}
delete (*vn);
@@ -756,12 +827,13 @@ void Model::list()
{
for (std::map<std::string, Model*>::iterator mit = registry.begin(); mit != registry.end(); mit++) {
con_print << " " << (*mit).second->name() << " "
- << ((*mit).second->vertex_count() + (*mit).second->evertex_count())/3 << " triangles "
+ << (*mit).second->tris() << " triangles ("
+ << (*mit).second->details() << " detail) "
<< (*mit).second->model_engine.size() << " engines "
<< (*mit).second->model_light.size() << " lights\n";
}
con_print << registry.size() << " registered models" << std::endl;
- con_print << "vertex array " << VertexArray::vertex_index << "/" << VERTEXARRAYSIZE << " used" << std::endl;
+ con_print << "vertex array " << VertexArray::vertex_index/3 << "/" << VERTEXARRAYSIZE/3 << " used" << std::endl;
}
}
diff --git a/src/core/model.h b/src/core/model.h
index 4fc4d97..958acc0 100644
--- a/src/core/model.h
+++ b/src/core/model.h
@@ -87,7 +87,6 @@ public:
return engine_location;
}
-private:
math::Vector3f engine_location;
};
@@ -104,7 +103,6 @@ public:
inline bool strobe() const { return light_strobe; }
-private:
math::Vector3f light_location;
math::Color light_color;
bool light_strobe;
@@ -134,17 +132,26 @@ public:
/// first vertex in the global VertexArray
inline size_t first_vertex() const { return model_first_vertex; }
- /// number of vertexes in this model
- inline size_t vertex_count() const { return model_vertex_count; }
+ /// number of structural vertices in this model
+ inline size_t vertex_structural() const { return model_vertex_count; }
+
+ /// number of detail vertices
+ inline size_t vertex_detail() const { return model_vertex_countdetail; }
/// first vertex in the global VertexArray
inline size_t first_evertex() const { return model_first_evertex; }
- /// number of vertexes in this model
- inline size_t evertex_count() const { return model_evertex_count; }
+ /// number of structural evertices in this model
+ inline size_t evertex_structural() const { return model_evertex_count; }
- /// number of triangles in this mdel
- inline size_t tris() const { return (model_vertex_count + model_evertex_count)/3; }
+ /// number of detail evertices in this model
+ inline size_t evertex_detail() const { return model_evertex_countdetail; }
+
+ /// total number of triangles in this model
+ size_t tris() const;
+
+ /// number of detail triangles in this model
+ size_t details() const;
/// radius
inline float radius() const { return model_radius; }
@@ -175,7 +182,7 @@ public:
private:
- void make_face(math::Plane3f *face, std::vector<math::Plane3f *> & planes);
+ void make_face(math::Plane3f *face, std::vector<math::Plane3f *> & planes, bool detail);
void add_engine(Engine *engine);
void add_light(Light *light);
@@ -194,8 +201,11 @@ private:
size_t model_first_vertex;
size_t model_vertex_count;
+ size_t model_vertex_countdetail;
+
size_t model_first_evertex;
size_t model_evertex_count;
+ size_t model_evertex_countdetail;
};
}
diff --git a/src/render/draw.cc b/src/render/draw.cc
index 55f173c..c3aed94 100644
--- a/src/render/draw.cc
+++ b/src/render/draw.cc
@@ -37,6 +37,22 @@ const float drawfxdistance = 32.0f;
math::Vector3f camera_target;
float angle = 0;
+
+/* ----- Distance test functions ----------------------------------- */
+
+inline bool test_draw_distance(core::Entity *entity)
+{
+ return (entity->model() &&
+ (math::distancesquared(camera_target, entity->location()) <= (drawdistance*drawdistance*entity->model()->radius())));
+}
+
+inline bool test_drawfx_distance(core::Entity *entity)
+{
+ return (entity->model() &&
+ (math::distancesquared(camera_target, entity->location()) <= (drawfxdistance*drawfxdistance*entity->model()->radius())));
+}
+
+
/* ----- Default Entity shapes ------------------------------------- */
void draw_sphere(math::Color const & color, float radius)
@@ -140,10 +156,13 @@ void draw_entity_axis(core::Entity *entity)
void draw_model_vertex(core::Entity *entity)
{
+ size_t count = entity->model()->vertex_structural();
+ if (test_drawfx_distance(entity))
+ count += entity->model()->vertex_detail();
+
// draw model vertices
- if (entity->model()->vertex_count()) {
+ if (count) {
size_t index = entity->model()->first_vertex();
- size_t count = entity->model()->vertex_count();
if (r_drawwireframe && r_drawwireframe->value()) {
glDrawArrays(gl::LineLoop, index, count);
@@ -157,10 +176,13 @@ void draw_model_vertex(core::Entity *entity)
void draw_model_evertex(core::Entity *entity)
{
+ size_t count = entity->model()->evertex_structural();
+ if (test_drawfx_distance(entity))
+ count += entity->model()->evertex_detail();
+
// draw model evertices
- if (entity->model()->evertex_count()) {
+ if (count) {
size_t index = entity->model()->first_evertex();
- size_t count = entity->model()->evertex_count();
render::gl::color(entity->color());
@@ -260,23 +282,6 @@ void draw_model_shield(core::EntityControlable *entity)
/* ----- Render passes --------------------------------------------- */
-
-inline bool test_draw_distance(core::Entity *entity)
-{
- if (!entity->model())
- return false;
- else
- return (math::distancesquared(camera_target, entity->location()) <= (drawdistance*drawdistance*entity->model()->radius()));
-}
-
-inline bool test_drawfx_distance(core::Entity *entity)
-{
- if (!entity->model())
- return false;
- else
- return (math::distancesquared(camera_target, entity->location()) <= (drawfxdistance*drawfxdistance*entity->model()->radius()));
-}
-
/* Draw entities without model */
void draw_pass_default()
{