Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src
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
parent6ade6c1c346743b8432600485e28682e276cfbd0 (diff)
moved render::Model to core::Model
Diffstat (limited to 'src')
-rw-r--r--src/client/Makefile.am8
-rw-r--r--src/client/view.cc6
-rw-r--r--src/core/Makefile.am4
-rw-r--r--src/core/face.cc53
-rw-r--r--src/core/face.h43
-rw-r--r--src/core/gameinterface.cc12
-rw-r--r--src/core/model.cc88
-rw-r--r--src/core/model.h51
-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
15 files changed, 232 insertions, 336 deletions
diff --git a/src/client/Makefile.am b/src/client/Makefile.am
index 1b504c4..0d74532 100644
--- a/src/client/Makefile.am
+++ b/src/client/Makefile.am
@@ -1,13 +1,13 @@
METASOURCES = AUTO
INCLUDES = -I$(top_srcdir)/src
-libclient_la_SOURCES = camera.cc chat.cc client.cc console.cc draw.cc hud.cc \
- input.cc keyboard.cc video.cc view.cc
+libclient_la_SOURCES = camera.cc chat.cc client.cc console.cc hud.cc input.cc \
+ keyboard.cc video.cc view.cc
libclient_la_CFLAGS = $(LIBSDL_CFLAGS) $(GL_CFLAGS)
libclient_la_LDFLAGS = -avoid-version -no-undefined $(GL_LIBS) $(LIBSDL_LIBS)
noinst_LTLIBRARIES = libclient.la
-noinst_HEADERS = camera.h chat.h client.h console.h draw.h input.h keyboard.h \
- video.h view.h
+noinst_HEADERS = camera.h chat.h client.h console.h input.h keyboard.h video.h \
+ view.h
libclient_la_LIBADD = $(top_builddir)/src/core/libcore.la \
$(top_builddir)/src/filesystem/libfilesystem.la $(top_builddir)/src/math/libmath.la \
$(top_builddir)/src/render/librender.la $(top_builddir)/src/sys/libsys.la
diff --git a/src/client/view.cc b/src/client/view.cc
index bf69072..0a5c44e 100644
--- a/src/client/view.cc
+++ b/src/client/view.cc
@@ -16,7 +16,7 @@
#include "client/chat.h"
#include "client/console.h"
#include "client/video.h"
-#include "client/draw.h"
+#include "render/draw.h"
#include "render/render.h"
#include "core/core.h"
#include "math/mathlib.h"
@@ -188,7 +188,6 @@ void frame(float seconds)
gl::clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
if (core::application()->connected()) {
- // draw the game world
// Change to the projection matrix and set our viewing volume.
gl::matrixmode(GL_PROJECTION);
@@ -203,7 +202,8 @@ void frame(float seconds)
camera::draw(seconds); // draw the current camera transformation
- draw_world(seconds); // draw the world
+ render::draw(camera::target, seconds); // draw the world
+
}
// switch to ortographic projection to draw the GUI
diff --git a/src/core/Makefile.am b/src/core/Makefile.am
index 8a65e9a..6f78e6a 100644
--- a/src/core/Makefile.am
+++ b/src/core/Makefile.am
@@ -2,8 +2,8 @@ METASOURCES = AUTO
INCLUDES = -I$(top_srcdir)/src
libcore_la_SOURCES = application.cc commandbuffer.cc core.cc cvar.cc entity.cc \
- func.cc gameconnection.cc gameinterface.cc gameserver.cc module.cc netclient.cc \
- netconnection.cc netserver.cc player.cc
+ func.cc gameconnection.cc gameinterface.cc gameserver.cc model.cc module.cc \
+ netclient.cc netconnection.cc netserver.cc player.cc
libcore_la_LDFLAGS = -avoid-version -no-undefined
libcore_la_LIBADD = $(top_builddir)/src/math/libmath.la \
$(top_builddir)/src/filesystem/libfilesystem.la $(top_builddir)/src/sys/libsys.la $(top_builddir)/src/net/libnet.la
diff --git a/src/core/face.cc b/src/core/face.cc
deleted file mode 100644
index 31b7fcc..0000000
--- a/src/core/face.cc
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- render/face.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/face.h"
-#include "render/gl.h"
-
-namespace render {
-
-Face::Face(math::Vector3f const & normal, math::Color const *color) :
- face_normal(normal)
-{
- face_normal.normalize();
-
- if (color)
- face_color = new math::Color(*color);
- else
- face_color = 0;
-}
-
-Face::~Face()
-{
- for (std::vector<math::Vector3f *>::iterator it = face_vertex.begin(); it != face_vertex.end(); it++) {
- delete (*it);
- }
-
- face_vertex.clear();
-
- if (face_color)
- delete face_color;
-}
-
-void Face::add_vertex(math::Vector3f const & vertex)
-{
- math::Vector3f *v = new math::Vector3f(vertex);
-
- face_vertex.push_back(v);
-}
-
-void Face::draw()
-{
- //gl::begin(gl::LineLoop);
- gl::begin(gl::Polygon);
- gl::normal(face_normal); // face_normal already has unit lenght
- for (std::vector<math::Vector3f *>::iterator it = face_vertex.begin(); it != face_vertex.end(); it++) {
- gl::vertex(*(*it));
- }
- gl::end();
-}
-
-}
diff --git a/src/core/face.h b/src/core/face.h
deleted file mode 100644
index a0a4d5a..0000000
--- a/src/core/face.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- render/face.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_FACE_H__
-#define __INCLUDED_RENDER_FACE_H__
-
-#include <vector>
-
-#include "math/mathlib.h"
-
-namespace render {
-
-/// one face (polygon) of a model
-class Face {
-public:
- Face(math::Vector3f const & normal, math::Color const *color=0);
- ~Face();
-
- /// the normal of this face
- inline math::Vector3f const & normal() const { return face_normal; };
-
- /// the color of this face
- inline math::Color const *color() const { return face_color; };
-
- /// add a vertex to the face
- void add_vertex(math::Vector3f const &vertex);
-
- /// draw the polygon
- void draw();
-
-private:
- math::Vector3f face_normal;
- math::Color *face_color;
- std::vector<math::Vector3f *> face_vertex;
-};
-
-}
-
-#endif // __INCLUDED_RENDER_FACE_H__
-
diff --git a/src/core/gameinterface.cc b/src/core/gameinterface.cc
index 9aa50fc..1f8f265 100644
--- a/src/core/gameinterface.cc
+++ b/src/core/gameinterface.cc
@@ -12,11 +12,17 @@
#include "core/cvar.h"
#include "core/func.h"
#include "core/gameinterface.h"
+#include "core/model.h"
#include "core/player.h"
namespace core
{
+void func_list_model(std::string const &args)
+{
+ Model::list();
+}
+
Player GameInterface::game_localplayer;
EntityControlable *localcontrol()
@@ -54,10 +60,13 @@ GameInterface::GameInterface()
}
+ core::Func::add("list_model", (core::FuncPtr) func_list_model);
}
GameInterface::~GameInterface()
{
+ core::Func::remove("list_model");
+
clear();
}
@@ -87,6 +96,9 @@ void GameInterface::clear()
Cvar::registry.erase(it);
}
}
+
+ // remove all models
+ Model::clear();
}
diff --git a/src/core/model.cc b/src/core/model.cc
index ae34270..3b1cabd 100644
--- a/src/core/model.cc
+++ b/src/core/model.cc
@@ -12,16 +12,17 @@
#include <vector>
#include <list>
-#include "render/model.h"
-#include "render/gl.h"
+#include "core/model.h"
#include "filesystem/filesystem.h"
-namespace render
+namespace core
{
const float MAX_BOUNDS = 8192;
const float delta = 10e-10;
+/* ---------- core::Engine ------------------------------------------ */
+
Engine::Engine(math::Vector3f const & location) :
engine_location(location)
{}
@@ -29,6 +30,40 @@ Engine::Engine(math::Vector3f const & location) :
Engine::~Engine()
{}
+/* ---------- core::Face ------------------------------------------ */
+
+Face::Face(math::Vector3f const & normal, math::Color const *color) :
+ face_normal(normal)
+{
+ face_normal.normalize();
+
+ if (color)
+ face_color = new math::Color(*color);
+ else
+ face_color = 0;
+}
+
+Face::~Face()
+{
+ for (std::vector<math::Vector3f *>::iterator it = face_vertex.begin(); it != face_vertex.end(); it++) {
+ delete (*it);
+ }
+
+ face_vertex.clear();
+
+ if (face_color)
+ delete face_color;
+}
+
+void Face::add_vertex(math::Vector3f const & vertex)
+{
+ math::Vector3f *v = new math::Vector3f(vertex);
+
+ face_vertex.push_back(v);
+}
+
+/* ---------- core::Model ------------------------------------------ */
+
std::map<std::string, Model*> Model::registry;
Model::Model(std::string const & name) :
@@ -446,53 +481,6 @@ void Model::add_engine(Engine *engine)
model_engine.push_back(engine);
}
-void Model::draw(core::Entity const * entity, math::Vector3f const & eye)
-{
- //gl::scale(model_scale, model_scale, model_scale);
-
- // calculate a normal from eye to entity location
- math::Vector3f n = entity->location() - eye;
- n.normalize();
-
- // draw all faces
- for (std::list<Face *>::iterator fit = model_face.begin(); fit != model_face.end(); fit++) {
- // poor man's lighting
- // set the face color depending on the viewing direction
- //float d = fabsf(math::dotproduct(n, (*fit)->normal()));
-
- //if (d > 1)
- // d = 1;
- //d = 0.5f + d/2;
-
- if ((*fit)->color()) {
- render::gl::color(*(*fit)->color());
- } else {
- render::gl::color(entity->color());
- }
- (*fit)->draw();
- }
-}
-
-void Model::draw(core::EntityControlable const * entity, math::Vector3f const & eye)
-{
- // draw the model
- draw((core::Entity *) entity, eye);
-
- // draw engines
- // all engines are assumed to point to the rear
- if (model_engine.size() && entity->thrust()) {
- gl::color(1.0f,0 ,0);
- gl::begin(gl::Lines);
-
- for (std::list<Engine *>::iterator eit = model_engine.begin(); eit != 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();
- }
-}
-
Model *Model::find(std::string const & name)
{
std::map<std::string, Model*>::iterator it = registry.find(name);
diff --git a/src/core/model.h b/src/core/model.h
index eca896b..e22d87a 100644
--- a/src/core/model.h
+++ b/src/core/model.h
@@ -4,19 +4,44 @@
the terms of the GNU General Public License version 2
*/
-#ifndef __INCLUDED_RENDER_MODEL_H__
-#define __INCLUDED_RENDER_MODEL_H__
+#ifndef __INCLUDED_CORE_MODEL_H__
+#define __INCLUDED_CORE_MODEL_H__
+#include <vector>
#include <map>
#include <list>
+#include "math/mathlib.h"
#include "math/plane3f.h"
#include "core/entity.h"
-#include "render/face.h"
-namespace render
+namespace core
{
+/// one face (polygon) of a model
+class Face {
+public:
+ Face(math::Vector3f const & normal, math::Color const *color=0);
+ ~Face();
+
+ /// the normal of this face
+ inline math::Vector3f const & normal() const { return face_normal; };
+
+ /// the color of this face
+ inline math::Color const *color() const { return face_color; };
+
+ /// add a vertex to the face
+ void add_vertex(math::Vector3f const &vertex);
+
+ /// face vertexes
+ std::vector<math::Vector3f *> face_vertex;
+
+private:
+ math::Vector3f face_normal;
+ math::Color *face_color;
+
+};
+
/// a spacecraft engine
class Engine
{
@@ -50,16 +75,6 @@ public:
/// the Model registry
static std::map<std::string, Model*> registry;
- /// draw the model for an entity
- /** This will not draw attached engines, turrents and cannons
- */
- void draw(core::Entity const * entity, math::Vector3f const & eye);
-
- /// draw the model for a controlable enity
- /** This will draw all attached engines, turrents and cannons
- */
- void draw(core::EntityControlable const * entity, math::Vector3f const & eye);
-
/* ---- static functions for the Model registry -------------------- */
/// get name model, returns 0 if not found
@@ -73,14 +88,18 @@ public:
/// list the content of the model registry
static void list();
+
+ /// list of Faces
+ std::list<Face *> model_face;
+
+ /// list of Engines
+ std::list<Engine *> model_engine;
private:
void make_face(math::Plane3f *face, std::vector<math::Plane3f *> & planes);
void add_engine(Engine *engine);
void add_face(Face *face);
- std::list<Face *> model_face;
- std::list<Engine *> model_engine;
std::string model_name;
float model_scale;
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];
}