diff options
-rw-r--r-- | osirion.kdevelop.pcs | bin | 514385 -> 524876 bytes | |||
-rw-r--r-- | osirion.kdevses | 24 | ||||
-rw-r--r-- | src/client/view.cc | 4 | ||||
-rw-r--r-- | src/core/model.cc | 82 | ||||
-rw-r--r-- | src/core/model.h | 4 | ||||
-rw-r--r-- | src/render/Makefile.am | 4 | ||||
-rw-r--r-- | src/render/draw.cc | 87 | ||||
-rw-r--r-- | src/render/draw.h | 2 | ||||
-rw-r--r-- | src/render/sphere.cc | 132 | ||||
-rw-r--r-- | src/render/sphere.h | 46 |
10 files changed, 158 insertions, 227 deletions
diff --git a/osirion.kdevelop.pcs b/osirion.kdevelop.pcs Binary files differindex 02ebf51..6fb0f8e 100644 --- a/osirion.kdevelop.pcs +++ b/osirion.kdevelop.pcs diff --git a/osirion.kdevses b/osirion.kdevses index 7c59f5b..303a055 100644 --- a/osirion.kdevses +++ b/osirion.kdevses @@ -1,19 +1,25 @@ <?xml version = '1.0' encoding = 'UTF-8'?> <!DOCTYPE KDevPrjSession> <KDevPrjSession> - <DocsAndViews NumberOfDocuments="4" > - <Doc0 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/render/draw.cc" > - <View0 Encoding="" line="453" Type="Source" /> + <DocsAndViews NumberOfDocuments="6" > + <Doc0 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/core/model.h" > + <View0 Encoding="" line="27" Type="Source" /> </Doc0> - <Doc1 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/game/game.h" > - <View0 Encoding="" line="32" Type="Source" /> + <Doc1 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/core/model.cc" > + <View0 Encoding="" line="64" Type="Source" /> </Doc1> - <Doc2 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/core/model.cc" > - <View0 Encoding="" line="630" Type="Source" /> + <Doc2 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/render/sphere.cc" > + <View0 Encoding="" line="84" Type="Source" /> </Doc2> - <Doc3 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/render/sphere.cc" > - <View0 Encoding="" line="82" Type="Source" /> + <Doc3 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/render/sphere.h" > + <View0 Encoding="" line="39" Type="Source" /> </Doc3> + <Doc4 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/render/draw.cc" > + <View0 Encoding="" line="48" Type="Source" /> + </Doc4> + <Doc5 NumberOfViews="1" URL="file:///home/ingar/projects/osirion/osirion-work/src/client/view.cc" > + <View0 Encoding="" line="0" Type="Source" /> + </Doc5> </DocsAndViews> <pluginList> <kdevdebugger> diff --git a/src/client/view.cc b/src/client/view.cc index 15b8606..a19f98a 100644 --- a/src/client/view.cc +++ b/src/client/view.cc @@ -148,8 +148,8 @@ void draw_status() std::stringstream stats; stats << "fps " << std::setw(6) << fps << "\n"; if (core::application()->connected()) { - stats << "tris " << std::setw(6) << render::Stats::tris << "\n"; - stats << "spheres " << std::setw(3) << render::Stats::spheres << "\n"; + stats << "tris " << std::setw(5) << render::Stats::tris << "\n"; + stats << "quads " << std::setw(5) << render::Stats::quads << "\n"; } draw_text(video::width-CHARWIDTH*12, CHARHEIGHT*2, stats); } diff --git a/src/core/model.cc b/src/core/model.cc index 9f135b4..6a82989 100644 --- a/src/core/model.cc +++ b/src/core/model.cc @@ -19,7 +19,9 @@ namespace core { -const float MAX_BOUNDS = 8192; +//const float MAX_BOUNDS = 8192; +const float MAX_BOUNDS = 16384; + const float delta = 10e-10; /* ---------- core::VertexArray ------------------------------------ */ @@ -36,18 +38,88 @@ size_t VertexArray::vertex_index; void VertexArray::clear() { + vertex_index = 0; + // The VertexArray is only used by the client if (!(Cvar::sv_dedicated && Cvar::sv_dedicated->value())) { memset(vertex, 0, sizeof(vertex)); memset(vertex_color, 0, sizeof(vertex_color)); memset(vertex_normal, 0, sizeof(vertex_normal)); - //memset(evertex, 0, sizeof(evertex)); - //memset(evertex_normal, 0, sizeof(evertex_normal)); + add_sphere(); } - vertex_index = 0; - //evertex_index = 0; + +} + +void VertexArray::add_sphere() +{ + // load sphere vertices into the VertexArray + + // build sin/cos table + float *sintable; + float *costable; + + sintable = new float[SPHERESEGMENTS]; + costable = new float[SPHERESEGMENTS]; + float d = 2 * M_PI / (SPHERESEGMENTS-1); + + for (int i=0; i < SPHERESEGMENTS; i++) { + sintable[i] = sin( d * (float) i ); + costable[i] = cos ( d * (float) i ); + } + + // draw body + math::Color white(1.0f, 1.0f, 1.0f); + math::Vector3f v; + math::Vector3f n; + + int count; + + for (int j=0; j < SPHERESEGMENTS-1; j++) { + float r = sintable[j]; + float r1 = sintable[j+1]; + + // glBegin + v = math::Vector3f(r, 0, costable[j]); + n = v; + n.normalize(); + //normal(n); + //vertex(v); + add_vertex(v, n, white); + + v = math::Vector3f(r1, 0, costable[j+1]); + n = v; + n.normalize(); + //normal(n); + //vertex(v); + add_vertex(v, n, white); + + count =2; + + for (int i = SPHERESEGMENTS-1; i >= 0; i--) { + v = math::Vector3f(r*costable[i], r*sintable[i], costable[j]); + n = v; + n.normalize(); + //normal(n); + //vertex(v); + add_vertex(v, n, white); + + v = math::Vector3f(r1*costable[i], r1*sintable[i], costable[j+1]); + n = v; + n.normalize(); + //normal(n); + //vertex(v); + add_vertex(v, n, white); + count +=2; + } + // glEnd + + } + + con_debug << "SPhere segment count " << count <<std::endl; + delete[] sintable; + delete[] costable; } void VertexArray::add_vertex(math::Vector3f const &v, math::Vector3f const &n, math::Color const &color) { diff --git a/src/core/model.h b/src/core/model.h index 51e9ca7..4fc4d97 100644 --- a/src/core/model.h +++ b/src/core/model.h @@ -25,6 +25,7 @@ namespace core /// size of the global vertex array - 32M const size_t VERTEXARRAYSIZE=65536*512; +const int SPHERESEGMENTS=33; /// global vertex array class VertexArray @@ -40,6 +41,9 @@ public: static void clear(); static void add_vertex(math::Vector3f const &v, math::Vector3f const &n, math::Color const &color); + +private: + static void add_sphere(); }; /// a model triangle diff --git a/src/render/Makefile.am b/src/render/Makefile.am index d9a8301..87f3ba3 100644 --- a/src/render/Makefile.am +++ b/src/render/Makefile.am @@ -3,5 +3,5 @@ METASOURCES = AUTO noinst_LTLIBRARIES = librender.la librender_la_LDFLAGS = -avoid-version -no-undefined @GL_LIBS@ librender_la_LIBADD = $(top_builddir)/src/math/libmath.la -librender_la_SOURCES = draw.cc gl.cc render.cc sphere.cc text.cc tga.cc -noinst_HEADERS = draw.h gl.h render.h sphere.h text.h tga.h +librender_la_SOURCES = draw.cc gl.cc render.cc text.cc tga.cc +noinst_HEADERS = draw.h gl.h render.h text.h tga.h diff --git a/src/render/draw.cc b/src/render/draw.cc index 590cddd..55f173c 100644 --- a/src/render/draw.cc +++ b/src/render/draw.cc @@ -8,22 +8,19 @@ #include "core/model.h" #include "render/render.h" #include "render/draw.h" -#include "render/sphere.h" namespace render { -size_t Stats::tris; -size_t Stats::spheres; +size_t Stats::tris = 0; +size_t Stats::quads = 0; void Stats::clear() { tris = 0; - spheres = 0; + quads = 0; } -Sphere sphere(1); - math::Vector3f v0(1, -1, 1); math::Vector3f v1(1, 1, 1); math::Vector3f v2(-1, 1, 1); @@ -42,12 +39,32 @@ float angle = 0; /* ----- Default Entity shapes ------------------------------------- */ +void draw_sphere(math::Color const & color, float radius) +{ + //gl::push(); + gl::scale(radius, radius, radius); + gl::color(color); + + size_t index = 0; + size_t count = (core::SPHERESEGMENTS+1)*2; + + // draw body + for (int j=0; j < core::SPHERESEGMENTS-1; j++) { + if (r_drawwireframe && r_drawwireframe->value()) { + glDrawArrays(gl::LineLoop, index, count); + } else { + glDrawArrays(gl::QuadStrip, index, count); + } + index += count; + Stats::quads += count/2-1; + } + + //gl::pop(); +} + void draw_entity_sphere(core::Entity *entity) { - sphere.sphere_color = entity->color(); - sphere.radius = entity->radius(); - sphere.draw(); - Stats::spheres += 1; + draw_sphere(entity->color(), entity->radius()); } void draw_entity_cube(core::Entity *entity) @@ -198,16 +215,17 @@ void draw_model_engines(core::EntityControlable *entity) void draw_model_radius(core::Entity *entity) { - sphere.sphere_color = entity->color(); - sphere.sphere_color.a = 0.25f; - sphere.radius = entity->model()->radius(); - sphere.draw(); - Stats::spheres += 1; + + math::Color color = entity->color(); + color.a = 0.25f; + + draw_sphere(color, entity->model()->radius()); } void draw_model_shield(core::EntityControlable *entity) { // shield rotation + //gl::push(); gl::rotate(angle, 0.0f, 0.0f, 1.0f ); gl::scale(entity->model()->radius(), entity->model()->radius(), entity->model()->radius()); @@ -237,7 +255,7 @@ void draw_model_shield(core::EntityControlable *entity) gl::end(); - gl::rotate(-angle, 0.0f, 0.0f, 1.0f ); + //gl::pop(); } /* ----- Render passes --------------------------------------------- */ @@ -266,14 +284,6 @@ void draw_pass_default() for (it=core::Entity::registry.begin(); it != core::Entity::registry.end(); it++) { core::Entity *entity = (*it).second; - // load entity models if necessary - if (!entity->model() && entity->modelname().size()) { - entity->entity_model = core::Model::get(entity->modelname()); - - if (!entity->model()) - entity->entity_modelname.clear(); - } - // draw entities without model if (!entity->model()) { gl::push(); @@ -316,6 +326,15 @@ void draw_pass_model_vertex() core::Entity *entity = (*it).second; + // load entity models if necessary + if (!entity->model() && entity->modelname().size()) { + entity->entity_model = core::Model::get(entity->modelname()); + + if (!entity->model()) + entity->entity_modelname.clear(); + } + + if (test_draw_distance(entity)) { gl::push(); gl::translate(entity->location()); @@ -448,8 +467,7 @@ void draw(math::Vector3f const &eye, math::Vector3f const &target, float seconds gl::enable(GL_COLOR_MATERIAL); // enable color tracking gl::enable(GL_LIGHTING); gl::disable(GL_BLEND); // disbable alpha blending for world polys - - draw_pass_default(); // draw entities without model + gl::disable(GL_RESCALE_NORMAL); glVertexPointer(3, GL_FLOAT, 0, core::VertexArray::vertex); glNormalPointer(GL_FLOAT, 0, core::VertexArray::vertex_normal); @@ -458,25 +476,32 @@ void draw(math::Vector3f const &eye, math::Vector3f const &target, float seconds glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); glEnableClientState(GL_COLOR_ARRAY); - + draw_pass_model_vertex(); // draw entities with model glDisableClientState(GL_COLOR_ARRAY); + gl::enable(GL_RESCALE_NORMAL); // rescale normals by the transformation matrix scale factor + + draw_pass_default(); // draw entities without model + + gl::disable(GL_RESCALE_NORMAL); draw_pass_model_evertex(); // draw entities with model, vertices with entity color - glDisableClientState(GL_VERTEX_ARRAY); - glDisableClientState(GL_NORMAL_ARRAY); - gl::disable(GL_LIGHTING); gl::enable(GL_BLEND); draw_pass_model_fx(); // draw entity lights and engines gl::enable(GL_LIGHTING); + gl::enable(GL_RESCALE_NORMAL); draw_pass_model_radius(); //draw entity radius + + glDisableClientState(GL_VERTEX_ARRAY); + glDisableClientState(GL_NORMAL_ARRAY); + gl::disable(GL_RESCALE_NORMAL); gl::disable(GL_LIGHTING); gl::disable(GL_COLOR_MATERIAL); // disable color tracking gl::disable(GL_CULL_FACE); // disable culling @@ -484,6 +509,8 @@ void draw(math::Vector3f const &eye, math::Vector3f const &target, float seconds draw_pass_spacegrid(); // draw the blue spacegrid gl::disable(GL_DEPTH_TEST); // disable depth buffer writing + + // GL_BLEND must be enabled for the GUI } } diff --git a/src/render/draw.h b/src/render/draw.h index f9f35f3..b423aad 100644 --- a/src/render/draw.h +++ b/src/render/draw.h @@ -20,7 +20,7 @@ public: static void clear(); static size_t tris; - static size_t spheres; + static size_t quads; }; } diff --git a/src/render/sphere.cc b/src/render/sphere.cc deleted file mode 100644 index d44c9e6..0000000 --- a/src/render/sphere.cc +++ /dev/null @@ -1,132 +0,0 @@ -/* - gl/sphere.cc - This file is part of the Osirion project and is distributed under - the terms of the GNU General Public License version 2 -*/ - -#include "render/sphere.h" -#include "render/render.h" -#include "math/mathlib.h" - -using math::Vector3f; -using math::Color; - -namespace render { - -const int segments = 33; - -Sphere::Sphere(float r) -{ - radius = r; - - // TODO make global sine-cosine lists - sintable = new float[segments]; - costable = new float[segments]; - float d = 2 * M_PI / (segments-1); - - for (int i=0; i < segments; i++) { - sintable[i] = sin( d * (float) i ); - costable[i] = cos ( d * (float) i ); - } -} - -Sphere::~Sphere() -{ - delete[] sintable; - delete[] costable; -} - -Sphere::Sphere(const Sphere &other) -{ - (*this) = other; -} - -Sphere& Sphere::operator=(const Sphere &other) -{ - sphere_color = other.sphere_color; - radius = other.radius; - return (*this); -} - -void Sphere::draw() -{ - using namespace gl; - - float r = radius*sintable[1]; - //float h = radius*costable[1]; - - gl::color(sphere_color); - - /* - // draw top - begin(Polygon); - normal(0, 1, 0); - for (int i = segments-1; i >= 0; i--) { - v = Vector3f(r*costable[i], h, r*sintable[i]); - n = v; - n.normalize(); - normal(n); - vertex(v); - } - end(); - - // draw bottom - begin(Polygon); - normal(0, -1, 0); - for (int i = 0; i< segments; i++) { - //for (int i = segments-1; i >= 0; i--) - v = Vector3f(r*costable[i], -h, r*sintable[i]); - n = v; - n.normalize(); - normal(n); - vertex(v); - } - end(); - */ - - Vector3f v; - Vector3f n; - - // draw body - for (int j=0; j < segments-1; j++) { - r = radius*sintable[j]; - float r1 = radius*sintable[j+1]; - // draw all vertexes - if (r_drawwireframe && r_drawwireframe->value()) { - gl::begin(gl::LineStrip); - } else { - gl::begin(gl::QuadStrip); - } - v = Vector3f(r, 0, radius*costable[j]); - n = v; - n.normalize(); - normal(n); - vertex(v); - - v = Vector3f(r1, 0, radius*costable[j+1]); - n = v; - n.normalize(); - normal(n); - vertex(v); - - for (int i = segments-1; i >= 0; i--) { - v = Vector3f(r*costable[i], r*sintable[i], radius*costable[j]); - n = v; - n.normalize(); - normal(n); - vertex(v); - - v = Vector3f(r1*costable[i], r1*sintable[i], radius*costable[j+1]); - n = v; - n.normalize(); - normal(n); - vertex(v); - } - end(); - - } -} - - -} - diff --git a/src/render/sphere.h b/src/render/sphere.h deleted file mode 100644 index 73a2169..0000000 --- a/src/render/sphere.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - gl/sphere.h - This file is part of the Osirion project and is distributed under - the terms of the GNU General Public License version 2 -*/ - -#ifndef __INCLUDED_GL_SPHERE_H__ -#define __INCLUDED_GL_SPHERE_H__ - -#include "render/gl.h" - -namespace render { - -/// a drawable OpenGL block shape -class Sphere -{ -public: - /// create a new sphere - Sphere(float r = 1.0f); - - /// copy constructor - Sphere(const Sphere &other); - - /// destructor - ~Sphere(); - - /// assignment operator - Sphere& operator=(const Sphere &other); - - /// radius of the sphere - float radius; - - /// draw the sphere - void draw(); - - /// color - math::Color sphere_color; - -private: - float *sintable; - float *costable; -}; - -} // namespace gl - -#endif // __INCLUDED_GL_SPHERE_H__ |