From 0af232b6f1b17271338a278783b4270a83e8897f Mon Sep 17 00:00:00 2001 From: Stijn Buys Date: Thu, 6 Mar 2008 21:53:29 +0000 Subject: moved draw routines to render namespace --- src/client/draw.cc | 282 ----------------------------------------------------- src/client/draw.h | 13 --- src/render/draw.cc | 282 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/render/draw.h | 13 +++ 4 files changed, 295 insertions(+), 295 deletions(-) delete mode 100644 src/client/draw.cc delete mode 100644 src/client/draw.h create mode 100644 src/render/draw.cc create mode 100644 src/render/draw.h (limited to 'src') diff --git a/src/client/draw.cc b/src/client/draw.cc deleted file mode 100644 index 77e3e92..0000000 --- a/src/client/draw.cc +++ /dev/null @@ -1,282 +0,0 @@ -/* - client/draw.cc - This file is part of the Osirion project and is distributed under - the terms and conditions of the GNU General Public License version 2 -*/ - -#include "core/core.h" -#include "render/render.h" -#include "render/sphere.h" -#include "render/box.h" -#include "render/model.h" -#include "client/client.h" -#include "client/camera.h" -#include "client/draw.h" - -namespace client -{ - -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)); - -void draw_entity_sphere(core::Entity *entity) -{ - render::gl::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(); -} - - -void draw_entity_diamond(core::Entity *entity) -{ - using namespace render; - float r = entity->radius(); - gl::begin(gl::Lines); - gl::color(1.0f, 0.0f, 0.0f); - gl::vertex(r,0.0f,0.0f); - gl::color(entity->color()); - gl::vertex(-r,0.0f,0.0f); - - gl::vertex(0.0f,r/2,0.0f); - gl::vertex(0.0f,-r/2,0.0f); - - gl::vertex(0.0f,0.0f,r); - gl::vertex(0.0f,0.0f,-r); - gl::end(); -} - - - -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 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; - -void draw_ship(core::EntityControlable *entity) -{ - using math::Vector3f; - using math::Color; - using namespace render; - - gl::scale(0.2f, 0.2f, 0.2f); - - Vector3f tl(0.25, 0.125, 0.125); - Vector3f br(-0.25, -0.125, -0.125); - - Box box(tl, br); - box.topcolor = entity->color(); - box.bottomcolor = entity->color() * 0.7; - box.draw(); - - tl = Vector3f(0, 0.07, 0.25); - br = Vector3f(-0.5, -0.07, 0.125); - Box engine1(tl, br); - engine1.topcolor = Color(0.7, 0.7, 0.7); - engine1.bottomcolor = engine1.topcolor * 0.5; - engine1.draw(); - - tl = Vector3f(0, 0.07, -0.125); - br = Vector3f(-0.5, -0.07, -0.25); - Box engine2(tl, br); - engine2.topcolor = engine1.topcolor; - engine2.bottomcolor = engine1.bottomcolor; - engine2.draw(); - - tl = Vector3f(0.4, 0.07, 0.07); - br = Vector3f(0.25, -0.07, -0.07); - Box cockpit(tl, br); - cockpit.topcolor = engine1.topcolor; - cockpit.bottomcolor = engine1.bottomcolor; - cockpit.draw(); - - if(entity->thrust() > 0 ) { - gl::color(1.0f,0 ,0 ); - gl::begin(gl::Lines); - gl::vertex(-0.5f, 0, 0.185); - gl::vertex(-0.5f-0.25f*entity->thrust(), 0, 0.185); - - gl::vertex(-0.5f, 0, -0.185f); - gl::vertex(-0.5f-0.25f*entity->thrust(), 0, -0.185f); - gl::end(); - } - - // shield rotation - gl::rotate(angle, 0.0f, 0.0f, 1.0f ); - - // draw the shield - gl::color(Color(0.0f, 1.0f ,0.0f , 0.5f)); - - gl::begin(gl::LineLoop); - gl::vertex(v0); - gl::vertex(v1); - gl::vertex(v2); - gl::vertex(v3); - gl::end(); - - gl::begin(gl::LineLoop); - gl::vertex(v4); - gl::vertex(v5); - gl::vertex(v6); - gl::vertex(v7); - gl::end(); -} - - -// draw an entity of entity_type core::Entity::Default -void draw_entity_default(core::Entity *entity) -{ - using namespace render; - - Model *model = 0; - if (entity->modelname().size()) - model = Model::get(entity->modelname()); - - gl::push(); - gl::translate(entity->location()); - gl::rotate(entity->direction(), 0.0f, 0.0f, 1.0f ); - - if (model) { - model->draw(entity); - } else { - gl::disable(GL_LIGHTING); - gl::disable(GL_LIGHT0); - - switch(entity->shape()) { - case core::Entity::Sphere: - draw_entity_sphere(entity); - break; - - case core::Entity::Diamond: - draw_entity_diamond(entity); - break; - - case core::Entity::Cube: - - default: - draw_entity_cube(entity); - break; - } - - gl::enable(GL_LIGHTING); - gl::enable(GL_LIGHT0); // disable camera light - } - - gl::pop(); -} - -// draw an entity of entity_type core::Entity::Controlable -void draw_entity_controlable(core::EntityControlable *entity) -{ - render::Model *model = 0; - if (entity->modelname().size()) - model = render::Model::get(entity->modelname()); - - render::gl::push(); - render::gl::translate(entity->location()); - render::gl::rotate(entity->direction(), 0.0f, 0.0f, 1.0f ); - - if (model) { - model->draw(entity, camera::eye); - } else { - draw_ship(entity); - } - - render::gl::pop(); - -} - -void draw_spacegrid() -{ - using namespace render::gl; - - translate(camera::target); - - int gridsize = 32; - float s = 1.0f / gridsize; - float z = -4.0f; - - float dx = camera::target.x - floorf(camera::target.x); - float dy = camera::target.y - floorf(camera::target.y); - - color(0,0, 1.0f); - normal(0, 0, 1.0f); - - begin(Lines); - for (int i=-gridsize; i <= gridsize; i++) { - color(0,0, 0, 0); - vertex(i-dx, -gridsize-dy, z); - color(0,0, (gridsize-abs(i))*s, (gridsize-abs(i))*s); - vertex(i-dx, -dy, z ); - vertex(i-dx, -dy ,z ); - color(0,0, 0, 0); - vertex(i-dx, gridsize-dy, z); - - vertex(-gridsize-dx, i-dy, z ); - color(0,0, (gridsize-abs(i))*s, (gridsize-abs(i))*s); - vertex(-dx, i-dy, z); - vertex(-dx, i-dy, z); - color(0,0, 0, 0); - vertex(gridsize-dx, i-dy, z); - } - end(); -} - -void draw_world(float seconds) -{ - // used for animations - angle += 180.0f * seconds; - if( angle > 360.0f ) { - angle -= 360.0f; - } - - // draw entities - using namespace render; - - gl::enable(GL_DEPTH_TEST); // enable depth buffer writing - 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_NORMALIZE); - - std::map::iterator it; - for (it=core::Entity::registry.begin(); it != core::Entity::registry.end(); it++) { - switch ((*it).second->type()) { - case core::Entity::Default: - draw_entity_default((*it).second); - break; - case core::Entity::Controlable: - draw_entity_controlable(static_cast ((*it).second)); - break; - default: - break; - } - } - - gl::disable(GL_CULL_FACE); // disable culling - gl::disable(GL_COLOR_MATERIAL); // disable color tracking - gl::disable(GL_LIGHTING); - gl::disable(GL_LIGHT0); // disable camera light - //gl::disable(GL_NORMALIZE); - - // draw the background grid - draw_spacegrid(); - - gl::disable(GL_DEPTH_TEST); // disable depth buffer writing -} - -} diff --git a/src/client/draw.h b/src/client/draw.h deleted file mode 100644 index b6b7b31..0000000 --- a/src/client/draw.h +++ /dev/null @@ -1,13 +0,0 @@ -/* - draw.cc - This file is part of the Osirion project and is distributed under - the terms and conditions of the GNU General Public License version 2 -*/ - -namespace client -{ - -/// draw the world -void draw_world(float elapsed); - -} diff --git a/src/render/draw.cc b/src/render/draw.cc new file mode 100644 index 0000000..77e3e92 --- /dev/null +++ b/src/render/draw.cc @@ -0,0 +1,282 @@ +/* + client/draw.cc + This file is part of the Osirion project and is distributed under + the terms and conditions of the GNU General Public License version 2 +*/ + +#include "core/core.h" +#include "render/render.h" +#include "render/sphere.h" +#include "render/box.h" +#include "render/model.h" +#include "client/client.h" +#include "client/camera.h" +#include "client/draw.h" + +namespace client +{ + +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)); + +void draw_entity_sphere(core::Entity *entity) +{ + render::gl::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(); +} + + +void draw_entity_diamond(core::Entity *entity) +{ + using namespace render; + float r = entity->radius(); + gl::begin(gl::Lines); + gl::color(1.0f, 0.0f, 0.0f); + gl::vertex(r,0.0f,0.0f); + gl::color(entity->color()); + gl::vertex(-r,0.0f,0.0f); + + gl::vertex(0.0f,r/2,0.0f); + gl::vertex(0.0f,-r/2,0.0f); + + gl::vertex(0.0f,0.0f,r); + gl::vertex(0.0f,0.0f,-r); + gl::end(); +} + + + +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 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; + +void draw_ship(core::EntityControlable *entity) +{ + using math::Vector3f; + using math::Color; + using namespace render; + + gl::scale(0.2f, 0.2f, 0.2f); + + Vector3f tl(0.25, 0.125, 0.125); + Vector3f br(-0.25, -0.125, -0.125); + + Box box(tl, br); + box.topcolor = entity->color(); + box.bottomcolor = entity->color() * 0.7; + box.draw(); + + tl = Vector3f(0, 0.07, 0.25); + br = Vector3f(-0.5, -0.07, 0.125); + Box engine1(tl, br); + engine1.topcolor = Color(0.7, 0.7, 0.7); + engine1.bottomcolor = engine1.topcolor * 0.5; + engine1.draw(); + + tl = Vector3f(0, 0.07, -0.125); + br = Vector3f(-0.5, -0.07, -0.25); + Box engine2(tl, br); + engine2.topcolor = engine1.topcolor; + engine2.bottomcolor = engine1.bottomcolor; + engine2.draw(); + + tl = Vector3f(0.4, 0.07, 0.07); + br = Vector3f(0.25, -0.07, -0.07); + Box cockpit(tl, br); + cockpit.topcolor = engine1.topcolor; + cockpit.bottomcolor = engine1.bottomcolor; + cockpit.draw(); + + if(entity->thrust() > 0 ) { + gl::color(1.0f,0 ,0 ); + gl::begin(gl::Lines); + gl::vertex(-0.5f, 0, 0.185); + gl::vertex(-0.5f-0.25f*entity->thrust(), 0, 0.185); + + gl::vertex(-0.5f, 0, -0.185f); + gl::vertex(-0.5f-0.25f*entity->thrust(), 0, -0.185f); + gl::end(); + } + + // shield rotation + gl::rotate(angle, 0.0f, 0.0f, 1.0f ); + + // draw the shield + gl::color(Color(0.0f, 1.0f ,0.0f , 0.5f)); + + gl::begin(gl::LineLoop); + gl::vertex(v0); + gl::vertex(v1); + gl::vertex(v2); + gl::vertex(v3); + gl::end(); + + gl::begin(gl::LineLoop); + gl::vertex(v4); + gl::vertex(v5); + gl::vertex(v6); + gl::vertex(v7); + gl::end(); +} + + +// draw an entity of entity_type core::Entity::Default +void draw_entity_default(core::Entity *entity) +{ + using namespace render; + + Model *model = 0; + if (entity->modelname().size()) + model = Model::get(entity->modelname()); + + gl::push(); + gl::translate(entity->location()); + gl::rotate(entity->direction(), 0.0f, 0.0f, 1.0f ); + + if (model) { + model->draw(entity); + } else { + gl::disable(GL_LIGHTING); + gl::disable(GL_LIGHT0); + + switch(entity->shape()) { + case core::Entity::Sphere: + draw_entity_sphere(entity); + break; + + case core::Entity::Diamond: + draw_entity_diamond(entity); + break; + + case core::Entity::Cube: + + default: + draw_entity_cube(entity); + break; + } + + gl::enable(GL_LIGHTING); + gl::enable(GL_LIGHT0); // disable camera light + } + + gl::pop(); +} + +// draw an entity of entity_type core::Entity::Controlable +void draw_entity_controlable(core::EntityControlable *entity) +{ + render::Model *model = 0; + if (entity->modelname().size()) + model = render::Model::get(entity->modelname()); + + render::gl::push(); + render::gl::translate(entity->location()); + render::gl::rotate(entity->direction(), 0.0f, 0.0f, 1.0f ); + + if (model) { + model->draw(entity, camera::eye); + } else { + draw_ship(entity); + } + + render::gl::pop(); + +} + +void draw_spacegrid() +{ + using namespace render::gl; + + translate(camera::target); + + int gridsize = 32; + float s = 1.0f / gridsize; + float z = -4.0f; + + float dx = camera::target.x - floorf(camera::target.x); + float dy = camera::target.y - floorf(camera::target.y); + + color(0,0, 1.0f); + normal(0, 0, 1.0f); + + begin(Lines); + for (int i=-gridsize; i <= gridsize; i++) { + color(0,0, 0, 0); + vertex(i-dx, -gridsize-dy, z); + color(0,0, (gridsize-abs(i))*s, (gridsize-abs(i))*s); + vertex(i-dx, -dy, z ); + vertex(i-dx, -dy ,z ); + color(0,0, 0, 0); + vertex(i-dx, gridsize-dy, z); + + vertex(-gridsize-dx, i-dy, z ); + color(0,0, (gridsize-abs(i))*s, (gridsize-abs(i))*s); + vertex(-dx, i-dy, z); + vertex(-dx, i-dy, z); + color(0,0, 0, 0); + vertex(gridsize-dx, i-dy, z); + } + end(); +} + +void draw_world(float seconds) +{ + // used for animations + angle += 180.0f * seconds; + if( angle > 360.0f ) { + angle -= 360.0f; + } + + // draw entities + using namespace render; + + gl::enable(GL_DEPTH_TEST); // enable depth buffer writing + 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_NORMALIZE); + + std::map::iterator it; + for (it=core::Entity::registry.begin(); it != core::Entity::registry.end(); it++) { + switch ((*it).second->type()) { + case core::Entity::Default: + draw_entity_default((*it).second); + break; + case core::Entity::Controlable: + draw_entity_controlable(static_cast ((*it).second)); + break; + default: + break; + } + } + + gl::disable(GL_CULL_FACE); // disable culling + gl::disable(GL_COLOR_MATERIAL); // disable color tracking + gl::disable(GL_LIGHTING); + gl::disable(GL_LIGHT0); // disable camera light + //gl::disable(GL_NORMALIZE); + + // draw the background grid + draw_spacegrid(); + + gl::disable(GL_DEPTH_TEST); // disable depth buffer writing +} + +} diff --git a/src/render/draw.h b/src/render/draw.h new file mode 100644 index 0000000..b6b7b31 --- /dev/null +++ b/src/render/draw.h @@ -0,0 +1,13 @@ +/* + draw.cc + This file is part of the Osirion project and is distributed under + the terms and conditions of the GNU General Public License version 2 +*/ + +namespace client +{ + +/// draw the world +void draw_world(float elapsed); + +} -- cgit v1.2.3