Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-03-06 22:59:40 +0000
committerStijn Buys <ingar@osirion.org>2008-03-06 22:59:40 +0000
commitdf61a28d708c30e3e77d1f739dfb4561c042c89c (patch)
treed280b5eef345ea80f78f9d41df3c2367c9a88cd5 /src/render
parent6ade6c1c346743b8432600485e28682e276cfbd0 (diff)
moved render::Model to core::Model
Diffstat (limited to 'src/render')
-rw-r--r--src/render/Makefile.am5
-rw-r--r--src/render/box.cc3
-rw-r--r--src/render/box.h8
-rw-r--r--src/render/draw.cc257
-rw-r--r--src/render/draw.h14
-rw-r--r--src/render/render.cc13
-rw-r--r--src/render/render.h3
7 files changed, 138 insertions, 165 deletions
diff --git a/src/render/Makefile.am b/src/render/Makefile.am
index 656ae26..4041e1e 100644
--- a/src/render/Makefile.am
+++ b/src/render/Makefile.am
@@ -3,6 +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 face.cc gl.cc model.cc render.cc sphere.cc \
- text.cc tga.cc
-noinst_HEADERS = box.h face.h gl.h model.h render.h sphere.h text.h tga.h
+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
diff --git a/src/render/box.cc b/src/render/box.cc
index 79f62f7..d6f14b5 100644
--- a/src/render/box.cc
+++ b/src/render/box.cc
@@ -1,10 +1,9 @@
/*
- gl/box.cc
+ 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
*/
-// project headers
#include "render/box.h"
namespace render {
diff --git a/src/render/box.h b/src/render/box.h
index ceab8ec..aa211e1 100644
--- a/src/render/box.h
+++ b/src/render/box.h
@@ -1,11 +1,11 @@
/*
- gl/box.h
+ 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_GL_BOX_H__
-#define __INCLUDED_GL_BOX_H__
+#ifndef __INCLUDED_RENDER_BOX_H__
+#define __INCLUDED_RENDER_BOX_H__
#include "render/render.h"
#include "math/mathlib.h"
@@ -43,5 +43,5 @@ public:
}
-#endif // __INCLUDED_GL_BOX_H__
+#endif // __INCLUDED_RENDER_BOX_H__
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
}
diff --git a/src/render/draw.h b/src/render/draw.h
index b6b7b31..f27818b 100644
--- a/src/render/draw.h
+++ b/src/render/draw.h
@@ -1,13 +1,19 @@
/*
- draw.cc
+ render/draw.h
This file is part of the Osirion project and is distributed under
- the terms and conditions of the GNU General Public License version 2
+ the terms of the GNU General Public License version 2
*/
-namespace client
+#ifndef __INCLUDED_RENDER_DRAW_H__
+#define __INCLUDED_RENDER_DRAW_H__
+
+namespace render
{
/// draw the world
-void draw_world(float elapsed);
+void draw(math::Vector3f const &target, float seconds);
}
+
+#endif // __INCLUDED_RENDER_DRAW_H__
+
diff --git a/src/render/render.cc b/src/render/render.cc
index a1a66f9..c6183c0 100644
--- a/src/render/render.cc
+++ b/src/render/render.cc
@@ -6,7 +6,6 @@
// project headers
#include "render/render.h"
-#include "render/model.h"
#include "core/core.h"
#include "sys/sys.h"
@@ -14,12 +13,6 @@ namespace render {
GLuint textures[32];
-void func_list_model(std::string const &args)
-{
- Model::list();
-}
-
-
void init()
{
con_print << "Initializing renderer..." << std::endl;
@@ -39,16 +32,12 @@ void init()
core::application()->shutdown();
}
- Model::clear();
- core::Func::add("list_model", (core::FuncPtr) func_list_model);
+
}
void shutdown()
{
con_print << "Shutting down renderer..." << std::endl;
-
- Model::clear();
- core::Func::remove("list_model");
}
}
diff --git a/src/render/render.h b/src/render/render.h
index 4faa7d5..306d340 100644
--- a/src/render/render.h
+++ b/src/render/render.h
@@ -17,6 +17,9 @@ namespace render {
/// shutdown the render subsystem
void shutdown();
+ /// draw the game world
+ void draw(float elapsed);
+
extern GLuint textures[32];
}