Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/render/draw.cc')
-rw-r--r--src/render/draw.cc257
1 files changed, 117 insertions, 140 deletions
diff --git a/src/render/draw.cc b/src/render/draw.cc
index 77e3e92..299e59e 100644
--- a/src/render/draw.cc
+++ b/src/render/draw.cc
@@ -1,24 +1,70 @@
/*
- client/draw.cc
+ render/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 "core/model.h"
+#include "render/box.h"
+#include "render/draw.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
+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));
+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_model(core::Model *model, core::Entity *entity)
+{
+ // draw all faces
+ for (std::list<core::Face *>::iterator fit = model->model_face.begin(); fit != model->model_face.end(); fit++) {
+ if ((*fit)->color()) {
+ render::gl::color(*(*fit)->color());
+ } else {
+ render::gl::color(entity->color());
+ }
+
+ // draw all vertexes
+ gl::begin(gl::Polygon);
+ gl::normal((*fit)->normal());
+ for (std::vector<math::Vector3f *>::iterator vit = (*fit)->face_vertex.begin(); vit != (*fit)->face_vertex.end(); vit++) {
+ gl::vertex(*(*vit));
+ }
+ gl::end();
+ }
+}
+
+void draw_model_engines(core::Model *model, core::EntityControlable *entity)
+{
+ if (model->model_engine.size() && entity->thrust()) {
+ gl::color(1.0f,0 ,0);
+ gl::begin(gl::Lines);
+
+ for (std::list<core::Engine *>::iterator eit = model->model_engine.begin(); eit != model->model_engine.end(); eit++) {
+ math::Vector3f const & v = (*eit)->location();
+ gl::vertex(v);
+ gl::vertex(v.x - 0.0625f*entity->thrust(), v.y, v.z);
+ }
+ gl::end();
+ }
+
+}
+
void draw_entity_sphere(core::Entity *entity)
{
render::gl::color(entity->color());
@@ -35,7 +81,7 @@ void draw_entity_cube(core::Entity *entity)
}
-void draw_entity_diamond(core::Entity *entity)
+void draw_entity_axis(core::Entity *entity)
{
using namespace render;
float r = entity->radius();
@@ -54,103 +100,21 @@ void draw_entity_diamond(core::Entity *entity)
}
-
-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;
+ core::Model *model = 0;
if (entity->modelname().size())
- model = Model::get(entity->modelname());
+ model = core::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);
+ draw_model(model, entity);
} else {
gl::disable(GL_LIGHTING);
gl::disable(GL_LIGHT0);
@@ -161,7 +125,7 @@ void draw_entity_default(core::Entity *entity)
break;
case core::Entity::Diamond:
- draw_entity_diamond(entity);
+ draw_entity_axis(entity);
break;
case core::Entity::Cube:
@@ -174,68 +138,85 @@ void draw_entity_default(core::Entity *entity)
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;
+ core::Model *model = 0;
if (entity->modelname().size())
- model = render::Model::get(entity->modelname());
+ model = core::Model::get(entity->modelname());
- render::gl::push();
- render::gl::translate(entity->location());
- render::gl::rotate(entity->direction(), 0.0f, 0.0f, 1.0f );
+ gl::push();
+ gl::translate(entity->location());
+ gl::rotate(entity->direction(), 0.0f, 0.0f, 1.0f );
if (model) {
- model->draw(entity, camera::eye);
- } else {
- draw_ship(entity);
+ draw_model(model, entity);
+ draw_model_engines(model, entity);
}
- render::gl::pop();
+ // shield rotation
+ gl::rotate(angle, 0.0f, 0.0f, 1.0f );
+ gl::scale(0.2f, 0.2f, 0.2f);
+
+ // draw the shield
+ gl::color(math::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();
-void draw_spacegrid()
-{
- using namespace render::gl;
+ gl::pop();
+}
- translate(camera::target);
+void draw_spacegrid(math::Vector3f const &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);
+ float dx = target.x - floorf(target.x);
+ float dy = target.y - floorf(target.y);
- color(0,0, 1.0f);
- normal(0, 0, 1.0f);
+ gl::translate(target);
+ gl::color(0,0, 1.0f);
+ gl::normal(0, 0, 1.0f);
- begin(Lines);
+ gl::begin(gl::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);
+ gl::color(0,0, 0, 0);
+ gl::vertex(i-dx, -gridsize-dy, z);
+ gl::color(0,0, (gridsize-abs(i))*s, (gridsize-abs(i))*s);
+ gl::vertex(i-dx, -dy, z );
+ gl::vertex(i-dx, -dy ,z );
+ gl::color(0,0, 0, 0);
+ gl::vertex(i-dx, gridsize-dy, z);
+
+ gl::vertex(-gridsize-dx, i-dy, z );
+ gl::color(0,0, (gridsize-abs(i))*s, (gridsize-abs(i))*s);
+ gl::vertex(-dx, i-dy, z);
+ gl::vertex(-dx, i-dy, z);
+ gl::color(0,0, 0, 0);
+ gl::vertex(gridsize-dx, i-dy, z);
}
- end();
+ gl::end();
}
-void draw_world(float seconds)
+void draw(math::Vector3f const &target, float seconds)
{
// used for animations
angle += 180.0f * seconds;
@@ -245,14 +226,13 @@ void draw_world(float seconds)
// 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<unsigned int, core::Entity *>::iterator it;
for (it=core::Entity::registry.begin(); it != core::Entity::registry.end(); it++) {
switch ((*it).second->type()) {
@@ -267,14 +247,11 @@ void draw_world(float seconds)
}
}
- 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_LIGHTING);
+ gl::disable(GL_COLOR_MATERIAL); // disable color tracking
+ gl::disable(GL_CULL_FACE); // disable culling
+ draw_spacegrid(target); // draw the blue spacegrid
gl::disable(GL_DEPTH_TEST); // disable depth buffer writing
}