diff options
Diffstat (limited to 'src/render')
-rw-r--r-- | src/render/Makefile.am | 4 | ||||
-rw-r--r-- | src/render/box.cc | 102 | ||||
-rw-r--r-- | src/render/box.h | 47 | ||||
-rw-r--r-- | src/render/draw.cc | 119 | ||||
-rw-r--r-- | src/render/draw.h | 2 | ||||
-rw-r--r-- | src/render/render.h | 1 | ||||
-rw-r--r-- | src/render/sphere.cc | 77 | ||||
-rw-r--r-- | src/render/sphere.h | 11 |
8 files changed, 147 insertions, 216 deletions
diff --git a/src/render/Makefile.am b/src/render/Makefile.am index 4041e1e..d9a8301 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 = box.cc draw.cc gl.cc render.cc sphere.cc text.cc tga.cc -noinst_HEADERS = box.h draw.h gl.h render.h sphere.h text.h tga.h +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 diff --git a/src/render/box.cc b/src/render/box.cc deleted file mode 100644 index d6f14b5..0000000 --- a/src/render/box.cc +++ /dev/null @@ -1,102 +0,0 @@ -/* - render/box.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/box.h" - -namespace render { - -using math::Vector3f; -using math::Color; - -Box::Box(Vector3f const & tl, Vector3f const &br) : - topleft(tl), bottomright(br) -{ - topcolor = Color::White(); - bottomcolor= Color::White() * 0.7f; - radius = 1.0f; -} - -Box::Box(const Box & other) -{ - (*this) = other; -} - -Box& Box::operator=(const Box &other) -{ - bottomcolor = other.bottomcolor; - topcolor = other.topcolor; - - topleft = other.topleft; - bottomright = other.bottomright; - return (*this); -} - -void Box::draw() -{ - using namespace gl; - - Vector3f v0(topleft.x, bottomright.y, bottomright.z); - Vector3f v1(topleft.x, topleft.y, bottomright.z); - Vector3f v2(topleft.x, topleft.y, topleft.z); - Vector3f v3(topleft.x, bottomright.y, topleft.z); - - Vector3f v4(bottomright.x, bottomright.y, bottomright.z); - Vector3f v5(bottomright.x, topleft.y, bottomright.z); - Vector3f v6(bottomright.x, topleft.y, topleft.z); - Vector3f v7(bottomright.x, bottomright.y, topleft.z); - - begin(Quads); - - // top - color(topcolor); - vertex(radius*v2); - vertex(radius*v1); - vertex(radius*v5); - vertex(radius*v6); - - // sides - color(bottomcolor); - vertex(radius*v0); - color(topcolor); - vertex(radius*v1); - vertex(radius*v2); - color(bottomcolor); - vertex(radius*v3); - - vertex(radius*v3); - color(topcolor); - vertex(radius*v2); - vertex(radius*v6); - color(bottomcolor); - vertex(radius*v7); - - vertex(radius*v4); - color(topcolor); - vertex(radius*v5); - vertex(radius*v1); - color(bottomcolor); - vertex(radius*v0); - - vertex(radius*v7); - color(topcolor); - vertex(radius*v6); - vertex(radius*v5); - color(bottomcolor); - vertex(radius*v4); - - // bottom - color(bottomcolor); - vertex(radius*v4); - vertex(radius*v0); - vertex(radius*v3); - vertex(radius*v7); - - end(); - -} - -} - diff --git a/src/render/box.h b/src/render/box.h deleted file mode 100644 index aa211e1..0000000 --- a/src/render/box.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - render/box.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_RENDER_BOX_H__ -#define __INCLUDED_RENDER_BOX_H__ - -#include "render/render.h" -#include "math/mathlib.h" - -namespace render { - -/// a drawable OpenGL block shape -class Box -{ -public: - /// create a new standard cube with edge length 1 - Box(math::Vector3f const & tl, math::Vector3f const &br); - /// copy constructor - Box(const Box &other); - - /// assignment operator - Box& operator=(const Box &other); - - /// top left vertex (1,1,1) - math::Vector3f topleft; - /// bottom right vertex (-1,-1,-1) - math::Vector3f bottomright; - - /// draw the block - void draw(); - - /// Top color - math::Color topcolor; - /// bottom color - math::Color bottomcolor; - - /// size factor - float radius; -}; - -} - -#endif // __INCLUDED_RENDER_BOX_H__ - diff --git a/src/render/draw.cc b/src/render/draw.cc index 2dbdc6f..3fed4dd 100644 --- a/src/render/draw.cc +++ b/src/render/draw.cc @@ -6,28 +6,25 @@ #include "core/core.h" #include "core/model.h" -#include "render/box.h" #include "render/draw.h" -#include "render/render.h" #include "render/sphere.h" namespace render { -render::Sphere sphere(math::Vector3f(0,0,0),1); -render::Box cube(math::Vector3f(0.5f, 0.5f, 0.5f), math::Vector3f(-0.5f, -0.5f, -0.5f)); +render::Sphere sphere(1); -math::Vector3f v0(1.0f, -1.0f, -1.0f); -math::Vector3f v1(1.0f, 1.0f, -1.0f); -math::Vector3f v2(1.0f, 1.0f, 1.0f); -math::Vector3f v3(1.0f, -1.0f, 1.0f); +math::Vector3f v0(1, -1, 1); +math::Vector3f v1(1, 1, 1); +math::Vector3f v2(-1, 1, 1); +math::Vector3f v3(-1, -1, 1); -math::Vector3f v4(-1.0f, -1.0f, -1.0f); -math::Vector3f v5(-1.0f, 1.0f, -1.0f); -math::Vector3f v6(-1.0f, 1.0f, 1.0f); -math::Vector3f v7(-1.0f, -1.0f, 1.0f); -float angle = 0; +math::Vector3f v4(1, -1, -1); +math::Vector3f v5(1, 1, -1); +math::Vector3f v6(-1, 1, -1); +math::Vector3f v7(-1, -1, -1); +float angle = 0; void draw_model(core::Model *model, core::Entity *entity) { @@ -41,6 +38,7 @@ void draw_model(core::Model *model, core::Entity *entity) // draw all vertexes gl::begin(gl::Polygon); + //gl::begin(gl::LineLoop); gl::normal((*fit)->normal()); for (std::vector<math::Vector3f *>::iterator vit = (*fit)->face_vertex.begin(); vit != (*fit)->face_vertex.end(); vit++) { gl::vertex(*(*vit)); @@ -67,17 +65,59 @@ void draw_model_engines(core::Model *model, core::EntityControlable *entity) void draw_entity_sphere(core::Entity *entity) { - render::gl::color(entity->color()); + sphere.sphere_color = entity->color(); sphere.radius = entity->radius(); sphere.draw(); } void draw_entity_cube(core::Entity *entity) { - cube.topcolor = entity->color(); - cube.bottomcolor = entity->color(); - cube.radius = entity->radius(); - cube.draw(); + float radius = entity->radius()/2; + gl::scale(radius, radius, radius); + + gl::color(entity->color()); + gl::begin(gl::Quads); + + // top + gl::normal(0,0,1); + gl::vertex(v0); + gl::vertex(v1); + gl::vertex(v2); + gl::vertex(v3); + + // bottom + gl::normal(0,0, -1); + gl::vertex(v7); + gl::vertex(v6); + gl::vertex(v5); + gl::vertex(v4); + + // sides + gl::normal(1,0,0); + gl::vertex(v1); + gl::vertex(v0); + gl::vertex(v4); + gl::vertex(v5); + + gl::normal(-1,0,0); + gl::vertex(v3); + gl::vertex(v2); + gl::vertex(v6); + gl::vertex(v7); + + gl::normal(0,1,0); + gl::vertex(v2); + gl::vertex(v1); + gl::vertex(v5); + gl::vertex(v6); + + gl::normal(0,-1,0); + gl::vertex(v0); + gl::vertex(v3); + gl::vertex(v7); + gl::vertex(v4); + + gl::end(); } @@ -116,15 +156,17 @@ void draw_entity_default(core::Entity *entity) if (model) { draw_model(model, entity); } else { - gl::disable(GL_LIGHTING); - gl::disable(GL_LIGHT0); + //gl::disable(GL_LIGHTING); + //gl::disable(GL_LIGHT0); switch(entity->shape()) { case core::Entity::Sphere: draw_entity_sphere(entity); break; - + case core::Entity::Diamond: + + case core::Entity::Axis: draw_entity_axis(entity); break; @@ -135,8 +177,8 @@ void draw_entity_default(core::Entity *entity) break; } - gl::enable(GL_LIGHTING); - gl::enable(GL_LIGHT0); // disable camera light + //gl::enable(GL_LIGHTING); + //gl::enable(GL_LIGHT0); // disable camera light } gl::pop(); @@ -166,24 +208,24 @@ void draw_entity_controlable(core::EntityControlable *entity) gl::color(math::Color(0.0f, 1.0f ,0.0f , 0.5f)); gl::begin(gl::LineLoop); - gl::normal(0, -0.5, -0.5); - gl::vertex(v0); - gl::normal(0, 0.5, -0.5); - gl::vertex(v1); gl::normal(0, 0.5, 0.5); - gl::vertex(v2); + gl::vertex(v1); gl::normal(0, -0.5, 0.5); - gl::vertex(v3); - gl::end(); - - gl::begin(gl::LineLoop); + gl::vertex(v0); gl::normal(0, -0.5, -0.5); gl::vertex(v4); gl::normal(0, 0.5, -0.5); - gl::vertex(v5); + gl::vertex(v5); + gl::end(); + + gl::begin(gl::LineLoop); + gl::normal(0, -0.5, 0.5); + gl::vertex(v3); gl::normal(0, 0.5, 0.5); + gl::vertex(v2); + gl::normal(0, 0.5, -0.5); gl::vertex(v6); - gl::normal(0, -0.5, 0.5); + gl::normal(0, -0.5, -0.5); gl::vertex(v7); gl::end(); @@ -239,8 +281,10 @@ void draw(math::Vector3f const &target, float seconds) gl::enable(GL_CULL_FACE); // enable culling gl::enable(GL_COLOR_MATERIAL); // enable color tracking gl::enable(GL_LIGHTING); - gl::enable(GL_LIGHT0); // enable camera light - + gl::enable(GL_LIGHT0); + + gl::disable(GL_BLEND); // disbable alpha blending for world polys + std::map<unsigned int, core::Entity *>::iterator it; for (it=core::Entity::registry.begin(); it != core::Entity::registry.end(); it++) { switch ((*it).second->type()) { @@ -259,6 +303,9 @@ void draw(math::Vector3f const &target, float seconds) gl::disable(GL_LIGHTING); gl::disable(GL_COLOR_MATERIAL); // disable color tracking gl::disable(GL_CULL_FACE); // disable culling + + gl::enable(GL_BLEND); // enable alpha blending again + draw_spacegrid(target); // draw the blue spacegrid gl::disable(GL_DEPTH_TEST); // disable depth buffer writing diff --git a/src/render/draw.h b/src/render/draw.h index f27818b..c1273aa 100644 --- a/src/render/draw.h +++ b/src/render/draw.h @@ -7,6 +7,8 @@ #ifndef __INCLUDED_RENDER_DRAW_H__ #define __INCLUDED_RENDER_DRAW_H__ +#include "math/vector3f.h" + namespace render { diff --git a/src/render/render.h b/src/render/render.h index 306d340..c27b740 100644 --- a/src/render/render.h +++ b/src/render/render.h @@ -23,6 +23,7 @@ namespace render { extern GLuint textures[32]; } +#include "render/draw.h" #include "render/gl.h" #include "render/text.h" #include "render/tga.h" diff --git a/src/render/sphere.cc b/src/render/sphere.cc index 1715263..616424e 100644 --- a/src/render/sphere.cc +++ b/src/render/sphere.cc @@ -14,15 +14,14 @@ namespace render { const int segments = 33; -Sphere::Sphere(Vector3f p , float r) +Sphere::Sphere(float r) { - position = p; radius = r; // TODO make global sine-cosine lists sintable = new float[segments]; costable = new float[segments]; - float d = 2 * M_PI / segments; + float d = 2 * M_PI / (segments-1); for (int i=0; i < segments; i++) { sintable[i] = sin( d * (float) i ); @@ -43,7 +42,7 @@ Sphere::Sphere(const Sphere &other) Sphere& Sphere::operator=(const Sphere &other) { - position = other.position; + sphere_color = other.sphere_color; radius = other.radius; return (*this); } @@ -52,36 +51,72 @@ void Sphere::draw() { using namespace gl; - // draw top - // TODO upside-down float r = radius*sintable[1]; - float h = radius*costable[1]; + //float h = radius*costable[1]; + + gl::color(sphere_color); - begin(LineLoop); - //begin(Polygon); - for (int i = segments-1; i >= 0; i--) - vertex(r*costable[i], h, r*sintable[i]); + /* + // 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 - // TODO upside-down - begin(LineLoop); - for (int i = 0; i< segments; i++) - vertex(r*costable[i], -h, r*sintable[i]); + 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=1; j < segments-1; j++) { + for (int j=0; j < segments-1; j++) { r = radius*sintable[j]; float r1 = radius*sintable[j+1]; begin(QuadStrip); - vertex(r1, radius*costable[j+1], 0); - vertex(r, radius*costable[j], 0); + v = Vector3f(r, radius*costable[j], 0); + n = v; + n.normalize(); + normal(n); + vertex(v); + + v = Vector3f(r1, radius*costable[j+1], 0); + n = v; + n.normalize(); + normal(n); + vertex(v); + + for (int i = segments-1; i >= 0; i--) { + v = Vector3f(r*costable[i], radius*costable[j], r*sintable[i]); + n = v; + n.normalize(); + normal(n); + vertex(v); + + v = Vector3f(r1*costable[i], radius*costable[j+1], r1*sintable[i]); + n = v; + n.normalize(); + normal(n); + vertex(v); - for (int i = segments-1; i >= 0; i--) { - vertex(r1*costable[i], radius*costable[j+1], r1*sintable[i]); - vertex(r*costable[i], radius*costable[j], r*sintable[i]); //vertex(r*costable[i-1], radius*costable[j], r*sintable[i-1]); //vertex(r1*costable[i-1], radius*costable[j+1], r1*sintable[i-1]); } diff --git a/src/render/sphere.h b/src/render/sphere.h index b3ac826..73a2169 100644 --- a/src/render/sphere.h +++ b/src/render/sphere.h @@ -16,7 +16,7 @@ class Sphere { public: /// create a new sphere - Sphere(math::Vector3f p = math::Vector3f(), float r = 1.0f); + Sphere(float r = 1.0f); /// copy constructor Sphere(const Sphere &other); @@ -30,16 +30,11 @@ public: /// radius of the sphere float radius; - /// position of the sphere - math::Vector3f position; - /// draw the sphere void draw(); - /// Top color - math::Color topcolor; - /// bottom color - math::Color bottomcolor; + /// color + math::Color sphere_color; private: float *sintable; |